我这里有一个PHP代码
<?php
$txtnum = "Called Number Call Type Call Time Call Duration Call Charges
9231332454834 SMS2/5/2019 9:31:15
AM-- Minutes 0.00 PKR 9230374555790 SMS2/4/2019 8:42:07
PM-- Minutes 0.00 PKR
";
?>
现在我想得到如下的输出
9231332454834
9230374555790
请帮助我在Php中如何做到这一点
你可以用preg_match_all()
做到这一点。从我的角度来看,一个非正则表达式解决方案与PHP函数,如array_filter()
<?php
$txtnum = "Called Number Call Type Call Time Call Duration Call Charges 9231332454834 SMS2/5/2019 9:31:15 AM-- Minutes 0.00 PK 9230374555790 SMS2/4/2019 8:42:07 PM-- Minutes 0.00 PKR";
$words = explode(' ', $txtnum);
$result = array_filter($words, 'ctype_digit');
echo implode(PHP_EOL, $result);
?>
输出:
9231332454834
9230374555790
但是:Kua zxsw指出
就像是....
https://3v4l.org/GCViG