Page 2 of 2

Posted: Mon May 23, 2005 8:59 pm
by Skara
\w is for "word" characters. alphanumeric plus _, if I'm not mistaken. Change the \w to .

Posted: Mon May 23, 2005 9:07 pm
by Mr Tech
Thanks for your reply. Changing the /w to a dot (.) stops it from working alltogether... Any ideas why?

Posted: Tue May 24, 2005 1:33 pm
by Skara
... it shouldn't. post the code. :/

Posted: Tue May 24, 2005 4:57 pm
by Mr Tech
I tried replacing both with dots, only one with dots...

Code: Select all

$xhtml =preg_replace('/(.+)=(.+)/is','\\1="\\2"',$xhtml);

Posted: Tue May 24, 2005 9:10 pm
by Skara
Well that doesn't make any damn sense. . includes \w... *thinks*
Maybe it's catching the ws. Try using '\S' (capital S).

Posted: Tue May 24, 2005 9:29 pm
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>

Posted: Tue May 24, 2005 10:03 pm
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)

Posted: Tue May 24, 2005 10:14 pm
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?

Posted: Wed May 25, 2005 12:17 pm
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]

Posted: Wed May 25, 2005 4:53 pm
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!

Posted: Wed May 25, 2005 5:02 pm
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.' ;)