SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jan 2005
    Location
    New Zealand
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    arrays and str_replace

    I'm replacing the smilie codes with the actual images with str_replace.

    This takes the 2 rows (smilie code, smilie image URL) from a mysql table.

    The thing is $code[$r] takes the character number from the array. It's kinda an array into an array, I'm not sure it's right.. For example:

    PHP Code:
    $code ':)'

    $code[0//would print :
    $code[1//would print ) 
    so it's not replacing the smilie code correctly...

    any alternatives to this?

    heres the script:

    PHP Code:

    $getsmile 
    mysql_query("SELECT code,smilie FROM ".$so_prefix."_smilies") or die("Sql error >>>" mysql_error());

    while(
    $s mysql_fetch_row($getsmile)) {

    $code $s['0'];
    $smilies $s['1'];

    for( 
    $r 0$r <= sizeof($code); $r++ )

    {
      
    $fincomm str_replace($code[$r], '<img src="'.$smilies[$r].'" alt="" />'$cleancomm);




  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    If you are just changing the text that has been outputted from the database, why not just have a long list of smilie code > smilie image and parse it through as a function instead of having all your codes in a table?
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Member
    Join Date
    Jan 2005
    Location
    New Zealand
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well I want users to be able to add/remove smilies and the easiest way is with MySql.
    The script is replacing the smilie code with images from the POSTed data, like this forum does.

  4. #4
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Perosnally I would put the smilie code into an array or its own page/ function and include it when you parse the text. This has been discussed quite a lot recently, have a look through the search for smilies....
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •