473,406 Members | 2,549 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,406 software developers and data experts.

A simple preg_replace escaping problem

Hi I'm having trouble running the following preg_replace:

$thestring = preg_replace( '!<a href="javascript:radio('/0radio/
stream.php?radioID=(.*?)')" class="radioPlay">(.*?)</a>!' ,
"[radio:\\1]", $thestring );

Can anyone help me escape the ' apostrophe? I've tried all
combinations of \ in front of the ' characters but nothing seems
to work.

Cheers,
Ciarán
Jun 2 '08 #1
4 1857
Ciaran wrote:
Hi I'm having trouble running the following preg_replace:

$thestring = preg_replace( '!<a href="javascript:radio('/0radio/
stream.php?radioID=(.*?)')" class="radioPlay">(.*?)</a>!' ,
"[radio:\\1]", $thestring );

Can anyone help me escape the ' apostrophe? I've tried all
combinations of \ in front of the ' characters but nothing seems
to work.

Cheers,
Ciarán
Take a look at preg_quote()
Jun 2 '08 #2
On Apr 24, 7:52 pm, "Paul Lautman" <paul.laut...@btinternet.com>
wrote:
Ciaran wrote:
Hi I'm having trouble running the following preg_replace:
$thestring = preg_replace( '!<a href="javascript:radio('/0radio/
stream.php?radioID=(.*?)')" class="radioPlay">(.*?)</a>!' ,
"[radio:\\1]", $thestring );
Can anyone help me escape the ' apostrophe? I've tried all
combinations of \ in front of the ' characters but nothing seems
to work.
Cheers,
Ciarán

Take a look at preg_quote()

Ah! Very handy! Thanks a lot!
Jun 2 '08 #3
Ciaran wrote:
On Apr 24, 7:52 pm, "Paul Lautman" <paul.laut...@btinternet.com>
wrote:
>Ciaran wrote:
Hi I'm having trouble running the following preg_replace:
$thestring = preg_replace( '!<a
href="javascript:radio('/0radio/
stream.php?radioID=(.*?)')" class="radioPlay">(.*?)</a>!' ,
"[radio:\\1]", $thestring );
Can anyone help me escape the ' apostrophe? I've tried all
combinations of \ in front of the ' characters but nothing
seems to work.
Cheers,
Ciarán

Take a look at preg_quote()


Ah! Very handy! Thanks a lot!
Although I always thought that preg_escape() would have been a better name.
Jun 2 '08 #4
..oO(Paul Lautman)
>Ciaran wrote:
>On Apr 24, 7:52 pm, "Paul Lautman" <paul.laut...@btinternet.com>
wrote:
>>Take a look at preg_quote()

Ah! Very handy! Thanks a lot!

Although I always thought that preg_escape() would have been a better name.
function preg_escape($str, $delimiter = NULL) {
return preg_quote($str, $delimiter);
}

SCNR
Micha
Jun 2 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

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)...
8
by: Jochen Daum | last post by:
Hi, I'd like to use something like preg_replace("...","$this->somefunction('\\1','\\2');", $content); It says "Cannot find function somefunction()" I tried some escaping, but didn't...
2
by: Stijn Goris | last post by:
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...
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...
1
by: rybasso | last post by:
Hello, Does anyone has an idea why preg_replace() cause 'This page contains no data' in FF and 'This page could not be found' in IE. I spend a lot of time searching any ideas on newsgroups but...
2
by: Daz | last post by:
Hi everyone. I am looking to create a simple function that will spot a hexcolor in a font tag, that has quotes, and remove the quotes. i.e <font color="ffffff"should become <font color=ffffff>. ...
5
by: helraizer1 | last post by:
Hey folks and folksesses, I have written some code to get emoticons onto my image based shoutbox but there is quite a large bug, as there is with any code in the early stages, and I need your help...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.