棘手的替换功能 [英] tricky replace function
问题描述
嗨民谣
我需要写一个棘手的替换功能。
C =用C替换A与B
C =用C中的E代替D
A的例子可以是一只猫爬树,B的例子可以是
狗爬鳄鱼。因此,我想确保已经被替换的部分
不会再被替换(例如,E />
替换D语句)。我将用< span class =" replacePart"> ...新文本标记所有新文本(Bs和
Es)....< / span>。
我怎么能这样做?我可以使用正则表达式吗?
谢谢
Nicolaas
.. oO(windandwaves)
>我需要写一个棘手的替换函数。
C =在C中用B代替A = C =在C中用E替换D
A的例子可以是猫爬树,B的例子可以是
狗爬鳄鱼。因此,我想确保已经更换的部件不会再被替换(例如,E
替换D语句)。我将用< span class =" replacePart"> ...新文本标记所有新文本(B和
Es)....< / span>。
>我怎么能这样做?我可以使用正则表达式吗?
你可以先尝试strtr(),只用两个参数调用。有关详细信息,请参阅
手册。
http://www.php.net/strtr
Micha
除非我误解你是什么寻找,因为我无法看到
为什么这么复杂,为什么不使用简单的srt_replace
函数?
<?php
find = array(''cat'',''tree'');
Hi Folk
I need to write a tricky replacement function.
C = replace A with B in C
C = replace D with E in C
examples of A could be "a cat climbs a tree", examples of B could be
"a dog climbs a alligator". Thereby, I want to make sure that parts
that have already been replaced will not be replaced again (by the E
replaces D statement for example). I will mark all new text (Bs and
Es) with <span class="replacePart">... new text here ....</span>.
How could I go about this? Could I use a regular expression?
Thank you
Nicolaas
..oO(windandwaves)
>I need to write a tricky replacement function.
C = replace A with B in C
C = replace D with E in C
examples of A could be "a cat climbs a tree", examples of B could be
"a dog climbs a alligator". Thereby, I want to make sure that parts
that have already been replaced will not be replaced again (by the E
replaces D statement for example). I will mark all new text (Bs and
Es) with <span class="replacePart">... new text here ....</span>.
How could I go about this? Could I use a regular expression?You could try strtr() first, called with only two parameters. See the
manual for details.
http://www.php.net/strtr
Micha
Unless I am misunderstanding what you are looking for, as I cant see
why this is so complex, why not just use a simple srt_replace
function?
<?php
find = array(''cat'',''tree'');
这篇关于棘手的替换功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!