I am trying to get this all into one query, but my regex skills are not so grand. I did get it to work in this ungraceful manner. Any assistance is greatly appreciated.
the source $url would look like this:
$urlName1 = preg_replace("/[0-9]/","",$url);
$urlName2 = preg_replace("/(o)/","",$urlName1);
$urlName = preg_replace("/(\/)/","",$urlName2);
Just include the other characters in your character class for replacement.
$url = "/o/33484/bob-nomai"; echo preg_replace("~^/o[0-9/]+~", "", $url); // bob-nomai
There's no way you're doing
preg_replace("/(o)/", "", $urlName1) because that would just result in getting the string
"bb-nmai", which clearly isn't what you want.
Instead, you seem to want to remove the leading
"/o" at the begging of the string, which can be achieved in PCRE with an anchor.
Outside a character class, in the default matching mode, the circumflex character (^) is an assertion which is true only if the current matching point is at the start of the subject string.
^/o will match the
/o at the beginning of the subject and any proceeding characters of