473,383 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

preg_replace

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
2 4628
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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: JDJones | last post by:
I'm having some trouble getting this replacement to work efficiently. I have the following code: $thing = preg_replace("(\r\n|\n|\r|\t)", "", $thing1); What I want to do now is to get it to...
3
by: Justin Koivisto | last post by:
I am replacing a string in a text block that has a literal $ in it, and preg_replace is seeing it as a backreference. Here is what I am using: foreach($price_lists as $list)...
3
by: Sebastian Araya | last post by:
Hello, I have a string like this: var1: value1...valueI var2: value1...valueJ ... varN: value1...valueK this is an example: breakfast: coffee eggs lunch: sandwich apple dinner: chicken...
3
by: TXSherry | last post by:
Hi, I cannot seem to wrap my brain around preg_replace. Though I've read the help file backwords and forwards. :/ Hoping someone can give me a solution here. Problem: Given string 'str'...
1
by: yawnmoth | last post by:
say i have the following script: <? $test = "aaaaa"; print '"' . preg_replace('/.*/','x',$test) . '"<br>'; $test = "\n\n\n\n\n"; print '"' . preg_replace('/.*/','x',$test) . '"'; ?> the...
7
by: Margaret MacDonald | last post by:
I've been going mad trying to figure out how to do this--it should be easy! Allow the user to enter '\_sometext\_', i.e., literal backslash, underscore, some text, literal backslash, underscore...
2
by: Fotozine | last post by:
well, I have this peace of code which isn't woking as I would like it to work. $tekst = preg_replace('/\\\"/', '&quot;', $tekst); In my forms, I would like to change " to &quot; but this line is actualy...
3
by: Charles | last post by:
I'm new to this regular expression stuff. I'd like to use preg_replace to eliminate a known multi-line signature from the body of an E-mail. Say the body text is in $body, and the sig is this ...
5
by: julianmlp | last post by:
I'm fairly new to regex code, and I'm trying to find a way to replace any text after "///" (three slashes) and before a "\n" character. I've tried with: $filen = preg_replace("///./\n$", "",...
8
by: erikcw | last post by:
Hi all, I'm trying to write a regex pattern to use in preg_replace. Basically I want to put around every line (\n) in this variable. However, I need to exclude lines that already have brackets...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.