Get the string after a string from a string

前端 未结 5 1477
佛祖请我去吃肉
佛祖请我去吃肉 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:46
    $result = end(explode('_delimiter_', 'bla-bla_delimiter_important_stuff'));
    
    0 讨论(0)
  • 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

    0 讨论(0)
  • 2020-12-08 10:01

    here:

    $arr = explode('delimeter', $initialString);
    $important = $arr[1];
    
    0 讨论(0)
  • 2020-12-08 10:02
    $importantStuff = array_pop(explode('_delimiter_', $string));
    
    0 讨论(0)
  • 2020-12-08 10:05
    $string = "bla-bla_delimiter_important_stuff";
    list($junk,$important_stufF) = explode("_delimiter_",$string);
    
    echo $important_stuff;
    > important_stuff
    
    0 讨论(0)
提交回复
热议问题