homepage Welcome to WebmasterWorld Guest from 184.73.104.82
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Regex help treating & as regular character
XMLMania

10+ Year Member



 
Msg#: 6207 posted 3:06 pm on Dec 22, 2004 (gmt 0)

Hi,

I'm trying to highlight words in a string via regex. I not only want to highlight the singular word e.g. "word" but also plurals like "words" and "word's".

This is easy to do, but some strings use entities to represent single quotes, such as ’ and ’. This is were my problem is, because it appears & is being treated as an operator, instead of plain character.

I came up with a simple version that doesn't work:

$find = '/([^a-zA-Z0-9])(' . $keyword . 's¦' . $keyword . '\'s¦' . $keyword . '’s¦' . $keyword . '’s' . $keyword . ')([^a-zA-Z0-9])/i';

$replace = "\$1<b>\$2</b>\$3";

Any one know how i can get the regex parser to not interpret & as an operator?

Cheers

 

coopster

WebmasterWorld Administrator coopster us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 6207 posted 3:40 pm on Dec 22, 2004 (gmt 0)

Escape it.
\&
Also, have a look at preg_quote(). [php.net]
XMLMania

10+ Year Member



 
Msg#: 6207 posted 3:42 pm on Dec 22, 2004 (gmt 0)

Haha thats awesome mate! Muchos Gracias!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved