$match是數(shù)組,$match[0]是其第一個元素,是取回的全匹配元素,$match[2]是其第二個元素,是()中指定要的元素。 你可以使用$str="other words name:steven jobs others thing"; 測試print_r($match); 的輸出,會更清晰:
<?php
$p = '/[\w]+\:([a-z]+\s[\w]+)/i';
$str="other words name:steven jobs others thing";
preg_match($p, $str, $match);
print_r($match);
?>
輸出: Array ( ? ?[0] => name:steven jobs ? ?[1] => steven jobs )
2016-12-11
$match是數(shù)組,$match[0]是其第一個元素,是取回的全匹配元素,$match[2]是其第二個元素,是()中指定要的元素。 你可以使用$str="other words name:steven jobs others thing"; 測試print_r($match); 的輸出,會更清晰:
<?php
$p = '/[\w]+\:([a-z]+\s[\w]+)/i';
$str="other words name:steven jobs others thing";
preg_match($p, $str, $match);
print_r($match);
?>
輸出:
Array
(
? ?[0] => name:steven jobs
? ?[1] => steven jobs
)
2017-03-20
是()中指定要的元素是什么意思?