0

I'm aware there are similar questions and I have looked at a few of them however even with that knowledge I haven't been able to solve my own problem. I would greatly appreciate it if anyone could point out the problem to me!

function getCategories($source)
{
    $pattern = "<span class=\".*\" id=\".*\">.*<.span>.*<table class=\".*\".*>
<tr>
<th.*
<.th>
<th.*
<.th>
<th.*
<.th>
<th.*
<.th>
<th.*
<.th>
<th.*
<.th><.tr>
(<tr id=\".*\">\n(.*\n){6}<.td><.tr>(<.table>)?\n)*";

    preg_match($pattern, $source, $categories);

    return $categories;
}

With the error message:

Warning: preg_match() [function.preg-match]: Unknown modifier '.' in /home/a1464157/public_html/functions.php on line 31

Line 31 is "preg_match(...)".

I am sure the regex should work as I have tested it in a tool, and the correct string is definitely being passed through, it just doesn't like my reg. expression for some reason. I've tried to make sure everything was either escaped or replaced with a . (last resort when escaping the / didn't work).

Any assistance would be greatly appreciated! Thank you!

~Andrew

4

2 回答 2

1

您应该使用分隔符开始和结束您的模式字符串;通常是/,但由于您正在匹配 HTML,请选择您明天不会使用的内容。

于 2013-10-20T22:12:59.527 回答
1

您在模式的每一端都缺少分隔符,所以它看到了这个

$pattern = "<span class=\".*\" id=\".*\">.*<.span>.*<table class=\".*\".*>
            ^ opening delimiter            ^ closing delimiter followed by a modifier

尝试添加/为分隔符

$pattern = "/<span class=\".*\" id=\".*\">.*<.span>.*<table class=\".*\".*>
<tr>
<th.*
<.th>
<th.*
<.th>
<th.*
<.th>
<th.*
<.th>
<th.*
<.th>
<th.*
<.th><.tr>
(<tr id=\".*\">\n(.*\n){6}<.td><.tr>(<.table>)?\n)*/";
于 2013-10-20T22:13:53.837 回答