-2

I have tried, read and searched to to avail. I just need to replace -m_ with -b_ in a string containing an image name / location.

For instance: I just want to replace;

some-image-name-hyphenated-m_15235101.jpg

with

some-image-name-hyphenated-b_15235101.jpg

Easy right?

$mediumimage = 'some-image-name-hyphenated-b_15235101.jpg';

I tried

$biggerimage = preg_replace("-m_", "-b_", $mediumimage);

and

$biggerimage = preg_replace('-m_', '-b_', $mediumimage);

Also backslashing along with other tries resulting from searches.

Warning: preg_replace(): No ending delimiter '-' found

I don't feel well right now...

I beseech anyone who is smarter than me e.g..... any one here.

Ivan Chernykh
  • 41,617
  • 13
  • 134
  • 146
  • The warning tells something is wrong with the arguments you pass to the [`preg_replace()`](http://php.net/manual/en/function.preg-replace.php) function. Take a look at the [documentation](http://php.net/manual/en/regexp.reference.delimiters.php). – axiac Dec 17 '16 at 16:05

1 Answers1

0

Try use $biggerimage = str_replace("-b_", "-m_", $mediumimage);

No name
  • 136
  • 1
  • 7