str_replace() external file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • The Numerator

    str_replace() external file

    I have this page (print.php). In that file, I want to to include a text
    file from "songs/breathe.txt", and replace all instances of "<b" with
    "<span" and "</b>" with "</span>". I know how I should use str_replace
    and I tried to do this:

    <?php

    $replace_a=str_ replace("<span" ,"<b",include(" text/breathe.txt"));
    $replace_b=str_ replace("</span>",</b>",$replace_a) ;

    ?>

    but it doesn't work.

  • PTM

    #2
    Re: str_replace() external file

    "The Numerator" <alvin4jesus@gm ail.comwrote in message
    news:1153951139 .069847.269920@ m73g2000cwd.goo glegroups.com.. .
    >I have this page (print.php). In that file, I want to to include a text
    file from "songs/breathe.txt", and replace all instances of "<b" with
    "<span" and "</b>" with "</span>". I know how I should use str_replace
    and I tried to do this:
    >
    <?php
    >
    $replace_a=str_ replace("<span" ,"<b",include(" text/breathe.txt"));
    $replace_b=str_ replace("</span>",</b>",$replace_a) ;
    >
    ?>
    >
    but it doesn't work.
    >
    I've never tried that before, but I'm sure it's never going to do it.

    What you should do is open the file and read it in

    $file='[PATH TO FILE]';
    $filethis=fopen ($file,'rb') or die("Can't open TXT file '[FILENAME]'");

    Then read each line of the file, doing your replace as you go.


    Phil


    Comment

    • Miguel Cruz

      #3
      Re: str_replace() external file

      "The Numerator" <alvin4jesus@gm ail.comwrote:
      I have this page (print.php). In that file, I want to to include a text
      file from "songs/breathe.txt", and replace all instances of "<b" with
      "<span" and "</b>" with "</span>". I know how I should use str_replace
      and I tried to do this:
      >
      <?php
      >
      $replace_a=str_ replace("<span" ,"<b",include(" text/breathe.txt"));
      $replace_b=str_ replace("</span>",</b>",$replace_a) ;
      >
      ?>
      >
      but it doesn't work.
      $replace_a
      = str_replace('<s pan', '<b', file_get_conten ts('text/breathe.txt'));

      miguel
      --
      Photos from 40 countries on 5 continents: http://travel.u.nu
      Latest photos: Malaysia; Thailand; Singapore; Spain; Morocco
      Airports of the world: http://airport.u.nu

      Comment

      • The Numerator

        #4
        Re: str_replace() external file


        Miguel Cruz wrote:
        "The Numerator" <alvin4jesus@gm ail.comwrote:
        I have this page (print.php). In that file, I want to to include a text
        file from "songs/breathe.txt", and replace all instances of "<b" with
        "<span" and "</b>" with "</span>". I know how I should use str_replace
        and I tried to do this:

        <?php

        $replace_a=str_ replace("<span" ,"<b",include(" text/breathe.txt"));
        $replace_b=str_ replace("</span>",</b>",$replace_a) ;

        ?>

        but it doesn't work.
        >
        $replace_a
        = str_replace('<s pan', '<b', file_get_conten ts('text/breathe.txt'));
        >
        miguel
        --
        Photos from 40 countries on 5 continents: http://travel.u.nu
        Latest photos: Malaysia; Thailand; Singapore; Spain; Morocco
        Airports of the world: http://airport.u.nu

        sorry, this didn't work

        Comment

        • The Numerator

          #5
          Re: str_replace() external file


          The Numerator wrote:
          Miguel Cruz wrote:
          "The Numerator" <alvin4jesus@gm ail.comwrote:
          I have this page (print.php). In that file, I want to to include a text
          file from "songs/breathe.txt", and replace all instances of "<b" with
          "<span" and "</b>" with "</span>". I know how I should use str_replace
          and I tried to do this:
          >
          <?php
          >
          $replace_a=str_ replace("<span" ,"<b",include(" text/breathe.txt"));
          $replace_b=str_ replace("</span>",</b>",$replace_a) ;
          >
          ?>
          >
          but it doesn't work.
          $replace_a
          = str_replace('<s pan', '<b', file_get_conten ts('text/breathe.txt'));

          miguel
          --
          Photos from 40 countries on 5 continents: http://travel.u.nu
          Latest photos: Malaysia; Thailand; Singapore; Spain; Morocco
          Airports of the world: http://airport.u.nu
          >
          >
          sorry, this didn't work
          actually, i was wrong...i got it to work...

          <?php
          $content=file_g et_contents($tx t);
          $replace=str_re place("<b","<sp an",$content) ;
          echo(str_replac e("</b>","</span>",$replace ));
          ?>

          thx

          Comment

          Working...