2013-04-15 27 views

回答

5

使用正則表達式:

$string = '~1~~2~~3~'; 
preg_match_all('/~(\w+)~/', $string, $m); 
print_r($m[1]); 
3
preg_match_all('/([\d]+)/', $string, $match); 
1

我想匹配的數字:

preg_match_all("/(\d+)/", $string, $numbers) 
4

嘗試用:

$input = '~1~~2~~3~'; 
$output = array(); 

foreach (explode('~~', $input) as $val) { 
    $output[] = (int) trim($val, '~'); 
} 
1

好,只是讓你有充分的變異在您的處置下在陽光下... :-)

$s = '~1~~2~~3~'; 
$a = preg_split('/~+/', $s, -1, PREG_SPLIT_NO_EMPTY); 

run code

相關問題