Bryan Meyer Bryan Meyer - 11 days ago 5x
PHP Question

PHP remove characters after a specific string for a certain length

I have a string that is:

<p><img src="../filemanager/image.png?1476187745382"/></p> some text ...

I would like to remove everything after a
when question mark occurs. The goal is to remove the timestamp added
but not the
some text ...

Keeping in mind that the timestamp, will change and the what comes after the the image
will also be different.

I have looked at different solutions, but they all remove either the exact occurrence or everything after a certain character, which is not what I need to do.

This is what I have looked at:

  1. PHP remove characters after last occurrence of a character in a string

  2. Remove portion of a string after a certain character

Can someone point me to the right direction?


Not always needed, but a regex will do it:

$string = preg_replace('/\?[\d]{13}/', '', $string);

If the timestamp is not always 13 digits then replace the {13} with just a +.