How can I remove everything before the first ABC in a string?
So that this: somethingrandomABCotherrandomstuffABCmorerandomstuffABC
turns to this: otherrandomstuffABCmorerandomstuffABC.
Is this possible with php?
How can I remove everything before the first ABC in a string?
So that this: somethingrandomABCotherrandomstuffABCmorerandomstuffABC
turns to this: otherrandomstuffABCmorerandomstuffABC.
Is this possible with php?
There is a php built in for doing this: strstr
Combine with substr to strip out your token:
$out = substr(strstr($text, 'ABC'), strlen('ABC'))
<?php
function removeEverythingBefore($in, $before) {
$pos = strpos($in, $before);
return $pos !== FALSE
? substr($in, $pos + strlen($before), strlen($in))
: "";
}
echo(removeEverythingBefore("somethingrandomABCotherrandomstuffABCmorerandomstuffABC", "ABC"));
?>
Outputs:
otherrandomstuffABCmorerandomstuffABC