我正在编写一个php,用于使用preg match all标签匹配代码。
下面是我的PHP代码
preg_match_all('|SentSmsId('d*?)&noOfMessages|i', $data, $code);
回声"代码"美元;
这里是HTML代码。
<a href="sentSms.php?zxcoiesesscd=&SentSmsId=8830978&NoOfMessages=" style="text-decoration:none;"
我想匹配sentsmsid代码并回显它。
但不工作
您的正则表达式中缺少=
,
preg_match_all('|SentSmsId=('d*?)&noOfMessages|i', $data, $code);
print_r($code);
工作演示。
你需要考虑到=
。SentSmsId ' = (' d * ?), noOfMessages
这是当你有几个代码包含在$data:
preg_match_all('~SentSmsId='K'd++(?=&noOfMessages)~', $data, $codes);
print_r($codes);
但是,如果您只查找1个代码,您最好使用preg_match。