Home » Php » php – Get the string after a string from a string

php – Get the string after a string from a string

Posted by: admin April 23, 2020 Leave a comment

Questions:

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.

How to&Answers:

here:

$arr = explode('delimeter', $initialString);
$important = $arr[1];

Answer:

$result = end(explode('_delimiter_', 'bla-bla_delimiter_important_stuff'));

Answer:

$importantStuff = array_pop(explode('_delimiter_', $string));

Answer:

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:

1) for substr the string start at ‘0’ whereas for strpos & strlen takes the size of the string (starts at ‘1’)

2) using 1 character delimiter maybe a good idea

Answer:

$string = "bla-bla_delimiter_important_stuff";
list($junk,$important_stufF) = explode("_delimiter_",$string);

echo $important_stuff;
> important_stuff