我正在嘗試使用REGEX得到來自$str
變量的輸入的左右整數。但是我一直不停地把整數和逗號一起取回。我只想要整數而不是逗號。我也嘗試用\d
替換通配符.
,但仍然沒有解決方案。只有整數的PHP正則表達式
$str = "1,2,3,4,5,6";
function pagination()
{
global $str;
// Using number 4 as an input from the string
preg_match('/(.{2})(4)(.{2})/', $str, $matches);
echo $matches[0]."\n".$matches[1]."\n".$matches[1]."\n".$matches[1]."\n";
}
pagination();
請寫下您的預期輸出。 – sandeepsure
嘗試'preg_match('/(\ d +),4,(\ d +)/',$ str,$ matches);'then'$ matches [1]'將會有'3'和'$ matches [2]'將持有'5'。 –
爲什麼不使用for循環? 'for($ i = 1; $ i <$ max_pagecount; $ i ++){}' – pmayer