Getting anchor name with php regex -
i need capture name of anchor html tag regex , php text "hello" (the name of anchor)
tried that:
$regex  = '/(?<=name\=")#([^]+?)#(?=")/i';   preg_match_all($regex, $content, $data); print_r($data); i've tailed apache error log find out that:
php warning: preg_match_all(): compilation failed: missing terminating ] character class @ offset 26
also tried:
$regex  = '/(?<=name\=")([^]+?)(?=")/i';  $regex  = '/(?<=name\=")[^]+?(?=")/i';  which same. guess i'm missing something, silly slash or i'm not sure what
will appreciated thanks
solved
ok, @stillstanding , @gordon i've managed domdocument simple so, record, here snippet
$dom = new domdocument;     $dom->loadhtml($content);     foreach( $dom->getelementsbytagname('a') $node ) {         echo $node->getattribute( 'name' );     } 
use domxpath along domdocument or simplexml. never, ever use regex patterns!
Comments
Post a Comment