0

Hi all,

I have been trying to remove the URLS with http://www.CHickenHead.com that have areguments ?s= and ?sul= fromt some text. I can remove them but it is not case insensitive on the domain name part.
How can I modify this regex? I have tried (chickenHead.com)i but this doesen't work.

As you may guess I am not a computer science / regex type.

$text = "1asda <BR> http://www.foo.bar <BR> http://www.chickenHead.com <BR> http://www.CHickenHead.com?s=234234 <BR> http://www.cHickenHEad.com?sul=2QWR34 <BR> wtweghjio <BR> http://www.zitty.foo <BR> test";

$reg =	"(([a-zA-Z]+://)+".		//find xxx://
		"([a-zA-Z]+.)+".	//www.
		"(chickenHead.com)+".	//chickenHead.com
		"([^\s]+))";		//until space is reached

$linktext = preg_replace($reg, "", $text);
echo $linktext."<BR>";
2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by dubery
0
$reg = "%(([a-zA-Z]+://)+" .  //find xxx://
       "([a-zA-Z]+.)+" .      //www.
       "(chickenHead.com)+" . //chickenHead.com
       "([^\s]+))%i";         //until space is reached

As you can see I added %...%i The regex now has a start and end delimiter. The i after the delimiter is a modifier. i means case insensitive. (From PHP manual.)

Edited by pritaeas: n/a

0

Wonderful! Thanks for your help the final solution is:

$text = "1asda <BR> http://www.foo.bar <BR> http://www.chickenHead.com <BR> http://www.CHickenHead.com?s=234234 <BR> http://www.cHickenHEad.com?sul=2QWR34 <BR> wtweghjio <BR> http://www.zitty.foo <BR> test";
$reg =	"%".				//Open delimiter
		"(([a-zA-Z]+://)+".	//find ???://
		"([a-zA-Z]+.)+".	//???.
		"(chickenHead.com)+".	//chickenHead.com
		"([^\s]+))".		//until space is reached
		"%i";			//Close delimeter + case insentitive match 

$linktext = preg_replace($reg, "", $text);
echo $linktext."<BR>";

Resulting in

1asda
http://www.foo.bar http://www.chickenHead.com


wtweghjio
http://www.zitty.foo
test

This code will be used for removing links from email templates that users have manually inserted links into where the link should be auto generated from a tag.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.