Badchip Posted April 5, 2018 Share Posted April 5, 2018 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 More sharing options...
justsomeguy Posted April 5, 2018 Share Posted April 5, 2018 You haven't explained your problem well. Link to comment Share on other sites More sharing options...
Badchip Posted April 5, 2018 Author Share Posted April 5, 2018 I want to obtain a URL of a website (it's inside the HTML) and add the URL in the same PHP. Link to comment Share on other sites More sharing options...
justsomeguy Posted April 5, 2018 Share Posted April 5, 2018 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 More sharing options...
Badchip Posted April 6, 2018 Author Share Posted April 6, 2018 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 More sharing options...
justsomeguy Posted April 6, 2018 Share Posted April 6, 2018 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 More sharing options...
Badchip Posted April 6, 2018 Author Share Posted April 6, 2018 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now