Variable Visions

PHP preg_replace for adding hyphens to URL field

Published Thu. Aug. 02, 2012

Set this variable eqaul to your POST value for URL title and it will automatically add hyphens where spaces are found.

$urltitle = preg_replace('/[^A-Za-z0-9-]+/', '-', $urltitle);

Keywords:PHP, preg_replace, query string urls