0

I am trying to execute this function:

   public function get_referring_domains(){
        $pattern='/<p>Referring<b>Class C subnets<\/b>: <b>(.*?)<\/b> <\/p>/';
        $result=  preg_match_all($pattern, $this->dom, $matches, PREG_SET_ORDER);
        return $result;
   }

The result that I want to get is a number , as you can see in the pattern that I set, I want to get: ([0-9]+)... But I get 0 every time..why the pattern doesnt match?

This is what I am trying to match:

$pattern='/<p>Referring[\s]{1}<b>Class[\s]{1}C\ssubnets</b>:[\s]{1}<b>(.*?)</b>[\s]{1}</p>/i';

I get this:

preg_match_all() [function.preg-match-all]: Unknown modifier 'b'

  <p>Referring <b>Class C subnets</b>: <b>4,613</b> </p>

It is part of an html page

UPDATE. changed to this:

Dmitry Makovetskiyd
  • 6,942
  • 32
  • 100
  • 160

2 Answers2

2

You're missing some whitespace, it should be this:

$pattern = '/<p>Referring <b>Class C subnets<\/b>: <b>(.*?)<\/b> <\/p>/';

Also, I'd really suggest using DOMDocument instead of regex.

Read this: How to parse and process HTML with PHP?

Community
  • 1
  • 1
Jeroen
  • 13,056
  • 4
  • 42
  • 63
0

There should be a space after Referring

buckley
  • 13,690
  • 3
  • 53
  • 61