Escaping "." in preg_replace
What am I doing wrong?
<?php
$imageurl = $pagename1;
$imageurl = preg_replace('/.asp/', .$g_sites_img2.'.jpg', $pagename1);
?>
I am trying to escape the .
in the preg_replace
.
I have also tried:
<?php
$imageurl = $pagename1;
$imageurl = preg_replace('/\.asp/', .$g_sites_img2.'\.jpg', $pagen开发者_StackOverflow社区ame1);
?>
Why is it still giving me an error?
You have an extra .
before $g_sites_img2
.
$imageurl = preg_replace('/\.asp/', .$g_sites_img2.'\.jpg', $pagename1);?>
^ Here's your problem
I concur with @dtbarne -- preg_replace()
is totally unnecessary here. You should be using str_replace()
instead.
It doesn't look like preg_replace is necessary.
Why can't you just use str_replace? Anyway, you've got a syntax error (an extra period).
$imageurl = preg_replace('/\.asp/', $g_sties_img2 . '.jpg', $pagename1);
Try this:
<?php $imageurl = preg_replace('/\.asp/', $g_sites_img2.'\.jpg', $pagename1);?>
Notice the missing leading .
in the 2nd argument of the preg_replace()
call. Also, there is no need for the first line since you're writing the result of preg_replace
to that variable anyway.
精彩评论