Php 将字符串拆分为相应的单词
如果我有一根像这样的线Php 将字符串拆分为相应的单词,php,Php,如果我有一根像这样的线 ~1~~2~~3~ 如何使用php获取数字?使用正则表达式: $string = '~1~~2~~3~'; preg_match_all('/~(\w+)~/', $string, $m); print_r($m[1]); 我会匹配数字: preg_match_all("/(\d+)/", $string, $numbers) 尝试: $input = '~1~~2~~3~'; $output = array(); foreach ( explode('~~',
~1~~2~~3~
如何使用php获取数字?使用正则表达式:
$string = '~1~~2~~3~';
preg_match_all('/~(\w+)~/', $string, $m);
print_r($m[1]);
我会匹配数字:
preg_match_all("/(\d+)/", $string, $numbers)
尝试:
$input = '~1~~2~~3~';
$output = array();
foreach ( explode('~~', $input) as $val ) {
$output[] = (int) trim($val, '~');
}
好吧,只是为了让你在阳光下有各种各样的变化供你支配…:-)
$input = '~1~~2~~3~';
$output = array();
foreach ( explode('~~', $input) as $val ) {
$output[] = (int) trim($val, '~');
}
$s = '~1~~2~~3~';
$a = preg_split('/~+/', $s, -1, PREG_SPLIT_NO_EMPTY);