Home arrow PHP arrow Executing Shell Commands with PHP

Executing Shell Commands with PHP

In this sixth part of an eight-part series on working with the file and operating systems of a computer with PHP, you'll learn how to use PHP to write to a file and how to execute shell commands. This article is excerpted from chapter 10 of the book Beginning PHP and PostgreSQL 8: From Novice to Professional, written by W. Jason Gilmore and Robert H. Treat (Apress; ISBN: 1590595475).

  1. Executing Shell Commands with PHP
  2. Reading Directory Contents
  3. Executing Shell Commands
By: Apress Publishing
Rating: starstarstarstarstar / 0
December 07, 2011

print this article



Writing to a File

This section highlights several of the functions used to output data to a file.


int fwrite (resource handle, string string [, int length])

The fwrite() function outputs the contents of string to the resource pointed to by handle. If the optional length parameter is provided, fwrite() will stop writing when length characters have been written. Otherwise, writing will stop when the end of the string is found. Consider this example:

$subscriberInfo = "Jason Gilmore|wj@example.com";
$fh = fopen("/home/www/data/subscribers.txt", "at");
fwrite($fh, $subscriberInfo);

Tip If the optional length parameter is not supplied to fwrite(), the magic_quotes_runtime configuration parameter will be disregarded. See Chapters 2 and 9 for more information about this parameter.


int fputs (resource handle, string string [, int length])

The fputs() function operates identically to fwrite(). Presumably, it was incorporated into the language to satisfy the terminology preferences of C/C++ programmers.

>>> More PHP Articles          >>> More By Apress Publishing

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: