Page 1 of 1

Regex and Lowercase issues...

Posted: Wed Jul 06, 2005 10:02 pm
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?

Posted: Wed Jul 06, 2005 10:38 pm
by Burrito
umm, tried getting rid of the strtolower have you?

Posted: Wed Jul 06, 2005 11:04 pm
by Mr Tech
I want it to strtolower except I don't want it to mess up image and href tags... Is it possible?

Posted: Thu Jul 07, 2005 4:35 am
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);

Posted: Thu Jul 07, 2005 6:54 pm
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?

Posted: Thu Jul 07, 2005 7:04 pm
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);

Posted: Thu Jul 07, 2005 7:17 pm
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...