Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

update of the content in an HTML file

Last post 12-01-2008, 3:18 AM by mouna. 0 replies.
Sort Posts: Previous Next
  •  12-01-2008, 3:18 AM 49007

    update of the content in an HTML file

    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.Smile

    and i thank you a lot for your help.Smile

     

     

     

     

     

    $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.Smile

    and i thank you a lot for your help.Smile

     

     

     

     

     

     

View as RSS news feed in XML