How to remove special characters from a string using php?

I want to create a clean url by removing special symbols. My current code is:

str_replace(' ', '-', $rw_question['title'] );


I know I can do this by using multiple str_replace. But can I do it without using so many str_replace.

Thanks in advance

Asked 19 Dec, 15 at 12:32 PM

Arjun Singh
Php

Answer

This Should Work: 
Urlencode( Preg_replace('/[^A-Za-z0-9-]/', '', Str_replace(' ', '-', $rw_question['title'] ) ) ); 

like