打印此字符串中的数字总和


To print sum of numbers from this string

在采访中被问及如何从这个字符串中打印数字的总和我尝试了基本的算术运算,但没有成功。

$str="欢迎13,14,15,ab16,14ab";

您可以使用它来分离文本和数字,然后继续,

preg_match_all('/[^'d]+/', $string, $textMatch);
preg_match('/'d+/', $string, $numMatch);
$text = $textMatch[0];
$num = $numMatch[0];