Forum Moderators: coopster

Message Too Old, No Replies

Fopen doesn't open url inside array

         

JoaoJose

8:17 pm on Oct 7, 2006 (gmt 0)

10+ Year Member



Maybe this is a trivial question but I can't find the answer anywhere.

I want to open a series of urls that I get from a database.

So I inside the loop I do:

$handle = fopen($r->fields['url'], "r");
fclose($handle);

where $r->fields['url'] is a single url

And get:

Warning: fopen(http://www.domain.com ) [function.fopen]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found

But if I do:

$url='http://www.domain.com';
$handle = fopen($url, "r");
fclose($handle);

I have no problems opening my location.

Any ideias?

Thks!

JoaoJose

8:48 pm on Oct 7, 2006 (gmt 0)

10+ Year Member



Ok problem solved. It seems that $r->fields['url'] doesn't work because of the '' if I name the url with a number like $r->fields[1] fopen already works.

Thks anyway.

JoaoJose

4:18 pm on Oct 8, 2006 (gmt 0)

10+ Year Member



Well ignore my last post I was almost asleep.

I finally found what the problem was, before using fopen() or copy() you must trim all white space or else the url won't open.

So if using fopen() we would have:

$handle = fopen(trim($r->fields['url']), "r");

and it works like a charm.

eelixduppy

4:23 pm on Oct 8, 2006 (gmt 0)



>>Well ignore my last post I was almost asleep.

LOL...This happens to me all the time. Glad you got it, and thanks for sharing the solution ;)