亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

echo $match[0]; //$match[0]和$match[1]區別在哪?

<?php

//請修改變量p的正則表達式,使他能夠匹配str中的姓名

$p = '/[\w]+(\:[a-z]+\s[\w]+)/';

$str = "name:steven jobs";

preg_match($p, $str, $match);

echo $match[0]; //$match[0]和$match[1]區別在哪?


正在回答

2 回答

$match是數組,$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
)

2 回復 有任何疑惑可以回復我~
#1

web_東 提問者

非常感謝!
2016-12-11 回復 有任何疑惑可以回復我~

是()中指定要的元素是什么意思?

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

echo $match[0]; //$match[0]和$match[1]區別在哪?

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號