在PHP 4中复杂替换 [英] Complex replace in php 4
问题描述
我搜索并尝试开发(没有运气)一个函数来执行
跟随:
我有一个字符串可能是:
" Le''ts转到< a href =" my.htm">我的车< / a>。明天我将不得不买一辆
的新车。我的新车是< em> red< / em>!请不要认为他在纳斯卡!
我要做的就是更换汽车的出现。 < a
href =" /...& quot;> car< / aBUT在这些情况下:
- 如果已经有了包裹的链接
- 如果汽车是另一个词的一部分
另外,我正在使用php4所以我不能使用str_ireplace不区分大小写
替换。
你能帮帮我吗?
问候。
-
Fabri
标签Wii:8680 1598 2246 2466
http://www.consolerecords.it/forum/viewtopic.php?t=217
4月30日下午6:13,Fabri< farsi.i.cazzi.pro ... @ mai.ehwrote:
我搜索并尝试开发(没有运气)一个函数来执行
跟随:
我有一个字符串可能是:
" Le''ts转到< a href =" my.htm">我的车< / a>。明天我将不得不买一辆
的新车。我的新车是< em> red< / em>!请不要认为他在纳斯卡!
我要做的就是更换汽车的出现。 < a
href =" /...& quot;> car< / aBUT在这些情况下:
- 如果已经有了包裹链接
- 如果汽车是另一个单词的一部分
正则表达式。 preg_replace()是PERL兼容的常规
表达式,这只是我的偏好。您也可以使用普通的PHP
正则表达式(ereg_replace())。
string = preg_replace(''#( [\\\\())我的车([\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ b $ b href =" ..."> my car< / a>
I searched and tried to develop (with no luck) a function to do the
following:
I have a string that may be:
"Le''ts go to <a href="my.htm">my car</a>. Tomorrow I''ll have to buy a
new car. My new car is <em>red</em>! Please don''t think to be in Nascar!!"
What I have to do is replace occurences of "car" with <a
href="/...">car</aBUT in these cases:
- if there is already a wrapped link
- if car is part of another word
Also, I''m using php4 so I can''t use str_ireplace for case insensitive
replace.
Can you help me?
Regards.
--
Fabri
Tag Wii: 8680 1598 2246 2466
http://www.consolerecords.it/forum/viewtopic.php?t=217
On Apr 30, 6:13 pm, Fabri <farsi.i.cazzi.pro...@mai.ehwrote:I searched and tried to develop (with no luck) a function to do the
following:
I have a string that may be:
"Le''ts go to <a href="my.htm">my car</a>. Tomorrow I''ll have to buy a
new car. My new car is <em>red</em>! Please don''t think to be in Nascar!!"
What I have to do is replace occurences of "car" with <a
href="/...">car</aBUT in these cases:
- if there is already a wrapped link
- if car is part of another wordRegular Expressions. preg_replace() is PERL compatible regular
expressions, that''s just my preference. You can use the normal PHP
regex, too (ereg_replace()).
string = preg_replace( ''#([\s\(])my car([\s\)\.])#i'', ''
1<a
href="...">my car</a>
这篇关于在PHP 4中复杂替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!