duanpasi6287 2011-06-01 21:04 采纳率: 100%
浏览 87

PHP - Preg_match帮助

I am trying to parse PHPIDS's XML rule list (downloadable on their site http://phpids.org/), against the entered URL using the XML's regular expressions.

Now, i know very little about regex, and i've tried looking around and i haven't found much information on it which i've found helpful.

What i'd like to do is something like this (psuedo) if URL == regex die();

This is my latest attempt, of many:

<?php
$file="default_filter.xml";
$load = simplexml_load_file($file);

$regex = $load->filter->rule;
$url = explode(" ","http://localhost/test.php");
$url2 = "http://localhost/test.php";
if(in_array($regex,$url))
{
echo "bad url";
}
if(preg_match($regex,$url2))
{
echo "bad url";
}
//The above gives me Warning: preg_match() [function.preg-match]: Unknown modifier '|' in C:\wamp\www\test.php on line 12
//Which, already i don't understand regex so i dont know why the above is a problem...
?>

If i can get it to work, i'll loop through the rules, but for now i'm just trying 1 regex to get it working.

but i cannot figure out get the regex working.

This is the regex which is being pulled from the XML file:

<rule><![CDATA[(?:"[^"]*[^-]?>)|(?:[^\w\s]\s*\/>)|(?:>")]]></rule>

although i do not understand one bit of that...

Thanks in advance to anyone who can assit me.

  • 写回答

2条回答 默认 最新

  • duangekui7451 2011-06-01 21:08
    关注

    About the only thing I can say is the delimiters are missing. Given that the $regex contains only the regex and not the <![CDATA[ portion this should work:

    if(preg_match('#'.$regex.'#',$url2))
    

    Give that a shot.

    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP