Page 1 of 2
Making code between < & > lower case?
Posted: Wed May 18, 2005 7:54 pm
by Mr Tech
I got a WYSIWYG editor which puts most of the HTML code uppercase... Is there anyway to make everything betweend the < & > lower case and not effect the non HTML code?
Maybe even a HTML to XHTML convertor?
Thanks
Ben
Posted: Wed May 18, 2005 8:02 pm
by Skara
Code: Select all
preg_replace('/<(.+?)>/ies','strtolower("\\1")',$text);
I'm pretty sure that'll do it.
Posted: Wed May 18, 2005 8:42 pm
by Mr Tech
Yep, thanks. It did the job however I had to change it to: strtolower("<\\1>") otherwise it remvoed the < & >.
Also, is it possible to put quotes into html? For exaample:
Code: Select all
<tabel border=0 height=100 width=300 cellpadding=4 cellspacing=1>
Would change to:
Code: Select all
<tabel border="e;0"e; height="e;100"e; width="e;300"e; cellpadding="e;4"e; cellspacing="e;1"e;>
Thanks for your help!
Posted: Wed May 18, 2005 9:22 pm
by Skara
Ahaha. Rather than change it to strtolower("<\\1>"), change the first bit to.. (plus I fixed it a bit)
Code: Select all
preg_replace('/(<[^>]+>)/ies','strtolower("\\1")',$text);
my bad.
Ok, so to put quotes in... hmm... Assuming the param value is alphanumeric, then this might do the trick:
Code: Select all
preg_match_all('/<[^>]+>/is',$text,$matches);
$out = array();
for ($i=0; $i < count($matches[0]); $i++) {
$matches[0][$i] = preg_replace('/(\w+)=(\w+)/is','\\1="\\2"',$matches[0][$i]);
}
Posted: Wed May 18, 2005 9:46 pm
by Mr Tech
Awesome works well... Thanks for your help on this. I really apprciate it

Just one hiccup though...
1. One tags such as
alt=This is a picture it turns it into
alt="This" is a picture
Hopefully this isn't to complicated...
Also how do I set it up so that it keeps the non html code in the text? I tried:
Code: Select all
preg_match_all('/<ї^>]+>/is',$xhtml,$matches);
$out = array();
for ($i=0; $i < count($matchesї0]); $i++) {
$matchesї0]ї$i] = preg_replace('/(\w+)=(\w+)/is','\\1="e;\\2"e;',$matchesї0]ї$i]);
$final .= $matchesї0]ї$i];
}
But it removed all the non html text.
Thanks again

Posted: Wed May 18, 2005 11:15 pm
by Mr Tech
Never mind about the alt tag... It seems the WYSIWYG edit (which is stuffing up my code) adds quotes around them when the words are anymore then one word long...
All I need to know now is how to get it to show the non html text too...
Posted: Wed May 18, 2005 11:38 pm
by Mr Tech
Silly me... I worked it out....
This is the code that ended up working
Code: Select all
preg_match_all('/<ї^>]+>/is',$text,$matches);
$out = array();
for ($i=0; $i < count($matchesї0]); $i++) {
$text .= preg_replace('/(\w+)=(\w+)/is','\\1="e;\\2"e;',$matchesї0]ї$i]);
}
Posted: Thu May 19, 2005 12:26 am
by Mr Tech
ARGHHH!!! For some reaosn the code is no longer working... Any ideas?
Posted: Thu May 19, 2005 9:55 am
by n00b Saibot
It might be easier to search around for option that will make it write tags in lowercase.
Hmmm... i have a premonition.. are you using MS-Frontpage

then, buddy, there is the option to make it write tags in lowercase

Posted: Thu May 19, 2005 4:47 pm
by Mr Tech
Nah an online WYSIWYG editor called htmlarea... It's no longer developed and I can't find any options to make it lower case or put quotes around code in the source code... This script was working before but has all of a sudden stopped working... I might have chnaged the code without knowing...
Posted: Fri May 20, 2005 10:10 am
by phpScott
you could make your life easier and check out some of the many editors that have been discussed here
viewtopic.php?t=6288&postdays=0&postorder=asc&start=0
Posted: Sun May 22, 2005 6:42 pm
by Mr Tech
I'm unable to switch editors for various reasons... I think I worked it out though... It seems stable enough...
Instead of searching for everything between the < & >, I just used this code:
Code: Select all
$xhtml =preg_replace('/(\w+)=(\w+)/is','\\1="\\2"',$xhtml);
The only problem is if someone enters something like
red=color into the WYSIWYG editor it will put quotes around it but that's ok. I doubt anyone would need to do that...
Let me know if you think this code may not work for some cases...
Posted: Sun May 22, 2005 6:58 pm
by bokehman
My advice is download htmltrim from
http://www.w3.org and us it to tidy up your old code. htmltidy is another good piece of free software for tidying up your code.
Posted: Sun May 22, 2005 7:30 pm
by Chris Corbyn

Moved to regex
Posted: Mon May 23, 2005 7:03 pm
by Mr Tech
The code does not like something like
Code: Select all
<a href="e;http://www.google.com"e;>
The colen (
:) seems to stuff it up...
Any ideas on how to fix this? This is the code:
Code: Select all
$xhtml =preg_replace('/(\w+)=(\w+)/is','\\1="\\2"',$xhtml);