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

AndrewB
  • 764
  • 1
  • 6
  • 25

2 Answers2

1

You should start and end your pattern string with a delimiter character; usually that's /, but since you're matching HTML, choose something you won't be using tomorrow.

alexis
  • 48,685
  • 16
  • 101
  • 161
1

You're missing the delimiters at each end of your pattern so it's seeing this

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

Try adding / as a delimiter

$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)*/";
Popnoodles
  • 28,090
  • 2
  • 45
  • 53