My idea is to remove special characters and html codes and replace the whitespaces to dashes
let us doing it step by step
$text = "Hello world)<b> (*&^%$#@! it's me: and; love you.<p>";
now i’m want the output become Hello-world-its-me-and-love-you
I’ve tired this code for removal of special characters and html codes
$array = array();
$array[0] = "/<.+?>/";
$array[1] = "/[^a-zA-Z0-9 ]/";
$textout= preg_replace($array,"",$text);
Now the output will be like this Hello world its me and love you
so is there any way i can modify this code so that the text output become exact as i do needs Hello-world-its-me-and-love-you
~ thank you
You’re probably better off using
strip_tagsto get rid of the html tags for you, then use a regexp to remove all non alphanumeric (or non-space) characters. Then you can simply convert spaces to hyphens usingstr_replace. Note I also added a line to collapse multiple spaces to a single space, since that is what you did in your example. Otherwise you getworld--its-meinstead ofworld-its-me.