PHP 用自定义文本替换了一个不起作用的标签
PHP replaced a tag with custom texts not working
我正在编写 PHP preg_replace 脚本来用一些新的 texs 替换标签
ex- 我想替换
中的文本
我的代码在这里
$string= '<p style="margin: 0 0 16px;">Your order is shipped and
it’s on the way to your address, It will receive to you within
<tag>current_date format=”jS F Y” oddt=”” shipdays=”16″</tag></p>';
$search = "/[^<tag>](.*)[^<\/tag>]/";
$replace = "22nd January 2019 and 27th January";
echo $sv= preg_replace($search,$replace,$string);
但是输出结果是这样的
22nd January 2019 and 27th January 201922nd January 2019 and 27th January 201922nd January 2019 and 27th January 201922nd January 2019 and 27th January 201922nd January 2019 and 27th January 201922nd January 2019 and 27th January 201922nd January 2019 and 27th January 201922nd January 2019 and 27th January 201922nd January 2019 and 27th January 201922nd January 2019 and 27th January 2019
我的字符串只有一个但是脚本似乎替换了整个文本,任何人都可以知道这个错误的原因是什么以及解决方案
或其他方法。
非常感谢
你的表情应该是这样的
<?php
$string= '<p style="margin: 0 0 16px;">Your order is shipped and
it’s on the way to your address, It will receive to you within
<tag>current_date format=”jS F Y” oddt=”” shipdays=”16″</tag></p>';
$search = "/<tag>(.*)<\/tag>/";
$replace = "22nd January 2019 and 27th January";
echo $sv= preg_replace($search,$replace,$string);
?>
表达式 /<tag>(.*)<\/tag>/
表示 <tag>
和 </tag>
之间的任何文本..
我正在编写 PHP preg_replace 脚本来用一些新的 texs 替换标签
ex- 我想替换
中的文本我的代码在这里
$string= '<p style="margin: 0 0 16px;">Your order is shipped and
it’s on the way to your address, It will receive to you within
<tag>current_date format=”jS F Y” oddt=”” shipdays=”16″</tag></p>';
$search = "/[^<tag>](.*)[^<\/tag>]/";
$replace = "22nd January 2019 and 27th January";
echo $sv= preg_replace($search,$replace,$string);
但是输出结果是这样的
22nd January 2019 and 27th January 201922nd January 2019 and 27th January 201922nd January 2019 and 27th January 201922nd January 2019 and 27th January 201922nd January 2019 and 27th January 201922nd January 2019 and 27th January 201922nd January 2019 and 27th January 201922nd January 2019 and 27th January 201922nd January 2019 and 27th January 201922nd January 2019 and 27th January 2019
我的字符串只有一个但是脚本似乎替换了整个文本,任何人都可以知道这个错误的原因是什么以及解决方案
或其他方法。
非常感谢
你的表情应该是这样的
<?php
$string= '<p style="margin: 0 0 16px;">Your order is shipped and
it’s on the way to your address, It will receive to you within
<tag>current_date format=”jS F Y” oddt=”” shipdays=”16″</tag></p>';
$search = "/<tag>(.*)<\/tag>/";
$replace = "22nd January 2019 and 27th January";
echo $sv= preg_replace($search,$replace,$string);
?>
表达式 /<tag>(.*)<\/tag>/
表示 <tag>
和 </tag>
之间的任何文本..