0

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

Edited by Sanchixx: mistake

4
Contributors
7
Replies
8
Views
5 Years
Discussion Span
Last Post by Sanchixx
0

I solved it! I used htmlspecialchars_decode($Astring);

Edited by Sanchixx: sanch

0
<?php
    $input = "<p>This is an example of random input you might encounter! :)</p>";

    $output = strip_tags($input);

    $output = str_replace (":)", "<img src=\"https://www.google.ca/intl/en_ALL/images/logos/images_logo_lg.gif\" alt=\"\"/>", $output);

    echo $output;
?>

Remember that you need the slashes infront of the quotes so that PHP ignores the quotes (because they're not really the end quotes).

Edited by JameB

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.