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

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -