View Single Post
Old 05-14-2007, 11:38 AM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,476
sde is on a distinguished road
summary: this code reads in the text of the web page exampleurl. com and replaces all spaces with %20.


//Specify your URL
$URL = "http://www.exampleurl.com";

$ before a string indicates a variable in PHP. this line of code just assigns example.url.com to the variable: $URL


//Open a stream in READ mode
$handle = fopen ($URL, "r");

The comment says it all.


//It's this one I don't get
$key = str_replace(' ', '%20',fread($handle, 1000000));

you're calling 2 functions here. fread() reads the resource you send in and returns a string up to 1000000 bytes.

str_replace() just replaces the first argument with the second argument in the string defined in the third argument.

to make it easier to understand, look at it like this:
PHP Code:
$buffer fread($handle1000000);

$key str_replace(' ''%20'$buffer); 
also, remember PHP: Hypertext Preprocessor is your friend. use their function search when you need more information as to what functions like str_replace() and fread() do. it's an awesome resource.
__________________
Mike
sde is offline   Reply With Quote