我正在努力理解 php 的功能stripos
和str_replace
工作方式。
我有一段文字,例如:{% if group.newt !== "" %} XYZ's {% else %} ABC's {% endif %}
我想用Go to this link www.google.com
.
我搜索正文:
if(stripos($entity->getBodyOfText(), $strTFind) !== false)
{preg_match("{% if group.newt !== "" %} XYZ's {% else %} ABC's {% endif %}", $strToReplace)};
或者
$str_replace($strToFind, $strToReplace, $entity->getBodyOfText());
我得到的结果是没有找到或替换文本!我不懂为什么。有人可以为我解释一下吗?
编辑:
正文是一个包含大量图像、文本和树枝代码的电子邮件模板。在一组特定的电子邮件模板中,我需要用一行文本查找并替换整个树枝代码块(无论该文本是什么)。我遇到的问题是,当我使用str_replace
or在电子邮件模板中搜索代码块时preg_replace
,这些函数找不到或替换我要查找和替换的块。
所以我的输出是一样的(什么都没有找到,什么都没有改变)。
例如:
`here would be an image
now starts a heading,
some more text with {{ twig.variable }} and then more text.
more
text, lots more text some {% twig.fucntions %}blah{% ending %} and
then here is the block
I want to find and replace: {% replace this whole thing including the brackets and percentage signs %}keep replacing
{% else %}
replace that else (everything including the brackets and percentage signs)and
{% this too %}.
some more ending text.
image,
the end`
我希望这会有所帮助!