fopen and fread trouble

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gotornot
Forum Commoner
Posts: 54
Joined: Fri Jul 31, 2009 2:30 am

fopen and fread trouble

Post by gotornot »

Hi

i am trying to read a page that i open but i keep getting errors and dont know why any ideas.

The code im using is:

Code: Select all

	foreach($url_extq_data as $a)
		{
		$var .=$a;
		}
	// now replace all the tags in the substring and out put the data
	$from = array("{our_track}", "{name}", "{surname}", "{email}", "{title}", "{gender}", "{dobday}", "{dobmonth}", "{dobyear}", "{address}", "{address2}", "{town}", "{county}", "{postcode}", "{tel}", "{mobile}", "{timestampu}", "{timestampr}", "{username}", "{password}", "{company}", "{siteurl}", "{fax}", "{tracking}");
	$to = array("$our_id", "$name", "$surname", "$email", "$title", "$gender", "$dobday", "$dobmonth", "$dobyear", "$address", "$address2", "$town", "$county", "$postcode", "$tel", "$mobile", "$timestampu", "$timestampr", "$username", "$password", "$company", "$siteurl", "$fax", "$trackit");
	$final_url = str_replace($from, $to, $var);
	// open url and wait for response
	$handle = fopen('$final_url', "r");
	echo $final_url;
	##$contents2 = stream_get_contents($handle);
	$contents2 = '';
	$contents2 .= fread($handle, 100);
	$contents2 = trim($contents2);
This is what i get back:

<br /> <b>Warning</b>: fopen($final_url) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: No such file or directory in <b>/home/s/e/searlco/web/public_html/ms_creg.php</b> on line <b>232</b><br /> http://www.cleanleads.co.uk/lead.aspx?c ... ssLine1=31 Cottage Street&Postcode=SS131HR&Gender=M&DateOfBirth=13/10/1980&emailaddress=dait@tedfsdfsdit.com&title=Mr&SupplierSourceCode=11866<br /> <b>Warning</b>: fread(): supplied argument is not a valid stream resource in <b>/home/s/e/searlco/web/public_html/ms_creg.php</b> on line <b>236</b><br /> ER

Any help anyone???? im lost
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: fopen and fread trouble

Post by social_experiment »

resource fopen ( string $filename , string $mode [, bool $use_include_path= false [, resource $context ]] )
fopen() reads from a file or url, not from arrays. The warning you are receiving is because it can't find a file to read from. Same with fread(). Here is an fread() example

Code: Select all

<?php
// get contents of a file into a string
$filename = "/usr/local/something.txt";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);
?> 
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply