This is my input:
<
This is the output I need:
gt
But this is the output I GET from htmlspecialchars:
>
Basically, I want htmlspecialchars result, but really stripped down. I only want characters a-z
and 0-9
.
Can anyone help?
This should work for you:
(Just preg_replace()
all characters which aren't in a-z0-9
with an empty string which you get from htmlentities()
)
<?php
$str = "<";
echo preg_replace("/[^a-z0-9]/", "", htmlentities($str));
?>
output:
lt