Welcome Guest, Not a member yet? Register   Sign In
preg_replace function problem
#11

[eluser]basty_dread[/eluser]
still it doesnt work ...
it removes everythin..
can this be done?
exact match only if it find that web design google has a >
ie.
<a href='link'>web[b] design google </a> las vegas
it will not replace this because there is > beside web
#12

[eluser]theprodigy[/eluser]
Code:
$finalstring = preg_replace('/(^|[^<a.*?&gt;])('.$find.').*?[^</a>]*?/iU', '<a href="http://google.com">\\2</a>', $string,-1,$i);
I believe that should do it. It took me a while, but I think I finally got it (keeping fingers crossed).
#13

[eluser]basty_dread[/eluser]
do you have a testing server like xampp?

i tried to modify it again just removing some values and it turned good, but it removes the spacing between then

can you try this?
Code:
$find = "web design";
$string = "WEB DESIGN Web Design web design <a href='yahoo.com'>web design google</a> las vegas";
$finalstring = preg_replace('/(^|[^<a.*?&gt;])('.$find.')\b/iU', '<a href="http://google.com">\2</a>', $string,-1,$i);
echo $finalstring;
echo '<br />'.$i;
#14

[eluser]theprodigy[/eluser]
Code:
$finalstring = preg_replace('/(^|[^<a.*?&gt;])('.$find.')\b/iU', '\1<a href="http://google.com">\2</a>', $string,-1,$i);
#15

[eluser]basty_dread[/eluser]
works great.. thanks a lot theprodigy..
it takes me so much time try to figure it out..

i was working on crosslinking within the site..

things like this also could occur
Code:
$find = "designing";
$string = "<a href='link'>web desiging for all</a> nice web design";
$finalstring = preg_replace('/(^|[^<a.*?&gt;])('.$find.')\b/iU', '\1<a href="http://yahoo.com">\2</a>', $string,-1,$i);

we will surely have an error with this..

i appreciate your help.. thanks a lot for helping me on it. Many Thanks




Theme © iAndrew 2016 - Forum software by © MyBB