Get the string after a string from a string
PhpStringPhp Problem Overview
what's the fastest way to get only the important_stuff part from a string like this:
bla-bla_delimiter_important_stuff
_delimiter_
is always there, but the rest of the string can change.
Php Solutions
Solution 1 - Php
here:
$arr = explode('delimeter', $initialString);
$important = $arr[1];
Solution 2 - Php
$result = end(explode('_delimiter_', 'bla-bla_delimiter_important_stuff'));
Solution 3 - Php
I like this method:
$str="bla-bla_delimiter_important_stuff";
$del="_delimiter_";
$pos=strpos($str, $del);
cutting from end of the delimiter to end of string
$important=substr($str, $pos+strlen($del)-1, strlen($str)-1);
note:
-
for substr the string start at '0' whereas for strpos & strlen takes the size of the string (starts at '1')
-
using 1 character delimiter maybe a good idea
Solution 4 - Php
$importantStuff = array_pop(explode('delimiter', $string));
Solution 5 - Php
$string = "bla-bla_delimiter_important_stuff";
list($junk,$important_stufF) = explode("_delimiter_",$string);
echo $important_stuff;
> important_stuff