WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Mobile Dev World
Reads remainder of a stream into a string

stream_get_contents

(PHP 5)

stream_get_contentsReads remainder of a stream into a string

Description

string stream_get_contents ( resource $handle [, int $maxlength= -1 [, int $offset= 0 ]] )

Identical to file_get_contents(), except that stream_get_contents() operates on an already open stream resource and returns the remaining contents in a string, up to maxlength bytes and starting at the specified offset .

Parameters

handle (resource)

A stream resource (e.g. returned from fopen())

maxlength (integer)

The maximum bytes to read. Defaults to -1 (read all the remaining buffer).

offset (integer)

Seek to the specified offset before reading.

Return Values

Returns a string, or FALSE on failure.

Changelog

Version Description
5.1.0 The offset was added.

Examples

Example #1 stream_get_contents() example

<?php

if ($stream fopen('http://www.example.com''r')) {
    
// print all the page starting at the offset 10
    
echo stream_get_contents($stream, -110);

    
fclose($stream);
}


if (
$stream fopen('http://www.example.net''r')) {
    
// print the first 5 bytes
    
echo stream_get_contents($stream5);

    
fclose($stream);
}

?>

Notes

Note: This function is binary-safe.

See Also

  • fgets() - Gets line from file pointer
  • fread() - Binary-safe file read
  • fpassthru() - Output all remaining data on a file pointer


Mimic ASPs GetRows function with PHP
Categories : PHP, Databases, MySQL
Getting the size of a file in megs
Categories : PHP, Filesystem
How to dump a table's contents and build a new table from it.
Categories : MySQL, Databases



Get a folder size ( recursive )
Categories : PHP, Filesystem, Directories
make: Fatal error: Command failed for target `target_static`
Categories : PHP, Installation
Working with files - get a random file from a directory
Categories : PHP, Strings, Variables, Filesystem
Format US phone number version 2. Rewritten to have an invalid statement output, and to include a extension number, up to four digets.
Categories : PHP, Regexps
Builds JavaScript that updates the contents of one selector based on another.
Categories : HTML, Java Script, PHP, Complete Programs, General
This is a question that's asked regularly in the web community... "How can I get the screen resolution of a user's browser?" - Simple. Examine this code. All of the work's done with the screen.width and screen.height.
Categories : Java Script
Change the background color of a website daily dynamically using the php date function to get the current day of the week and depending on that day, set the background color for the web page.
Categories : PHP, Date Time, Beginner Guides, Web Design
Get ALL links from one or more URLs or local files. Corrects relative links.
Categories : PHP, Strings, Filesystem
time date modified changed last getlastmod last footer
Categories : Misc, Date Time
directory, opendir, listfiles, files in a directory, get directory
Categories : PHP, Filesystem
Open and return the contents of a text file.
Categories : PHP, Filesystem