By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,956 Members | 1,719 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,956 IT Pros & Developers. It's quick & easy.

preg_replace

P: n/a
Hi all,

I m trying to create a smiley system but no luck

I have
preg_replace ("/:-)/", '<img src="images/smiley.gif">', $strings);
but it returns Warning: Compilation failed: unmatched parentheses at offset
2

I have looked in the manual but no luck so far

regards
Stijn

Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Tue, 23 Mar 2004 00:27:02 GMT, "Stijn Goris" <me*****@hotmail.com> wrote:
Hi all,

I m trying to create a smiley system but no luck

I have
preg_replace ("/:-)/", '<img src="images/smiley.gif">', $strings);
but it returns Warning: Compilation failed: unmatched parentheses at offset
2

I have looked in the manual but no luck so far


Parentheses are ( and ).

These are used to capture patterns.

For each ( there must be a ).

If you want to match a literal ( or a literal ) you must escape them.

To escape characters you use \.

You're not including any variables in the pattern, so use single quotes. This
also means you can stop worrying about any confusion with PHP's escaping
mechanism.

preg_replace ('/:-\)/', '<img src="images/smiley.gif">', $strings);

Since there's nothing variable in your pattern match anyway, regular
expressions are overkill, so just use str_replace.

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Jul 17 '05 #2

P: n/a

"Andy Hassall" <an**@andyh.co.uk> wrote in message
news:lb********************************@4ax.com...
On Tue, 23 Mar 2004 00:27:02 GMT, "Stijn Goris" <me*****@hotmail.com> wrote:
Hi all,

I m trying to create a smiley system but no luck

I have
preg_replace ("/:-)/", '<img src="images/smiley.gif">', $strings);
but it returns Warning: Compilation failed: unmatched parentheses at offset2

I have looked in the manual but no luck so far
Parentheses are ( and ).

These are used to capture patterns.

For each ( there must be a ).

If you want to match a literal ( or a literal ) you must escape them.

To escape characters you use \.

You're not including any variables in the pattern, so use single quotes.

This also means you can stop worrying about any confusion with PHP's escaping
mechanism.

preg_replace ('/:-\)/', '<img src="images/smiley.gif">', $strings);

Since there's nothing variable in your pattern match anyway, regular
expressions are overkill, so just use str_replace.

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space

thanks
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.