11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

www.it-ebooks.infoCHAPTER 10 • WORKING WITH THE FILE AND OPERATING SYSTEMThe variable $userdata now contains the contents of the users.txt file.Reading in an Entire FileThe readfile() function reads an entire file specified by filename and immediately outputs it to theoutput buffer, returning the number of bytes read. Its prototype follows:int readfile(string filename [, int use_include_path])Enabling the optional use_include_path parameter tells <strong>PHP</strong> to search the paths specified by theinclude_path configuration parameter. This function is useful if you’re interested in simply dumping anentire file to the browser:$file = '/home/www/articles/gilmore.html';// Output the article to the browser.$bytes = readfile($file);Like many of <strong>PHP</strong>’s other file I/O functions, remote files can be opened via their URL if theconfiguration parameter fopen_wrappers is enabled.Reading a File According to a Predefined FormatThe fscanf() function offers a convenient means for parsing a resource in accordance with a predefinedformat. Its prototype follows:mixed fscanf(resource handle, string format [, string var1])For example, suppose you want to parse the following file consisting of Social Security numbers(SSN) (socsecurity.txt):123-45-6789234-56-7890345-67-8901

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!