Hi all, I am very bad with string functions, so I was wondering if any of you have the following function. Here is what I want it to do: 1. It takes a string, not very long, usually 32-64 characters. 2. It removes all characters, except [a-z] [0-9]. 3. It replaces all white space between words with "-". So if it takes a string like: "Ce credeti despre acest film???", it will return: "ce-credeti-despre-acest-film". Help is appreciated
$string = preg_replace('/[^0-9a-z]/', '', str_replace(' ', '-', strtolower($string))); PHP: Should work?
Thanks! It did not work properly, so I did some minor changes $string = preg_replace('/[^\-0-9a-z]/', '', str_replace(' ', '-', strtolower($string))); PHP: P.S. i would however like it to check if there is just 1 space between words, and if it's more than just 1, trip it to 1 space.
Then you need to modify it a bit: $string = preg_replace('/[^\-0-9a-z]/', '', preg_replace('/\s+/', '-', strtolower($string))); PHP: