Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.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 替换表达式中的标记_Php_Regex_Preg Replace - Fatal编程技术网

Php 替换表达式中的标记

Php 替换表达式中的标记,php,regex,preg-replace,Php,Regex,Preg Replace,来自包含标签布局的变量,如 取代 我成功地用一个字符替换了img标记,但不像我想要的那样尝试使用以下正则表达式: $string = '<img src="mon image" style="width:80px; float: right;">'; $pattern = "/(\<img\b[^>]*>)/"; $replacement = '${1}<br/>'; echo preg_replace($pattern, $replacement,

来自包含标签布局的变量,如

取代



我成功地用一个字符替换了
img
标记,但不像我想要的那样

尝试使用以下正则表达式:

$string = '<img src="mon image" style="width:80px; float: right;">';
$pattern = "/(\<img\b[^>]*>)/";
$replacement = '${1}<br/>';
echo preg_replace($pattern, $replacement, $string);

但是正则表达式也适用于该标记声明。

Fyi:img标记始终以结束斜杠结尾
right;“/>
否则将无法验证…的可能重复。另请参阅bobince对
<img src="mon image" style="width:80px; float: right;"/>