Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP中的preg_替换和正则表达式_Php_Regex_Hyperlink_Preg Replace - Fatal编程技术网

PHP中的preg_替换和正则表达式

PHP中的preg_替换和正则表达式,php,regex,hyperlink,preg-replace,Php,Regex,Hyperlink,Preg Replace,你能帮帮我吗?我不明白为什么会出现这个错误 警告:preg_replace():未知修饰符“h” $data\u proces=”http://news.abc.com/news/url?sa=t&;fd=R&;ampkk&;url=http://example.com/abc $find\u delete=“http:\/\/news\.abc\.com\/news\/url\?sa=.+url=”; $replace_x=“”; $data\u process=preg

你能帮帮我吗?我不明白为什么会出现这个错误

警告:preg_replace():未知修饰符“h”

$data\u proces=”http://news.abc.com/news/url?sa=t&;fd=R&;ampkk&;url=http://example.com/abc  
$find\u delete=“http:\/\/news\.abc\.com\/news\/url\?sa=.+url=”;
$replace_x=“”;
$data\u process=preg\u replace($find\u delete,$replace\u x,$data\u process);

您在
$find\u delete
中错过了delimetes。它应该是:

$data_process="<link>http://news.abc.com/news/url?sa=t&amp;fd=R&ampkkk&amp;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);
$find_delete="/<link>http:\/\/news\.abc\.com\/news\/url\?sa=.+url=/";
$data\u进程=”http://news.abc.com/news/url?sa=t&fd=R&KK&;网址=http://example.com/abc";
$find_delete=“/http:\/\/news\.abc\.com\/news\/url\?sa=.+url=/”;
^                                                   ^
$replace_x=“”;
echo preg\u replace($find\u delete,$replace\u x,$data\u process);

您在
$find\u delete
中错过了delimetes。它应该是:

$data_process="<link>http://news.abc.com/news/url?sa=t&amp;fd=R&ampkkk&amp;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);
$find_delete="/<link>http:\/\/news\.abc\.com\/news\/url\?sa=.+url=/";
$data\u进程=”http://news.abc.com/news/url?sa=t&fd=R&KK&;网址=http://example.com/abc";
$find_delete=“/http:\/\/news\.abc\.com\/news\/url\?sa=.+url=/”;
^                                                   ^
$replace_x=“”;
echo preg\u replace($find\u delete,$replace\u x,$data\u process);

简单。在PHP中,您必须以
/
开始和结束正则表达式字符串。在结束
/
之后,您可以放置一些修饰符标志。阅读此内容以了解更多信息

因此,您的代码应该是:

$data_process="<link>http://news.abc.com/news/url?sa=t&amp;fd=R&ampkkk&amp;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);
$find_delete="/<link>http:\/\/news\.abc\.com\/news\/url\?sa=.+url=/";
$find\u delete=“/http:\/\/news\.abc\.com\/news\/url\?sa=.+url=/”;

简单。在PHP中,您必须以
/
开始和结束正则表达式字符串。在结束
/
之后,您可以放置一些修饰符标志。阅读此内容以了解更多信息

因此,您的代码应该是:

$data_process="<link>http://news.abc.com/news/url?sa=t&amp;fd=R&ampkkk&amp;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);
$find_delete="/<link>http:\/\/news\.abc\.com\/news\/url\?sa=.+url=/";
$find\u delete=“/http:\/\/news\.abc\.com\/news\/url\?sa=.+url=/”;

在开始和结束处使用分隔符。建议选择不出现在模式中的字符,例如:

$find_delete = "#<link>http://news\\.abc\\.com/news/url\\?sa=[^;]+;url=#";
$find\u delete=”#http://news\\.abc\\.com/news/url\\?sa=[^;]+;url=#“;

在开始和结束处使用分隔符。建议选择不出现在模式中的字符,例如:

$find_delete = "#<link>http://news\\.abc\\.com/news/url\\?sa=[^;]+;url=#";
$find\u delete=”#http://news\\.abc\\.com/news/url\\?sa=[^;]+;url=#“;
$data\u proces=“>”;$find\u delete=“/http:\/\/news\.abc\.com\/news\/url\?sa=.+url=/”;$replace\u x=“”;echo$data\u process=preg\u replace($find\u delete,$replace\u proces);$data\u=“>”;$find\u delete=“/http:\/\/news\.abc\.com\/news\/news\/url\/url\\ sa=.+url=/”;$replace\replace$data\u process=preg($find_delete,$replace_x,$data_proces);