2012-08-14 31 views

回答

1
$id = substr(strstr($name, '_', true), 5); 
1

我会尝试正则表达式:

preg_match("/(?:\d){6}(\d+)/", "1330001337_jenir.jpg", $matches); 

echo $matches[2]; 
+0

这可能为'改善/(?:\ d){6}(\ d +)/'。这样,前6位数字不会以匹配形式返回,然后下一个组就是整组数字 - 不需要检查下划线或任何其他字符。 – newfurniturey 2012-08-14 06:55:20

+0

@newfurniturey:谢谢。我不得不停止使用那些非贪婪的捕捉组... – Blender 2012-08-14 07:05:09

0

试试这个代码块 -

$mystr = "1330001337_jenir.jpg"; 

echo substr($mystr,6,4); 
0

只需

<?php 
$myStr='1330001337_jenir.jpg'; 

$strArray=explode($myStr,'-'); 
$numStr=substr($strArray[0],6); //returns 1337 

$nameStr=substr($strArray[1],0,-4); //returns jenir 

?>