SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
Thread: Reg Ex issue with smilie parser
-
May 24, 2004, 09:42 #1
Smilies being parsed in URLs
I'm trying to modify a smilie parser to deal with smilie replacement text appearing in a URL and hence breaking the URL. I've got the following
PHP Code:foreach ($this->smilieSearchArray as $key=>$value)
{
$parsedText = preg_replace('#(?<!&|"|<|>|©)' . preg_quote($value, '#') . '#s', $this->smilieReplaceArray[$key], $text);
}
It's probably something obvious that I'm missing but I just can't see itLast edited by [Az]; May 25, 2004 at 06:15.
HEXUS Webmaster
-
May 25, 2004, 03:32 #2
bump
HEXUS Webmaster
-
May 25, 2004, 05:50 #3
I found the bug with the script, as expected a stupid error where I was overwriting the parsedText with the original for every loop of the array except for the last. Stupid really
Anyway, I now have an issue where it is parsing smilies inside an <a href tag that has a javascript command e.g. <a href=javascriptpenWindow. The parser will pick up the
in the command and mess up the URL. I've tried to get to the bottom of it but no luck. Can anyone point me in the right direction to make sure it excludes any strings inside an HTML tag ?
HEXUS Webmaster
-
May 25, 2004, 05:50 #4
in fact it does exactly what has appeared above
HEXUS Webmaster
-
May 25, 2004, 06:48 #5
- Join Date
- Apr 2004
- Location
- germany
- Posts
- 4,324
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The simplest solution would be
PHP Code:$test=<<<EEE
<a href='javascript:open'>foo :o bar</a>foo :o bar<img alt="foo :o bar">:o
EEE;
$test=preg_replace("~(>[^<]*)(:o)~","$1{smile}",$test);
I think "real-life" html parser cannot be made with regexps. You need something like sax parser for this.
-
May 25, 2004, 09:40 #6
Seems to work like a charm. I'm going to try and see if I can find normal circumstances under which it may break but it's better than what I had. In general I aim for XHTML 1.1 Strict so the code should be well-formed (famous last words
)
thanks, your help was much appreciatedHEXUS Webmaster
Bookmarks