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
精彩评论