php - preg_replace() only replace spaces, symbols with a hyphen -


how replace letters , numbers hyphen? slug url person type in string url. problem i’m having people inputting symbols , many spaces make url invalid.

also, resource test don’t have ask again? thanks.

the code

$input_url = "this example: it?"; $slug_url = preg_replace("/[^a-za-z0-9]/", "-", $input_url); print($slug_url); 

will output

this-is-only-an-example--do-you-like-it-

demo


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -