0
我收到此错误。我试图删除字符串中找到的所有字符。preg_replace正斜杠后的所有内容/
例如'google.com/remove' 应该成为 'google.com'
preg_replace ('////.*/' , '' , $string);
消息:的preg_replace():未知的修饰词 '/'
我收到此错误。我试图删除字符串中找到的所有字符。preg_replace正斜杠后的所有内容/
例如'google.com/remove' 应该成为 'google.com'
preg_replace ('////.*/' , '' , $string);
消息:的preg_replace():未知的修饰词 '/'
不要我们e preg_replace
来做到这一点。
// PHP 5.4
$string = explode('/', $string, 2)[0];
// Before PHP 5.4
$string = array_shift(explode('/', $string, 2));
试试这个:
preg_replace ('/\/(.*)/' , '' , $string);
不能测试它的那一刻,但它应该工作...
编辑:在线测试快速,按预期工作:)
你需要逃避你的斜杠。 ('\ /')忽略这个事实,这看起来像一个屁股。 – Matt 2012-07-27 15:49:06