1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| function preg_match_all_callback($regex, $callback, $string, &$result)
{
preg_match_all($regex, $string, $matches);
foreach($matches as $match)
{
if (call_user_func($callback, $match))
{
$result[] = $match;
}
}
}
function test_string($match)
{
// Si on trouve http:// non suivi de www.lebon.com
// Si on trouve acceuil non précédé de /de/ ou /es/ ou /it/ ou /nl/ ou /pt/ ou /gb/ ou /fr/
// Si on trouve un mot (\b) qui commence par imag
// On retourne FALSE (faux)
if( preg_match('#http://(?!www.lebon.com/)#', $match[1]) || preg_match('#(?<!/(de|es|it|nl|pt|gb|fr)/)acceuil#', $match[1]) || preg_match('#\bimag#', $match[1]) )
{
return FALSE;
}
return TRUE;
}
preg_match_all_callback('#<a href="(.*)"#Ui', 'test_string', $chaine, $matches); |