-2

Im struggling to get this PHP reg match work. I am loading file through file_get_contents() and my content will be like this,

                        <li  > 
                            <a href="http://www.example.org/index.php?id=2" >
                                Name AB 
                            </a>
                        </li>
                                                <li  > 
                            <a href="http://www.example.org/index.php?id=3" >
                                Name CD 
                            </a>
                        </li>

I want to get an array like

array('2' => 'Name AB'), array('3' => 'Name CD')

I have tried

preg_match("/([A-Z].*?[a-z].+)/", $input_line, $output_array);

It will only give me a name.

Thank you

AVM
  • 592
  • 2
  • 11
  • 25
CyberHelp
  • 63
  • 1
  • 2
  • 9
  • 3
    never use regular expression to parse html use [PHP DOM](http://php.net/manual/en/book.dom.php) – bansi Dec 18 '15 at 08:58
  • http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags – bansi Dec 18 '15 at 09:01

1 Answers1

0

try this,

$link = preg_replace("/\s+/", " ", $link);
preg_match_all('/<a[^>]*>(.*?)<\/a>/si', $link, $result);

foreach($result[1] as $i => $data){
    $arr[] = array($i => $data);
}

print_r($arr);
Rakesh Singh
  • 1,250
  • 9
  • 8