hello everybody,
my program displays all the tags <a> that do not contain the title attribute in the form of a table
like this:
<?php $motCle='title="bien"';
$chemin="telechargement/source.htm";
$ouvrir_fichier=fopen($chemin,'r+') or die('Fichier introuvable');
$contenu=tidy_get_root(tidy_parse_file($chemin));
if (preg_match_all("/<a([^>](?![^<>]*title=)[^<>]+)>(.*)<\/a>/siU",$contenu,$out, PREG_SET_ORDER))
{
foreach($out as $hkey=>$hval)
{
//then I must add these tags found the title attribute as follows:
$val=$hval[1];
$remp=$val." ".$motCle;
echo $hkey."____".'<span style='color:blue'>'.$hval[1].'</span>'.'<br/>'
$replace=preg_replace('/'.$val.'/',$remp,$contenu);
echo $replace."<br/>";
}
}
else
{
//
}
=> Finally, I must write these new tags with their title attribute in the html file:source.html:
fwrite($ouvrir_fichier,$replace)
fclose($ouvrir_fichier);
=>the problem is that the content is written in the html file every time we made a replacement ,i.e :depending on the number of tags found ,while I want the replacements is done by writing the content only once, i.e :without deformed the contents of the file html
and i thank you a lot for your help.
and i thank you a lot for your help.
$motCle='title="bien"';
$chemin="telechargement/source.htm";
$ouvrir_fichier=fopen($chemin,'r+') or die('Fichier introuvable');
$contenu=tidy_get_root(tidy_parse_file($chemin));
if (preg_match_all("/<a([^>](?![^<>]*title=)[^<>]+)>(.*)<\/a>/siU",$contenu,$out, PREG_SET_ORDER))
{
foreach($out as $hkey=>$hval)
{
//then I must add these tags found the title attribute as follows:
$val=$hval[1];
$remp=$val." ".$motCle;
echo $hkey."____".'<span style='color:blue'>'.$hval[1].'</span>'.'<br/>'
$replace=preg_replace('/'.$val.'/',$remp,$contenu);
echo $replace."<br/>";
}
}
else
{
//
}
=> Finally, I must write these new tags with their title attribute in the html file:source.html:
fwrite($ouvrir_fichier,$replace)
fclose($ouvrir_fichier);
=>the problem is that the content is written in the html file every time we made a replacement ,i.e :depending on the number of tags found ,while I want the replacements is done by writing the content only once, i.e :without deformed the contents of the file html
and i thank you a lot for your help.
and i thank you a lot for your help.