0

I have this img tag

<img src="../img/tmp/pack_mini_5753_.jpg?time=1464793546" alt="" class="imgm img-thumbnail">

I would like to delete the string ?time=1464793546. I have the time a dynamic variable so 1464793546 will change dependent on time.

I tried this

 $image_tag = ImageManager::thumbnail($path_to_image, 'pack_mini_'.$pack_item->id.'_'.$this->context->shop->id.'.jpg', 120);
                        var_dump($image_tag);
 $pattern = '/(\w+)?time=(\d+)/i';
 $replacement = '${1}';
 $pack_items[$i]['image'] =preg_replace($pattern, $replacement, $image_tag);
 var_dump($pack_items[$i]['image']);exit;

$image_tag returns the img tag

<img src="../img/tmp/pack_mini_5753_.jpg?time=1464793546" alt="" class="imgm img-thumbnail">

Var_dump return null.

chris85
  • 23,846
  • 7
  • 34
  • 51
tarek fellah
  • 365
  • 1
  • 10
  • 32

1 Answers1

1

You forgot to escape the question mark which has special meaning in regex. Just escape it:

$pattern = '/\?time=(\d+)/i';
chris85
  • 23,846
  • 7
  • 34
  • 51
splash58
  • 26,043
  • 3
  • 22
  • 34