Get the string after a string from a string

前端 未结 5 1478
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-08 09:36

what\'s the fastest way to get only the important_stuff part from a string like this:

bla-bla_delimiter_important_stuff

5条回答
  •  离开以前
    2020-12-08 09:51

    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

提交回复
热议问题