How can you replace html only when needed?
I am makeing a comment system, i have a string where i remove html code:
$area = stripslashes(htmlspecialchars($area));
But i replace text sometimes by code, but it doesn't work because of the code above:
$txtSmileys = array (':-)', ':-(');
$imgSmileys = array ('<img src="smiley.jpg" />', '<img src="smiley-sad.jpg" />');
$text = str_replace($txtSmileys, $imgSmileys, $text);
So how can i remove html before replacing?
Sanchixx
Sanchixx
Junior Poster in Training
80 posts since May 2012
Reputation Points: 0
Solved Threads: 2
Skill Endorsements: 0
Reverse the order, replace the smileys first, then use the strip and special functions.
pritaeas
Posting Prodigy
9,287 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,458
Skill Endorsements: 86
That doesn't work i've already tried it. :(
Sanchixx
Junior Poster in Training
80 posts since May 2012
Reputation Points: 0
Solved Threads: 2
Skill Endorsements: 0
Sanchixx
Junior Poster in Training
80 posts since May 2012
Reputation Points: 0
Solved Threads: 2
Skill Endorsements: 0
I solved it! I used htmlspecialchars_decode($Astring);
Sanchixx
Junior Poster in Training
80 posts since May 2012
Reputation Points: 0
Solved Threads: 2
Skill Endorsements: 0
Sanchixx
Junior Poster in Training
80 posts since May 2012
Reputation Points: 0
Solved Threads: 2
Skill Endorsements: 0