I have this simple function: function strip_url($title) { return preg_replace('/-+/i', '-', strtolower(implode('-', preg_replace('/[^a-z0-9]/i', '', explode(' ', $title))))); } PHP: I use it to generate a clean url compatible string out of any string inputted and it works very very well. There is one problem though, if a user inputs special characters they can "break" it and have it return just blankness. For example, passing "````" without the quotes returns nothing. I am trying to come up with a better solution for this and so Im asking DP for some ideas.
From what you wrote it sounds like urlencode does exactly what you're trying to do. What're you trying to do that's different?
Well I realized that it would be easier to start the function with urlencode and then change it in a few ways to be more SEO optimized, which I have done.
You are looking for something like thsi? <?php function replace($x) { $k1=array('ä','ö','ü','Ä','Ö','Ü',' ',':','&','?','!','"'); $k2=array('ae','oe','ue','ae','oe','ue','-','-','und','','',''); for ($i='0';$i<'12';$i++) { $x = str_replace($k1[$i],$k2[$i],$x); } return $x; } $clean_title = replace($mytitel); ?> PHP: