0

I have a url that ends with _s.jpg. The URL is set to a variable, and it called later on. Before it's called I need to slice the URL and remove _s.jpg and add _o.jpg.

$img_src = $data['picture'];

This returns my url

http://photos-b.ak.fbcdn.net/hphotos-ak-snc7/416968_4827318927507_851357969_s.jpg

I need the $img_src URL changed and then put into a new variable $new_img_src

I know I can do it with jQuery, but I need it done in PHP.

Thanks

Ryan
  • 2,144
  • 8
  • 28
  • 39
  • 1
    Use [`str_replace()`](http://php.net/str_replace) for simplicity, or [`preg_replace`](http://php.net/preg_replace) for asserting the structure. – mario Oct 29 '12 at 23:17
  • possible duplicate of [change file extension in php?](http://stackoverflow.com/questions/1724612/change-file-extension-in-php) – mario Oct 29 '12 at 23:19

1 Answers1

3
$new_img_src = str_replace('_s.jpg', '_o.jpg', $data['picture']);

this ought to work...

nathan hayfield
  • 2,627
  • 1
  • 17
  • 28