Jump to content

Get contents and write in the same PHP file...


Badchip

Recommended Posts

I want to get the url from another site and put it in my php. Something like this:

$url = file_get_contents('http://...');
$url = get_string_between($url, 'http://...', '"');

$fopen($url, 'w');
fwrite($url);
fclose()

header("Location: http://result.here");

If it is not possible, what other alternative do I have?

Link to comment
Share on other sites

OK, then in a vague sense the code you wrote would basically be how to do that, assuming that get_string_between function works.  There's not a built-in function with that name.  There's no reason to use fopen, fwrite, and fclose though.

Link to comment
Share on other sites

I think it's almost done. Now I need to skip the 'fopen' and 'fwrite' lines if there are no results between '"file": "http://', '"'); 

$url = file_get_contents('http://web.com');
$url = get_string_between($url, '"file": "http://', '"');

$file = fopen("web_url.txt", "w");
fwrite($file, $url);

$file = file_get_contents('web_url.txt');

header("Location: http://$file");

Any idea?

 

Link to comment
Share on other sites

You can use file_put_contents instead of those other functions, first off.  I don't know what you're asking though.  If your content wasn't found, wouldn't you just use an if statement to check that and write to the file if your condition is satisfied?

Link to comment
Share on other sites

I have solved it. Thank you.

$url = file_get_contents('http://web.com');
$url = get_string_between($url, '"file": "http://', '"');
if (empty($url)) $url = file_get_contents('web_url.txt');
else file_put_contents('web_url.txt', $url);
header("Location: http://$url");

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...