populating emoticons

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • omerbutt
    Contributor
    • Nov 2006
    • 638

    populating emoticons

    hi there
    i am making a scrapbook application i which i have some emoticons also i had to make a preview section for writing a scrap in which i have to show the emoticons also that are written in the scrap ,i have completed the preview part with the help of javascript ,now i have to show those scraps along with the emoticons populated in the scrap book .The logic that i am using is to filter the scrap from the database just before they are populated in the scrapbook i tried to use the same logic as i used in the java script but it is not working quit right, i used the function str.replace() while using javascript but in php ihad to use the str_replace()
    but it is not replacing the sign of the emoticon with the image tag. here is my code[code=php]
    function stripperPhp($st r){
    $arraysigns=arr ay("8)","*)",": @",":#",":o",": e",":s","*p" , "-p",":)",":D",": p",":$",":(" , ":w",":*",":x", ":-","8x","8|",":6 ",":&", "8*","$)","'(", "g(");
    $arrayname=arra y("goggle.gif", "love.gif","hot .gif","sad.gif" ,"shock.gif" , "wacked.gif","p issed.gif", "horny.gif","di zzy.gif","smile .gif","happytee th.gif","tounge .gif", "shy.gif","disa p.gif","wot.gif ","kiss.gif","s hutup.gif","hol iday.gif", "army.gif","ner ed.gif","devil. gif","sadangle. gif", "kissdead.gif", "money.gif" , "money.gif","sw et.gif");
    $stringlength=s trlen($str);
    $arraylen=sizeo f($arraysigns);
    for($j=0;$j<$ar raylen;$j++){
    for($k=0;$k<$st ringlength;$k++ ){
    $replaced=str_r eplace($arraysi gns[$j],"<img src=images/emoticons/".$arraynam e[$k]."/>",$str);

    }
    }
    return $str;
    }
    function emoticn($str){
    $replaced=strip perPhp($str);
    echo "replaced=".$re placed;
    }
    [/code]
    what i am doing in his code is that first i call a function emoticn($str); in which i pass the scrp as a string and then that string is passed to the
    funtion stripperPhp($st r) which filters the string an replaces ':)' or any other smiley appearing in that string with the <img src='images/emoticons/smiley.gif'> i have stored the names of the smiley in an array and the name of the gifs fo that emoticons into another arrayand then use those array in the str_replace() funtion to swap the signs of smileys with the actual name of the gifs but it is not doing it so
    any suggesstions
    regards,
    omer
    Last edited by ronverdonk; Apr 28 '08, 10:49 AM. Reason: post breaks page
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Your IDE must have given you an error because statement [php]src=images/emoticons/".$arraynam e[$k]." />";[/php] is erroneous. It must be [php]src="images/emoticons/".$arraynam e[$k]." />";[/php]but that statement does not make sense to me at all. Because what variable is src? And when not a variable, what ius it doing in the middle of the code?

    Ronald

    Comment

    • omerbutt
      Contributor
      • Nov 2006
      • 638

      #3
      Originally posted by ronverdonk
      Your IDE must have given you an error because statement [php]src=images/emoticons/".$arraynam e[$k]." />";[/php] is erroneous. It must be [php]src="images/emoticons/".$arraynam e[$k]." />";[/php]but that statement does not make sense to me at all. Because what variable is src? And when not a variable, what ius it doing in the middle of the code?

      Ronald
      sorry sir
      that was a commented line that i was using in my code for testing different ways to assign the paths it was to be excluded from the post i have edited my previous post, now you can see it.Sorry again
      regards,
      omer

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        The changed (replaced) text line is NOT in $str but in $replace, because you assigned it there in statement[php] $replaced=str_r eplace($arraysi gns[$j],"<img src=images/emoticons/".$arraynam e[$k]."/>",$str);[/php]this also means that you must not return $str from the function, but $replaced.

        So the text in $str is replaced and stored in $replaced. But in subsequent passes through the loop you still replace the text in $str and assign the new string to $replaced, over and over again.

        YOu should assign the result of the str_replace to $str and return $str, as you already do. That will work like[php] $str=str_replac e($arraysigns[$j],"<img src=images/emoticons/".$arraynam e[$k]."/>",$str);
        }
        }
        return $str;[/php]Ronald

        Comment

        • omerbutt
          Contributor
          • Nov 2006
          • 638

          #5
          Originally posted by ronverdonk
          The changed (replaced) text line is NOT in $str but in $replace, because you assigned it there in statement[php] $replaced=str_r eplace($arraysi gns[$j],"<img src=images/emoticons/".$arraynam e[$k]."/>",$str);[/php]this also means that you must not return $str from the function, but $replaced.

          So the text in $str is replaced and stored in $replaced. But in subsequent passes through the loop you still replace the text in $str and assign the new string to $replaced, over and over again.

          YOu should assign the result of the str_replace to $str and return $str, as you already do. That will work like[php] $str=str_replac e($arraysigns[$j],"<img src=images/emoticons/".$arraynam e[$k]."/>",$str);
          }
          }
          return $str;[/php]Ronald
          hey thanks alot ron that worked fine :) thanks alot man
          regards,
          omer

          Comment

          • ronverdonk
            Recognized Expert Specialist
            • Jul 2006
            • 4259

            #6
            Welcome. See you next time.

            Ronald

            Comment

            • omerbutt
              Contributor
              • Nov 2006
              • 638

              #7
              Originally posted by ronverdonk
              Welcome. See you next time.

              Ronald
              yes ron sure,
              regards,
              omer

              Comment

              Working...