<?php
// 1. Identify the block of <a> elements
$string = '<div><a href=%http://link1%><img></a><a href=%http://link2%><img></a><a href=%http://link3%><img></a></div>';
$re = '|<div>((<a((?!href)(?!<).)+?href=%([^%]+?)%((?!</a>).)+?</a>){3})</div>|';
$matches = array();
echo('result='.intval(preg_match($re, $string, $matches))."\n");
echo('$matches='); print_r($matches);
/*
// 2. Split it into individual <a> elements
$re = '|(?<=</a>)(?=<a)|';
$pieces = preg_split($re, $matches[1]);
echo('$pieces='); print_r($pieces);
// 3. Analyze each <a> element, extract the interesting components
$re = '|href=%([^%]*)%|';
foreach ($pieces as $a) {
$matches = array();
if (preg_match($re, $a, $matches)) {
echo($a.': '.$matches[1]."\n");
}
}
*/
$re = '|<a((?!href)(?!<).)+?href=%([^%]+?)%((?!</a>).)+?</a>|'
preg_match_all($re, $matches[1], $matches);
print_r($matches);
- Output for 5.4.0 - 5.4.40, 5.5.24, 5.6.8
- Parse error: syntax error, unexpected 'preg_match_all' (T_STRING) in /in/PDoTe on line 25
Process exited with code 255. - Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
- Parse error: syntax error, unexpected T_STRING in /in/PDoTe on line 25
Process exited with code 255. - Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
- Parse error: parse error, unexpected T_STRING in /in/PDoTe on line 25
Process exited with code 255. - Output for 4.3.2 - 4.3.4
- Parse error: parse error in /in/PDoTe on line 25
Process exited with code 255.
preferences:
223.23 ms | 1399 KiB | 132 Q