473,320 Members | 1,832 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,320 software developers and data experts.

PHP preg_replace

I have a very specific need. Too long to get into what and why here (If
you please).

I have this test code...

$_str = "testing that'S supposed to work!"; // Notice the CAP 'S, this
is the key!

$suffixes = "'S";
$str = preg_replace("/(\\w)($suffixes)\\b/e", '"$1".strtolower("$2")',
$_str);
echo $str;
exit;

It gives me this...

TESTING THAT\'s SUPPOSED TO WORK!

Notice the SLASH?

I don't want the slash. Beyond that, this does what I want it to do.

Please understand, this code is for example only. The question focuses
around the preg_replace(), not on how I get/create "$_str"
Any ideas?

Thanks
WAlter

Jun 16 '06 #1
1 1667
ot*******@gmail.com wrote:
I have a very specific need.
Too long to get into what and why here (If you please).
Unclear to me what purpose that statement serves. Ie. does it benefit
you to state it?
I have this test code...

$_str = "testing that'S supposed to work!"; // Notice the CAP 'S, this
is the key!

$suffixes = "'S";
$str = preg_replace("/(\\w)($suffixes)\\b/e", '"$1".strtolower("$2")',
$_str);
echo $str;
exit;

It gives me this...

TESTING THAT\'s SUPPOSED TO WORK!


Seems interesting to me, too. Evidently, php assumes that the inner
strings will be single quote delimited and pre escapes the match
strings. To fix, swap the single and double quotes:
'"$1".strtolower("$2")' => "'$1'.strtolower('$2')"

Csaba Gabor from Vienna

Jun 16 '06 #2

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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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...

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.