PHP
  Home arrow PHP arrow Page 2 - File And Directory Manipulation In PHP (part 2)
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

File And Directory Manipulation In PHP (part 2)
By: icarus, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 65
    2003-08-21


    Table of Contents:
  • File And Directory Manipulation In PHP (part 2)
  • Stripping It To The Bone
  • Fertile Fields
  • Configuring The System
  • The Right Path
  • Move It
  • Beam Me Up
  • Diving Into Directories
  • A Pattern Emerges
  • Purging The Dead
  • Size Does Matter
  • In Process
  • Disk Full

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    File And Directory Manipulation In PHP (part 2) - Stripping It To The Bone
    ( Page 2 of 13 )

    You may remember, from the first part of this article, how I used the
    fgets() function to read the contents of a file and print it to the browser. In case you don't, here's a quick reminder:


    <?php

    // set file to read
    $filename = "mindspace.txt";

    // open file
    $fh = fopen ($filename, "r") or die("Could not open file");

    // read file
    while (!feof($fh))
    {
    $data = fgets($fh);
    echo $data;
    }

    // close file
    fclose ($fh);

    echo "-- ALL DONE --";

    ?>

    PHP also offers the fgetss() function, which works just like the regular
    fgets() function, except that it also strips out HTML and PHP code from the lines it reads. So, for example, if you had a file containing intermingled HTML code and ASCII text (as most HTML files are), like in the following example,


    <HTML>
    <HEAD>
    </HEAD>

    <BODY>

    <TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0">
    <TR>
    <TD>
    <FONT FACE="Verdana, Arial" SIZE="2" COLOR="#66CC00">
    <B><A HREF="article.php?id=169"><IMG SRC="/images/sm_arrow.jpg" WIDTH=20 HEIGHT=20 ALT="" BORDER=0 ALIGN="ABSMIDDLE" HSPACE=4>Learning To SMILe</A></B> </FONT> </TD> </TR> <TR> <TD> <FONT FACE="Verdana, Arial" SIZE="1" COLOR="Black">
    Use SMIL to quickly build new Web-based multimedia applications | 20 Dec 2002
    </FONT>
    </TD>
    </TR>
    <TR>
    <TD HEIGHT=25>
    &nbsp;
    </TD>
    </TR>
    <TR>
    <TD>
    <FONT FACE="Verdana, Arial" SIZE="2" COLOR="#66CC00">
    <B><A HREF="article.php?id=168"><IMG SRC="/images/sm_arrow.jpg" WIDTH=20 HEIGHT=20 ALT="" BORDER=0 ALIGN="ABSMIDDLE" HSPACE=4>Writing A User Manual (part 1)</A></B> </FONT> </TD> </TR> <TR> <TD> <FONT FACE="Verdana, Arial" SIZE="1" COLOR="Black"> It ain't easy writing a user manual...but our cheat sheet should help | 20
    Dec 2002
    </FONT>
    </TD>
    </TR>
    </TABLE>

    </BODY>
    </HTML>

    you could retrieve just the ASCII from it with the following example script:


    <?php

    // set file to read
    $filename = "data.html";

    // open file
    $fh = fopen ($filename, "r") or die("Could not open file");

    // read file
    while (!feof($fh))
    {
    // strip out tags
    $data = fgetss($fh, 999);

    // if nothing present after stripping tags, move on
    // else print the cleaned line
    if (trim($data) != "")
    {
    echo trim($data) . "\r\n";
    }
    }

    // close file
    fclose ($fh);

    echo "-- ALL DONE --";

    ?>

    Here's what the output looks like:


    Learning To SMILe
    Use SMIL to quickly build new Web-based multimedia applications | 20 Dec 2002 &nbsp; Writing A User Manual (part 1) It ain't easy writing a user manual...but our cheat sheet should help | 20 Dec 2002



     
     
    >>> More PHP Articles          >>> More By icarus, (c) Melonfire
     

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    Stay green...Green IT