include part of a text file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • brianwalker@i-rent.us

    include part of a text file

    hello all.

    I have a text document that stores text for use in a flash movie. I'm
    also using PHP to displace the same text on another page. However the
    text document includes 2 tags for use by the flash movie... title= and
    &content= ... see text file at end of post ....

    when i use the php command <?php include ("info.txt") ; ?> it also
    displays those tags. Is there any way to use php to just display what
    apprars after the &content= in my text file.

    I can't remove the tag begause it is required for the flash file
    elsewhere on the site.

    "
    title=CDN HOME &content=The COMPUTER DONATION NETWORK is a resource of
    new, used and refurbished computer equipment, software, networking gear
    and lab furnishings for "

    grassy ass,
    (Thank You)

  • gardnern

    #2
    Re: include part of a text file

    Assuming "&content=" isnt anywhere else in the txt file, you could use
    PHPs explode function like so...

    <?php
    $textfile= "/usr/local/something.txt";
    $handle = fopen($textfile , "r");
    $contents = fread($handle, filesize($textf ile));
    fclose($handle) ;

    $content = explode("&conte nt=", $contents);
    print($content[1]);
    ?>

    fopen function..


    fread function...


    explode function...


    -Nathan

    Comment

    • NC

      #3
      Re: include part of a text file

      brianwalker@i-rent.us wrote:[color=blue]
      >
      > when i use the php command <?php include ("info.txt") ; ?>[/color]

      There's no need to use include() for anything other than PHP files. If
      you just want to output the contents of the file, use readfile()
      instead.
      [color=blue]
      > Is there any way to use php to just display what
      > apprars after the &content= in my text file.[/color]
      ....[color=blue]
      > "
      > title=CDN HOME &content=The COMPUTER DONATION NETWORK
      > is a resource of new, used and refurbished computer equipment, software,
      > networking gear and lab furnishings for "[/color]

      Yes:

      list(, $content) = explode('&conte nt=', file_get_conten ts('info.txt')) ;

      echo $content;

      Cheers,
      NC

      Comment

      • brianwalker@i-rent.us

        #4
        Re: include part of a text file

        Thank you so much. This worked like a charm

        Comment

        Working...