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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
//jeu de données
$exemples[] = array('être trop', 'Ceci être peut être trop bien.');
$exemples[] = array('être trop', '<span>Ceci peut être <br />trop </span>bien.');
$exemples[] = array('être trop', '<span>Ceci peut <a href="#">être trop</a> bien.</span>');
$exemples[] = array('être trop', '<span>Ceci peut <span>ê</span>t<span>r</span>e trop bien.</span>');
$exemples[] = array('etre trop', '<span>Ceci peut <span>e</span>t<span>r</span>e trop bien.</span>');
$exemples[] = array('trop', 'Ceci peut <span class="gras">ê</span>tre tro<em>p</em> bien.');
$exemples[] = array('trop', 'Ceci peut <span class="gras">e</span>tre tro<em>p</em> bien.');
$exemples[] = array('devices participating in a computer network, that uses', 'An <b>Internet Protocol</b> (<b>IP</b>) <b>address</b> is a numerical label that is assigned to devices participating in a <a href="http://en.wikipedia.org/wiki/Computer_network" title="Computer network" target="_blank">computer network</a>, that uses the <a href="http://en.wikipedia.org/wiki/Internet_Protocol" title="Internet Protocol" target="_blank">Internet Protocol</a> for communication between its nodes.<sup id="cite_ref-rfc760_0-0" class="reference"><a href="http://en.wikipedia.org/wiki/#cite_note-rfc760-0" target="_blank"><span>[</span>1<span>]</span></a></sup> An IP address serves two principal functions: host or network interface <a href="http://en.wikipedia.org/wiki/Identification_%28information%29" title="Identification (information)" target="_blank">identification</a> and location <a href="http://en.wikipedia.org/wiki/Logical_address" title="Logical address" target="_blank">addressing</a>. Its role has been characterized as follows: <i>"A <a href="http://en.wikipedia.org/wiki/Hostname" title="Hostname" target="_blank">name</a> indicates what we seek. An address indicates where it is. A route indicates how to get there."</i><sup id="cite_ref-rfc791_1-0" class="reference"><a href="http://en.wikipedia.org/wiki/#cite_note-rfc791-1" target="_blank"><span>[</span>2<span>]</span></a></sup>');
foreach($exemples as $exemple) {
echo '====================== DEBUT ====================== <br />';
echo 'Recherche de : "'.$exemple[0].'" dans le code html "'.htmlentities(($exemple[1])).'"<br /><br />';
$str_len = strlen($exemple[0]);
$ma_chaine_regex = "" ;
for($i = 0; $i < $str_len; ++$i ) {
//$ma_chaine_regex = $ma_chaine_regex.$exemple[0][$i]."(?:\[\/?\w\])*" ;
$ma_chaine_regex = $ma_chaine_regex.'((<\w[^>]*>)*(<\/\w>)*)*'.$exemple[0][$i];//.'((<\w[^>]*>)*(<\/\w>)*)*' ;
}
$ma_chaine_regex = '#'.$ma_chaine_regex.'#i';
echo 'Regex : '.$ma_chaine_regex.'<br /><br />';
$html = convertHtmlToLatin1($exemple[1]);
$ret = preg_match_all($ma_chaine_regex, $html, $tab, PREG_OFFSET_CAPTURE );
//print_r($tab);
echo '<br /><br />';
if ( $ret ) {
/*
print_r($tab[0][0]);
echo '<br /><br />';
*/
$start = substr($html,0, $tab[0][0][1]);
//$start = substr($html,0,-1);
$middle = $tab[0][0][0];//substr($html,$tab[0][0][1],strlen($tab[0][0][0]));
$end = substr($html,($tab[0][0][1]+strlen($tab[0][0][0])));
//htmlentities
echo htmlentities('Sortie 2 : '.$start.
'<span style="background-color:#ffff66">'.$middle.'</span>'.
$end).'<br />';
}
else {
echo ' -- Fonctionne pas -- <br /><br />';
}
echo '====================== FIN ====================== <br /><br />';
} |
Partager