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-
Comments
Post a Comment