how would I extend this preg_replace (in PHP), using regular expressions to replace white spaces also..
$this->permalink = preg_replace('[^a-z0-9]', '-', $this->permalink);
It's for generating page permalinks based on a page title. 'About me' will become 'about-me'. everything's fine except it doesn't remove the space yet.
Thanks!
As pointed out in the comment, you're regular expression is missing the delimiters. I've also added the i
modifier so that it's case-insensitive.
Example:
$this->permalink = preg_replace('/[^a-z0-9]/i', '-', $this->permalink);
Here's a working example: http://codepad.org/OlzQax1c.