There are similar questions in SO, but I couldn't find any exactly like this. I need to remove everything up to (and including) a particular delimiter. For example, given the string File:MyFile.jpg
, I need to remove everything up to the :
, so that I'm left with only MyFile.jpg
. Thanks in advance!
Use this preg_replace call:
$str = 'File:MyFile.jpg';
$repl = preg_replace('/^[^:]*:/', '', $str); // MyFile.jpg
OR else avoid regex and use explode like this:
$repl = explode(':', $str)[1]; // MyFile.jpg
EDIT: Use this way to avoid regex (if there can be more than one : in string):
$arr = explode(':', 'File:MyFile.jpg:foo:bar');
unset($arr[0]);
$repl = implode(':', $arr); // MyFile.jpg:foo:bar
EDIT: this one works fine.
$str = "File:MyFile.jpg";
$str = substr( $str, ( $pos = strpos( $str, ':' ) ) === false ? 0 : $pos + 1 );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With