这是我的if语句,它将从源代码中获取此示例href:
href="/toronto/2013/05/14/the-airborne-toxic-event/4296/" 从源代码
if ($text=preg_match('/href="([^"]*)"/', $text, $matches))
{
$output=$matches[1];
return $output;
}然后返回
/toronto/2013/05/14/the-airborne-toxic-event/4296/我正在尝试返回没有"/toronto"或"/toronto/"的url (我不确定我需要哪一个)
如果你能向我展示可以做到这一点的正则表达式,我将不胜感激。谢谢
发布于 2013-05-14 23:22:21
使用preg_replace
return preg_replace('~^/?toronto/~', '', $output);如果您确定"toronto/“不会出现在字符串中的任何其他位置,则可以使用str_replace
return str_replace('/toronto', '', $output);这假设总是会有一个前导斜杠。
https://stackoverflow.com/questions/16547019
复制相似问题