Skip to content

Instantly share code, notes, and snippets.

@bkmorse
Created December 5, 2013 16:38
Show Gist options
  • Select an option

  • Save bkmorse/7808733 to your computer and use it in GitHub Desktop.

Select an option

Save bkmorse/7808733 to your computer and use it in GitHub Desktop.
<?php
$string = 'food-q-c-1279-303-6.jpg';
$pattern = '\.\w+';
$replacement = '_small$1';
echo preg_replace($pattern, $replacement, $string);
?>
@zacwasielewski
Copy link
Copy Markdown

Try this:

$pattern = '(.+)\.([a-z]+)';
$replacement = '$1_small.$2';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment