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

PHP preg_replace

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.