我很努力去理解php函数stripos
和str_replace
是如何工作的。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)};
OR
$str_replace($strToFind, $strToReplace, $entity->getBodyOfText());
我得到是文本没有被发现或更换的结果!我不懂为什么。有人能帮我解释一下吗?
编辑:
文本的主体是有很多图片,文本和树枝代码的电子邮件模板。在一组特定的电子邮件模板中,我需要用一行文本来查找和替换整个代码段(文本的内容无关紧要)。我遇到的问题是当我使用str_replace
或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`
我希望帮助!
什么是在其中有{%...%}'子字符串的完整字符串的小例子? – mickmackusa
它是枝条代码...“{%if statements!==”“%}这应该显示{%else%}另一件事显示{%endif%}”。 – grgre
我不熟悉枝条代码。当我尝试用str/preg替换类型问题来帮助其他用户时,我希望能够清楚地了解完整输入的内容,它们作为子字符串的目标以及取而代之的内容。我看到你想要链接字符串,但其余的不清楚。请在文本之前和之后显示完整内容,以便您的问题很清楚。除了树枝表达外还有更多文字吗? – mickmackusa