preg_replace 和 PHP 中的正则表达式
preg_replace and Regular expression in PHP
你能帮帮我吗?我不明白为什么会出现此错误。
Warning: preg_replace(): Unknown modifier 'h'
$data_proces="<link>http://news.abc.com/news/url?sa=t&fd=R&kkk&url=http://example.com/abc<link>
$find_delete="<link>http:\/\/news\.abc\.com\/news\/url\?sa=.+url=";
$replace_x="<link>";
$data_process= preg_replace($find_delete,$replace_x, $data_process);
您错过了 $find_delete
中的分隔符。应该是:
$data_process="<link>http://news.abc.com/news/url?sa=t&fd=R&kkk&url=http://example.com/abc<link>";
$find_delete="/<link>http:\/\/news\.abc\.com\/news\/url\?sa=.+url=/";
^ ^
$replace_x="<link>";
echo preg_replace($find_delete,$replace_x, $data_process);
简单。在 PHP 中,您必须使用 /
开始和结束正则表达式字符串。在结束 /
之后你可以放一些修饰符标志。阅读本文以获得更多理解。 http://www.rexegg.com/regex-modifiers.html
所以你的代码应该是:
$find_delete="/<link>http:\/\/news\.abc\.com\/news\/url\?sa=.+url=/";
在开始和结束时使用分隔符。建议选择模式中未出现的字符,例如:
$find_delete = "#<link>http://news\.abc\.com/news/url\?sa=[^;]+;url=#";
你能帮帮我吗?我不明白为什么会出现此错误。
Warning: preg_replace(): Unknown modifier 'h'
$data_proces="<link>http://news.abc.com/news/url?sa=t&fd=R&kkk&url=http://example.com/abc<link>
$find_delete="<link>http:\/\/news\.abc\.com\/news\/url\?sa=.+url=";
$replace_x="<link>";
$data_process= preg_replace($find_delete,$replace_x, $data_process);
您错过了 $find_delete
中的分隔符。应该是:
$data_process="<link>http://news.abc.com/news/url?sa=t&fd=R&kkk&url=http://example.com/abc<link>";
$find_delete="/<link>http:\/\/news\.abc\.com\/news\/url\?sa=.+url=/";
^ ^
$replace_x="<link>";
echo preg_replace($find_delete,$replace_x, $data_process);
简单。在 PHP 中,您必须使用 /
开始和结束正则表达式字符串。在结束 /
之后你可以放一些修饰符标志。阅读本文以获得更多理解。 http://www.rexegg.com/regex-modifiers.html
所以你的代码应该是:
$find_delete="/<link>http:\/\/news\.abc\.com\/news\/url\?sa=.+url=/";
在开始和结束时使用分隔符。建议选择模式中未出现的字符,例如:
$find_delete = "#<link>http://news\.abc\.com/news/url\?sa=[^;]+;url=#";