PHP - Strip Tags allow "<3" text hearts

1k Views Asked by At

Hey Guys, I usually come to StackOverflow for my php coding answers, although this time I could not seem to find one.

I am creating a social networking type website that requires lots of text entering and data checking. Everything seems good and the other day I was testing some characters users may enter and its seems that if I try to insert a '<3' it says its empty.

<?php
$text = "<3";
$clean = strip_tags($text);
echo $clean; // prints out nothing..
?>
2

There are 2 best solutions below

1
On BEST ANSWER

Use htmlspecialchars instead strip_tags.

0
On

"<3" will be break your HTML when you output it directly.

May you replace it with an (Heart)Image or other HTML- Tag( with css heart property) , like you would do with Smileys.