preg_match();- 未知修饰符“+" [英] preg_match(); - Unknown modifier '+'

查看:38
本文介绍了preg_match();- 未知修饰符“+"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我目前正在解析 RSS 提要.我已经得到了我需要的数据,没有问题,剩下的就是解析游戏标题.

Alright, so I'm currently working on parsing an RSS feed. I've gotten the data I need no problem, and all I have left is parsing the game title.

这是我目前拥有的代码(忽略草率,这只是一个概念证明):

Here is the code I currently have (ignore the sloppiness, it is just a proof of concept):

<?php
$url = 'http://raptr.com/conexion/rss';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$result = curl_exec($ch); 
curl_close($ch);

$xml = new SimpleXMLElement($result);

$lastgame = $xml->channel->item[0]->description;
preg_match('[a-zA-Z]+</a>.$', $lastgame, $match);

echo $match;
?>

一切都很好,但后来我开始收到这个错误:

Everything was working great, but then I started getting this error:

Warning: preg_match() [function.preg-match]: 
Unknown modifier '+' in raptr.php on line 14

我唯一剩下的就是去掉结束锚标记和句点,但我似乎无法弄清楚为什么它不喜欢+".有什么想法吗?

The only thing I have left is to strip out the closing anchor tag and the period, but I can't seem to figure out why it isn't liking the '+'. Any ideas?

这不应被标记为重复,因为它是在另一个问题两年前提出的.

This should not be marked as a duplicate as it was asked two years before the other question.

推荐答案

您需要在 PHP 中使用带有正则表达式的分隔符.您可以使用常用的/,但PHP 允许您使用任何匹配的字符,因此@# 很受欢迎.

You need to use delimiters with regexes in PHP. You can use the often used /, but PHP lets you use any matching characters, so @ and # are popular.

进一步阅读.

如果您在正则表达式中插入变量,请确保将您选择的分隔符作为第二个参数传递给 preg_quote().

If you are interpolating variables inside your regex, be sure to pass the delimiter you chose as the second argument to preg_quote().

这篇关于preg_match();- 未知修饰符“+"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆