file-get-contents

file_get_contents with spaces in URL

那年仲夏 提交于 2019-12-01 17:16:05
I have an issue where even if I replace the spaces to %20 and get this content the ultimate url the browser gets turns the "%20" into "%2520" Here's my code, any suggestions to get this to work? it seems easy but I'm stuck :/ <?php //$_GET['song'] will contain a song name with spaces $song = str_replace(array("%20", "&", "?" , "/"), array(" ", "", "", ""), $_GET['song']); // I use this to check how the GET 'song' looks after the str_replace $list = "http://www.lyrdb.com/lookup.php?q=" . $song . "&for=fullt"; echo "list url is " . $list . "<hr>"; $content = file_get_contents("http://www.lyrdb

Do we need to close file_get_contents?

旧巷老猫 提交于 2019-12-01 15:39:11
问题 I'm running file_get_contents() inside a loop, I see a lot of files opened in the Apache log. I don't know the reason behind it. Do we need to close the file_get_contents() function after each read? 回答1: file_get_contents() reads a file and closes the file afterwards. It returns the read data or false , so you have no file handle to use with an fclose() , anyway. 来源: https://stackoverflow.com/questions/19650817/do-we-need-to-close-file-get-contents

Download a file via CURL with Cookies using php [closed]

十年热恋 提交于 2019-12-01 14:37:26
I need to POST cookies.txt then download a page to a text file using CURL. This is my FGC example but apparently FGC is bad at cookies so I need CURL. <?php $file = file('source\1.txt'); foreach ($file as $link) { $link = trim($link); $link2 = "http://site-that.com/authenticates?={$link}"; $downloaded = file_get_contents($link2); $myFile = "parsed/$link" . ".txt"; $fh = fopen($myFile, 'a') or die('Cannot open file'); fwrite($fh, $downloaded); } $timestamp = time(); rename('source\1.txt', "source/done/done-{$timestamp}.txt"); echo 'Finished'; Any ideas? Code examples would be extremely

Download a file via CURL with Cookies using php [closed]

99封情书 提交于 2019-12-01 13:24:52
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . I need to POST cookies.txt then download a page to a text file using CURL. This is my FGC example but apparently FGC is bad at cookies so I need CURL. <?php $file = file('source\1.txt'); foreach ($file as $link)

How to use PHP to get a webpage into a variable

天涯浪子 提交于 2019-12-01 12:29:28
I want to download a page from the web, it's allowed to do when you are using a simple browser like Firefox, but when I use "file_get_contents" the server refuses and replies that it understands the command but don't allow such downloads. So what to do? I think I saw in some scripts (on Perl) a way to make your script like a real browser by creating a user agent and cookies, which makes the servers think that your script is a real web browser. Does anyone have an idea about this, how it can be done? Use CURL. <?php // create curl resource $ch = curl_init(); // set url curl_setopt($ch, CURLOPT

file_get_contents, HTTP request failed

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-01 09:22:21
问题 I try to get content from another site by using file_get_contents but I always get "failed to open stream: HTTP request failed!" allow_url_fopen is on, and I have tested with my firewall off. But it still happens, what other reasons can it be? EDIT: Here is the full message Warning: file_get_contents(http://yemto.deviantart.com/): failed to open stream: HTTP request failed! in D:\xampp\htdocs\deviantart\webcam\img.php on line 15 And code //Load the page into a DOMDocument $file = file_get

php: file_get_contents() work with CLI, but does not work when called on server (in page)

元气小坏坏 提交于 2019-12-01 07:31:26
I am slightly baffled. I am using the bit.ly PHP API to shorten some urls. This works fine on local host - but when I tried it on my server (php running in Apache), file_get_contents() returns an empty string. I checked my apache logs and cannot see any warning/errors by Apache, so I tried the same command at the CL (using PHP CLI): >php -a php > $long_url = some_url_encoded_string; php > echo file_get_contents($long_url); {"errorCode": 0, "errorMessage": "", "results": {"http://www.example.html": {"userHash": "abc", "shortKeywordUrl": "", "hash": "xyz", "shortCNAMEUrl": "http://bit.ly/foobar"

php file_get_contents returns null when allow_url_fopen is on

我的未来我决定 提交于 2019-12-01 05:25:30
I get the warning message: file_get_contents failed to open stream permission denied I have set all_url_open to on in the php.ini file. My php file is in my apache server and it is trying to access a url (that returns JSON) from a tomcat server on the same machine. The code in the php file looks like: $srcURL = 'http://samemachine:8080/returnjson/'; $results = file_get_contents($srcURL); I have also tried curl and it returns nothing and doesn't hit the tomcat server either: function curl($url){ $ch = curl_init(); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept-Language: en-us')); curl

How to call a website service from PHP?

折月煮酒 提交于 2019-11-30 21:13:36
问题 My problem is the following, I have an EmailReports.php on my server which I use to send mails like EmailReports.php?who=some@gmail.com&what=123456.pdf I can NOT modify EmailReports.php since that belongs to a diferent project and it instantly sends an email and has been aproved by QA team and all that stuff. Now, on a diferent LookReports.php I need to offer a service like "Send me the reports I reviewed" which manually can be easily executed as just calling EmailReports.php, the question is

Search String and Return Line PHP

走远了吗. 提交于 2019-11-30 21:12:40
I'm trying to search a PHP file for a string and when that string is found I want to return the whole LINE that the string is on. Here is my example code. I'm thinking I would have to use explode but cannot figure that out. $searchterm = $_GET['q']; $homepage = file_get_contents('forms.php'); if(strpos($homepage, "$searchterm") !== false) { echo "FOUND"; //OUTPUT THE LINE }else{ echo "NOTFOUND"; } Just read the whole file as array of lines using file function. function getLineWithString($fileName, $str) { $lines = file($fileName); foreach ($lines as $lineNumber => $line) { if (strpos($line,