PHP Explode from first number (integer)

大城市里の小女人 提交于 2019-12-12 15:16:50

问题


I want to explode some test with first number (integer) in it . Here are some words .

Avant Browser 2013 Build 110

Firefox 23.0 Beta 10

Google Chrome 29.0.1547.41 Beta

i am trying this but its not working.

$in ='Avant Browser 2013 Build 110';

preg_match("/\d[^A-Za-z]+([A-Za-z\s]+)/", $in, $match);

echo $match[0];

Output needed is :-

Avant Browser

Firefox

Google Chrome

Please help


回答1:


Try this regex:

^.*?(?=\d)    //start lookup from linestart, get all symbols before first number occurance



回答2:


Try this regex:

^[^0-9]+    // get all non-numeric character and stop when it meets numeric character..



回答3:


Here usng preg_match_all

$txt =<<<EOT
Avant Browser 2013 Build 110
Firefox 23.0 Beta 10
Google Chrome 29.0.1547.41 Beta
EOT;

preg_match_all('/^([^0-9]*)/m',$txt,$match);

var_dump($match);


来源:https://stackoverflow.com/questions/18031055/php-explode-from-first-number-integer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!