file-get-contents

file_get_contents not working?

笑着哭i 提交于 2019-11-26 08:26:20
问题 This code is not working to server. But It is working to my localhost (xampp) $url = file_get_contents(\'http://www.site.com/\'); $xhtml=\'|<tr style=\"background-color:#dddddd;\"> <td class=\"odd\" align=\"left\">(.+?)</td><td class=\"odd\">(.+?)</td> </tr>|i\'; preg_match_all($xhtml,$url,$score); array_shift($score); echo\"<pre>\"; print_r($score); echo\"</pre>\"; It prints another scores when I change the code like this. Because there are two rows like this. It has same codes. by the way

Show image using file_get_contents

风格不统一 提交于 2019-11-26 05:32:35
问题 how can I display an image retrieved using file_get_contents in php? Do i need to modify the headers and just echo it or something? Thanks! 回答1: Do i need to modify the headers and just echo it or something? exactly. Send a header("content-type: image/your_image_type"); and the data afterwards. 回答2: You can use readfile and output the image headers which you can get from getimagesize like this: $remoteImage = "http://www.example.com/gifs/logo.gif"; $imginfo = getimagesize($remoteImage);

Upload a file using file_get_contents

隐身守侯 提交于 2019-11-26 05:19:36
问题 I realise I can do this with CURL very easily, but I was wondering if it was possible to use file_get_contents() with the http stream context to upload a file to a remote web server, and if so, how? 回答1: First of all, the first rule of multipart Content-Type is to define a boundary that will be used as a delimiter between each part (because as the name says, it can have multiple parts). The boundary can be any string that is not contained in the content body . I will usually use a timestamp:

file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known

一曲冷凌霜 提交于 2019-11-26 03:44:37
问题 I\'m trying to download an image from a server using a PHP script on my website on xampp server. The image is being downloaded using the function file_get_contents. The php code for downloading on the server is: if(isset($_GET[\'path\']) && isset($_GET[\'username\'])) { echo \"path:\".$_GET[\'path\']; $temp = explode(\".\", $_GET[\'path\']); $extension = end($temp); $fname=\"images/\".$_GET[\'title\']; $filenameIn = $_GET[\'path\']; $filenameOut = \"\" . $fname; $contentOrFalseOnFailure =

file_get_contents(): SSL operation failed with code 1, Failed to enable crypto

做~自己de王妃 提交于 2019-11-26 03:13:51
问题 I’ve been trying to access this particular REST service from a PHP page I’ve created on our server. I narrowed the problem down to these two lines. So my PHP page looks like this: <?php $response = file_get_contents(\"https://maps.co.weber.ut.us/arcgis/rest/services/SDE_composite_locator/GeocodeServer/findAddressCandidates?Street=&SingleLine=3042+N+1050+W&outFields=*&outSR=102100&searchExtent=&f=json\"); echo $response; ?> The page dies on line 2 with the following errors: Warning: file_get

PHP cURL vs file_get_contents

北战南征 提交于 2019-11-26 03:08:52
问题 How do these two pieces of code differ when accessing a REST API? $result = file_get_contents(\'http://api.bitly.com/v3/shorten?login=user&apiKey=key&longUrl=url\'); and $ch = curl_init(\'http://api.bitly.com/v3/shorten?login=user&apiKey=key&longUrl=url\'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($ch); They both produce the same result, judging by print_r(json_decode($result)) 回答1: file_get_contents() is a simple screwdriver. Great for simple GET requests where the

Does file_get_contents() have a timeout setting?

梦想的初衷 提交于 2019-11-26 02:21:01
问题 I am calling a series of links using the file_get_contents() method in a loop. Each link may take more than 15 minutes to process. Now, I worry about whether PHP\'s file_get_contents() has a timeout period? If yes, it will time out with a call and move to next link. I don\'t want to call the next link without the prior one finishing. So, please tell me whether file_get_contents() has a timeout period. The file which contains the file_get_contents() is set to set_time_limit() to zero

How to get the content-type of a file in PHP?

試著忘記壹切 提交于 2019-11-26 02:11:56
问题 I\'m using PHP to send an email with an attachment. The attachment could be any of several different file types (pdf, txt, doc, swf, etc). First, the script gets the file using \"file_get_contents\". Later, the script echoes in the header: Content-Type: <?php echo $the_content_type; ?>; name=\"<?php echo $the_file_name; ?>\" How to I set the correct value for $the_content_type ? 回答1: I am using this function, which includes several fallbacks to compensate for older versions of PHP or simply

Get content between two strings PHP

☆樱花仙子☆ 提交于 2019-11-26 01:53:57
问题 Whats is the best way to obtain the content between two strings e.g. ob_start(); include(\'externalfile.html\'); ## see below $out = ob_get_contents(); ob_end_clean(); preg_match(\'/{FINDME}(.|\\n*)+{\\/FINDME}/\',$out,$matches); $match = $matches[0]; echo $match; ## I have used .|\\n* as it needs to check for new lines. Is this correct? ## externalfile.html {FINDME} Text Here {/FINDME} For some reason this appears to work on one place in my code and not another. Am I going about this in the

file_get_contents() Breaks Up UTF-8 Characters

岁酱吖の 提交于 2019-11-26 00:55:10
问题 I am loading a HTML from an external server. The HTML markup has UTF-8 encoding and contains characters such as ľ,š,č,ť,ž etc. When I load the HTML with file_get_contents() like this: $html = file_get_contents(\'http://example.com/foreign.html\'); It messes up the UTF-8 characters and loads Å, ¾, ¤ and similar nonsense instead of proper UTF-8 characters. How can I solve this? UPDATE: I tried both saving the HTML to a file and outputting it with UTF-8 encoding. Both doesn\'t work so it means