- Code: Tout sélectionner
if(preg_match_all('#<(?:iframe|object|video|embed)[^>]+>.*</(?:iframe|object|video|embed)>#i', $content, $embeds, PREG_SET_ORDER)) {
foreach($embeds as $i => $embed) {
$patterns[$i] = '#' . $embed[0] . '#i';
preg_match('#(?:src|value)="([^"]+)"#', $embed[0], $matches[$i]);
$replacements[$i] = '<code>' . esc_html($matches[$i][1]) . '</code>';
}
$content = preg_replace($patterns, $replacements, $content, -1, $n);
$content .= '<code>' . esc_html(var_export($embeds, true)) . '</code> Count:' . count($matches) . ' Replacements: ' . $n;
} else $content = $content;
return $content;
Résultats :
- Code: Tout sélectionner
array ( 0 => array ( 0 => '<iframe src="//www.dailymotion.com/embed/video/x469mwq" width="480" height="270" frameborder="0" allowfullscreen="allowfullscreen"></iframe>', ), 1 => array ( 0 => '<iframe src="https://www.youtube.com/embed/SpKgCOawNbU" width="560" height="315" frameborder="0" allowfullscreen="allowfullscreen"></iframe>', ), 2 => array ( 0 => '<object width="480" height="270"><param name="movie" value="http://www.dailymotion.com/swf/x19ivz3?syndication=132352&logo=0&info=0" /><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="wmode" value="transparent" /><embed type="application/x-shockwave-flash" src="http://www.dailymotion.com/swf/x19ivz3?syndication=132352&logo=0&info=0" width="480" height="270" wmode="transparent" allowfullscreen="allowfullscreen" allowscriptaccess="always" /></object>', ), 3 => array ( 0 => '<video controls width="220" height="140" poster=""><source src="http://deransart.fr/Culturisme/Les%20culturistes%20à%20la%20Foire%20de%20Paris.mp4" type="video/mp4"></video>', ), 4 => array ( 0 => '<iframe src="https://player.vimeo.com/video/140255843" width="640" height="360" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>', ), ) Count:5 Replacements: 4
J'ai perdu le troisième (n°2) en route…