Regex and Lowercase issues...

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
User avatar
Mr Tech
Forum Contributor
Posts: 424
Joined: Tue Aug 10, 2004 3:08 am

Regex and Lowercase issues...

Post by Mr Tech »

Hey guys, how are ya?

This regex script has been working great! However I found one little bug... This code makes all of the HTML tags lower case which works fine:

$content =preg_replace('/(<[^>]+>)/ies','strtolower("\\1")',$content);

However, lets say I have an image called ImAgE.JPG. And then I have this code: <img src="ImAgE.JPG">. The regex script then makes the images name lower case which ends up like this: <img src="image.jpg">...

Because the linking to the image is case sensitive, it then gives a 404 error on the image. Is there anyway around this?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

umm, tried getting rid of the strtolower have you?
User avatar
Mr Tech
Forum Contributor
Posts: 424
Joined: Tue Aug 10, 2004 3:08 am

Post by Mr Tech »

I want it to strtolower except I don't want it to mess up image and href tags... Is it possible?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Code: Select all

$content =preg_replace('/(?:<(\/?\w+)[^>]+>)/ies','strtolower("\\1")',$content);
\/?\w+)[^>]+>)/ies','strtolower("\\1")',$content);ent);;(\/?\w+)[^>]+>)/ies','strtolower("\\1")',$content);\1")',$content);e;)',$content);$content =preg_replace('/(?:<(\/?\w+)[^>]+>)/ies','strtolower("\\1")',$content);place('/(?:<(\/?\w+)[^>]+>)/ies','strtolower(&quote;\\1&quote;)',$content);>]+>)/ies','strtolower("\\1")',$content);es','strtolower("\\1")',$content);$content =preg_replace('/(?:<(\/?\w+)[^>]+>)/ies','strtolower("\\1")',$content);
User avatar
Mr Tech
Forum Contributor
Posts: 424
Joined: Tue Aug 10, 2004 3:08 am

Post by Mr Tech »

Thanks d11wtq,

However that code seems to remove all the HTML... E.g: It replaces:

<IMG height=106 src="images/zoom_img.jpg" hspace=7 width=90 align=left>

With:

img

Any ideas?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Yeah sorry... I've had one of those day lol....

untested... but you get the idea (should be easy to fix if it's broken)

Code: Select all

$content =preg_replace('/(?:<(\/?\w+)([^>]+)>)/ies','<'.'strtolower("\\1")'.'\\2>',$content);
User avatar
Mr Tech
Forum Contributor
Posts: 424
Joined: Tue Aug 10, 2004 3:08 am

Post by Mr Tech »

d11wtq wrote:(should be easy to fix if it's broken)
Not quite... The error
Parse error: parse error, unexpected '<' in c:\program files\easyphp\www\created\oe_content_manager_v2\html2xhtml\test.php(11) : regexp code on line 1

Fatal error: Failed evaluating code:
in c:\program files\easyphp\www\created\oe_content_manager_v2\html2xhtml\test.php on line 11
I tried replacing '<'.'strtolower("\\1")'.'\\2>' with '<'.strtolower("\\1").'\\2>' but no luck...
Post Reply