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>";
$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.)

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.