DOMDocumentを使用し、HTMLを解析するために正規表現を使用しないでください。
$html = '
<a href="link1">[BIOL 107 Section 1] Concepts in Biology</a>
<a href="link2">[CENG 230 Section 7] Introduction to C Programming</a>
<a href="link3">[CENG 230 All Sections] Introduction to C Programming</a>
';
$dom = new DOMDocument;
$dom->loadHTML($html);
$tags = $dom->getElementsByTagName('a');
$links = array();
$value = array();
foreach($tags as $a){
if (preg_match('/\ball\b/i', $a->nodeValue)) continue;
$links[] = $a->getAttribute('href');
$value[] = $a->nodeValue;
}
print_r($links);
print_r($value);
出力:
Array
(
[0] => link1
[1] => link2
)
Array
(
[0] => [BIOL 107 Section 1] Concepts in Biology
[1] => [CENG 230 Section 7] Introduction to C Programming
)
ここで質問は何ですか? _where_から行を削除しますか?これがPHPの場合、これを行うコードはどこにありますか? HTMLのいくつかの行は実際にここで続行するには十分ではありません。 – jdv
あなたが試したことをお見せしてください。しかし、それは良い練習ではありません([またはいくつかの悪い](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454))))にHTMLを解析するにはregexpを使用します。 –