removing a word from a url using regex in php -
this if statement take example href source code:
href="/toronto/2013/05/14/the-airborne-toxic-event/4296/" from source code
if ($text=preg_match('/href="([^"]*)"/', $text, $matches)) { $output=$matches[1]; return $output; } and return
/toronto/2013/05/14/the-airborne-toxic-event/4296/ i trying return url without either "/toronto" or "/toronto/" (i'm not sure 1 need)
if show me regex expression would appreciate it. thanks
use preg_replace:
return preg_replace('~^/?toronto/~', '', $output); if you're sure "toronto/" not appear anywhere else in string, can use str_replace:
return str_replace('/toronto', '', $output); this assumes there'll leading slash.
Comments
Post a Comment