Welcome Guest, Not a member yet? Register   Sign In
how to remove link?
#1

[eluser]basty_dread[/eluser]
Hello Guys i need your help removing links..

for example i want to remove the link that surrounds this keyword: codeigniter

Code:
$string = "Welcom to Codeigniter <a href='http://codeigniter.com'>codeigniter</a><br />
<a href='http://mysite.com/index.php/forums/coding/sample'>codeigniter</a>";

$search = "codeigniter";


//code to use to remove the link that surrounds codeigniter..


i dont really know how to use preg_replace or str_replace..

I hope you will help me.. THanks..
#2

[eluser]Michael Wales[/eluser]
uhhh... what? Do you even know HTML - to remove the link just remove the anchor tag.
#3

[eluser]basty_dread[/eluser]
thanks for posting.. haha..

using preg_replace or something..
because im dealing on cms.. i really hope anyone could help..
i have a form that will enter a keyword.. and then
the function will remove the link that surrounds the keyword..

Please help.. thanks.
#4

[eluser]Dyllon[/eluser]
strip_tags()
#5

[eluser]basty_dread[/eluser]
strip tags cannot be used.. because there are still some other links that should not be removed..
#6

[eluser]Dyllon[/eluser]
[quote author="basty_dread" date="1265452977"]strip tags cannot be used.. because there are still some other links that should not be removed..[/quote]
Specify the tags as allowable or use preg_replace()

Code:
$pattern = "/<a[^>]*>(.*)<\/a>/iU";

$string = "Welcom to Codeigniter <a href='http://codeigniter.com'>codeigniter</a><br />
<a href='http://mysite.com/index.php/forums/coding/sample'>codeigniter</a>";

$string = preg_replace($pattern, "$1", $string);
#7

[eluser]basty_dread[/eluser]
This worked great.. Thank's a lot..here is what i've modified..

Code:
$word = "codeigniter";

$pattern = "/<a[^>]*>(".$word.")<\/a>/iU";

$string = "Welcom to Codeigniter <a href='http://codeigniter.com'>codeigniter</a><br />
<a href='http://mysite.com/index.php/forums/coding/sample'>codeigniter</a>
<a href='www.google.com'>google</a>";

$string = preg_replace($pattern, "$1", $string);


echo $string;

Thanks a lot Dyllon




Theme © iAndrew 2016 - Forum software by © MyBB