开发者

How to get quickly two data from this String data?

开发者 https://www.devze.com 2023-04-04 09:54 出处:网络
There is this String data from the column value of a table column : /var/www/imfmobile/photoj2meupload/7455575/photo32.png

There is this String data from the column value of a table column : /var/www/imfmobile/photoj2meupload/7455575/photo32.png

I want to get the 7455575 and the photo32.png substring's. How to a开发者_JAVA技巧chieve that quickly ?


use explode to split the string at /:

$parts = explode('/',$mystring);

and then just use array_pop to get the values:

$filename = array_pop($parts);
$foldername = array_pop($parts);


$str = '/var/www/imfmobile/photoj2meupload/7455575/photo32.png';
$arr = explode('/', $str);
echo end($arr); // photo32.png
echo prev($arr); // 7455575


You might want to look at the pathinfo() and basename() functions:

$path_parts = pathinfo('/var/www/imfmobile/photoj2meupload/7455575/photo32.png');

echo basename( $path_parts['dirname'] ) . "\n";
echo $path_parts['basename'] . "\n";

Will output:

7455575
photo32.png
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号