Hi first time dealing with preg_replace and found damn complex to understand specially learner.
Trying to change title string to slug for url structure where it remove all special character like ( ) ? *
and replace multiple space into single -
with converting all text in to lower case.
Here is my funny code but not getting desire output.
$title_slug = $q_slug->title;
$title_slug = preg_replace("/[\s+\?]/", " ", $title_slug);
$title_slug = str_replace(" ", " ", $title_slug);
$title_slug = str_replace(" ", "-", $title_slug);
$title_slug = preg_replace("/[^\w^\_]/"," ",$title_slug);
$title_slug = preg_replace("/\s+/", "-", $title_slug);
$title_slug = strtolower($title_slug);
return $title_slug;
EDIT: Added Example
Example: if my title is what is * the() wonder_ful not good?? and where???
Result: if-my-title-is-what-is-the-wonder_ful-not-good-and-where
Feel free to laugh :) and million thanks for help.