html - PHP Cleaning special characters from string -


so made scrapper , returns strings multiple sites. want check if strings match, use php clean string , check. however, & , other special characters appear in 2 ways, 1 & , other &. how go removing each type.

preg_replace("/[^a-za-z0-9]+/", "", $string); 

i have that, doesn't take out special characters.

thanks.

try

function removespecialchar($string) {     $string = str_replace('', '-', $string); // replaces spaces hyphens.     return preg_replace('/[^a-za-z0-9\-]/', '', $string); // removes special chars. }  echo removespecialchar(html_entity_decode('&khawer&')); //will output khawer 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -