使用PHP在字符串的开头获取一个int


Get an int at the beginning of a string with PHP

假设我有:

$yeah='71263andsomemore632';

如何我可以得到这样的两个变量:

$intAtBeginning=71263;
$theRest='andsomemore632';

我真的不知道该怎么做,因为两个整数的长度可能不同。我保证我会研究你帮我做的任何事情,理解它,今天睡得开心;)

谢谢。

一个简单的方法是使用sscanf

list($intAtBeginning, $theRest) = sscanf($yeah, '%d%s');
echo $intAtBeginning.'<br>'.$theRest;