We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26074
    • 121 Posts
    In this script the function trim don’t cut the space

    <?php
    $rr = 'http://biodizionario.it/images/semafori/rr.gif';
    $r =  'http://biodizionario.it/images/semafori/r.gif';
    $g =  'http://biodizionario.it/images/semafori/g.gif';
    $v  = 'http://biodizionario.it/images/semafori/v.gif';
    $vv = 'http://biodizionario.it/images/semafori/vv.gif';
    
    $filer = fopen("bio_format.txt", "w");
    $file = fopen("bio.txt", "r");
    
    while (!feof($file)) {
        $buffer = fgets($file, 4096);
        
        $pos = stripos($buffer,$rr);
        if ($pos) $s = "RR; ";
        $pos = stripos($buffer,$r);
        if ($pos) $s = "R; ";
        $pos = stripos($buffer,$g);
        if ($pos) $s = "G; ";
        $pos = stripos($buffer,$v);
        if ($pos) $s = "V; ";
        $pos = stripos($buffer,$vv);
        if ($pos) $s = "VV; ";
        
        $pos1 = stripos($buffer,'<b>');
        $pos2 = stripos($buffer,'</b>');
        $diff = $pos2 - $pos1;
        $start = $pos1 + 3;
        $rest = $diff - 3;
        $nome = substr($buffer, $start, $rest);
        $s = $s . $nome . ";" ;
        
        $pos1 = stripos($buffer,'</b>');
        $pos2 = stripos($buffer,'<br />');
        $diff = $pos2 - $pos1;
        $start = $pos1 + 4;
        $rest = $diff - 4;
        $descr = substr($buffer, $start, $rest);
        $descr1 = trim($descr);
        $s = $s . $descr1 . ";" . "\r\n";
        
        fwrite($filer, $s);
    }
    fclose($file);
    fclose($filer);
    ?>
    


    I have a result file like this:

    RR; 1-NAPHTHOL;      colorante capelli;
    RR; 1,2,4-BENZENETRIACETATE;      colorante capelli;
    RR; 1,3-BIS-(2,4-DIAMINOPHENOXY)PROPANE;      colorante capelli;
    RR; 1,5-NAPHTHALENEDIOL;      colorante capelli;
    

    etc...

    I don’t want the space beetwen semicolon and colorante capelli.

    In attachment the script if someone will try to help me.
      ___________________________________________________________________
      ..:: Samuele ::..
      • 26074
      • 121 Posts
      I solved using a regular expression.
      Thanks all the same.
        ___________________________________________________________________
        ..:: Samuele ::..