Current code only replace the spaces to dash (-)
$url = str_replace(' ','-',$url);
I want only letters, numbers and dash (-) allowed on the URL.
Let me know the tricks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Do you want this for generating slug?
Then you can do something like this:
It will strip leading and trailing whitespace first, convert the string to lowercase, then replace all non-word characters (not a-z, 0-9 or -) with a single
-A Beautiful *# Day will become
a-beautiful-dayRemove
strtolower()if you don’t mind uppercase letters in the slug.