Making code between < & > lower case?

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

Moderator: General Moderators

User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

\w is for "word" characters. alphanumeric plus _, if I'm not mistaken. Change the \w to .
User avatar
Mr Tech
Forum Contributor
Posts: 424
Joined: Tue Aug 10, 2004 3:08 am

Post by Mr Tech »

Thanks for your reply. Changing the /w to a dot (.) stops it from working alltogether... Any ideas why?
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

... it shouldn't. post the code. :/
User avatar
Mr Tech
Forum Contributor
Posts: 424
Joined: Tue Aug 10, 2004 3:08 am

Post by Mr Tech »

I tried replacing both with dots, only one with dots...

Code: Select all

$xhtml =preg_replace('/(.+)=(.+)/is','\\1="\\2"',$xhtml);
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

Well that doesn't make any damn sense. . includes \w... *thinks*
Maybe it's catching the ws. Try using '\S' (capital S).
User avatar
Mr Tech
Forum Contributor
Posts: 424
Joined: Tue Aug 10, 2004 3:08 am

Post by Mr Tech »

Hmmm it's not liking that either... Is there a way to "allow" certain characters? The characters I need it to accept are:

:
/
_
-


I don't think there are anymore I would need...

I tried this code:

$xhtml =preg_replace('/(\w+)=([:\w]+)/is','\\1="\\2"',$xhtml);

and it showed this:

Code: Select all

<a href=&quote;http:&quote;//www.google.com>
instead of this:

Code: Select all

<a href=&quote;http&quote;://www.google.com>
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

haha, well, your two code examples were the same. But here's what you need. Instead of "\w" or "." use "[\w:\/-_]" (the / is escaped)
User avatar
Mr Tech
Forum Contributor
Posts: 424
Joined: Tue Aug 10, 2004 3:08 am

Post by Mr Tech »

No they are different... One the quote is to the left of the colon the other is to the right...

Thanks for all you help.. I really do apprciate it ;)

I add your code:

Code: Select all

$xhtml =preg_replace('/(\w+)=([\w:\/-_.]+)/is','\\1="\\2"',$xhtml);
And I am getting results such as:

Code: Select all

&lt;form action=&quote;http://www.google.com&gt;&lt;p&gt;&lt;img&quote; height=&quote;106&quote; src=&quote;images/zoom_img.jpg&quote; hspace=&quote;7&quote; width=&quote;90&quote; align=&quote;left&quote; /&gt;
And:

Code: Select all

&lt;div id=&quote;testimonial&gt;&quote;
Any ideas why?
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

haha, didn't even see the difference in the ".

Anyway, this: [\w:\/-_.] was supposed to be: [\w:\/-_] (no .)

If that doesn't work, you could try to look for things to not include:
[^>\'\"\s]
User avatar
Mr Tech
Forum Contributor
Posts: 424
Joined: Tue Aug 10, 2004 3:08 am

Post by Mr Tech »

That's perfect :) Seems to work fine. Thank you for all your help. I could never have done it without you.

The reason I used [\w:\/-_.] was because it was adding the quote after the first dot (E.g: <a href="http://www."google.com>)... But that doesn't matetr anymore. It works :)

Thanks again!
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

Cool. ^_^
Yeah, if looking for an actual dot, then you need to escape it (\.). A single . is a regex special char which means 'any character.' ;)
Post Reply