Extract specific part of a string in PHP

前端 未结 4 1719
一整个雨季
一整个雨季 2021-01-14 01:03

I was simply wondering what would be the simplest and most efficient way of extracting a certain part of a dynamic string in PHP?

Per example, in this string:

<
4条回答
  •  逝去的感伤
    2021-01-14 01:28

    One of the following:

    preg_match('~/[^/]*$~', $str, $matches);
    echo $matches[0];
    

    Or:

    $parts = explode('/', $str);
    echo array_pop($parts);
    

    Or:

    echo substr($str, strrpos($str, '/'));
    

提交回复
热议问题