Php regex ile çapa adı alınıyor

0 Cevap php

Metin ben "merhaba" (çapa adını) alacak kadar ben regex ve php ile bir çapa html etiketinin adını yakalamak gerekiyor

Denedim:

$regex  = '/(?<=name\=")#([^]+?)#(?=")/i';  
preg_match_all($regex, $content, $data);
print_r($data);

Bunu öğrenmek için apache hata günlüğünü kuyruklu ettik:

PHP Warning: preg_match_all(): Compilation failed: missing terminating ] for character class at offset 26

Ayrıca çalıştı:

$regex  = '/(?<=name\=")([^]+?)(?=")/i'; 
$regex  = '/(?<=name\=")[^]+?(?=")/i'; 

which are basically the same. I guess I'm missing something, probably a silly slash or something like that but I'm not sure as to what

Will appreciated any help Thanks

SOLVED

Ok, Thanks to @stillstanding and @Gordon I've managed to do that with DOMDocument which is much simple so, for the record, Here is the Snippet

$dom = new DOMDocument;
    $dom->loadHTML($content);
    foreach( $dom->getElementsByTagName('a') as $node ) {
        echo $node->getAttribute( 'name' );
    }

0 Cevap