file-get-contents

cURL Html output different from original page when rendered

十年热恋 提交于 2019-12-23 15:28:26
问题 I am working on a project that involves fetching pages with cURL or file_get_contents. The problem is that when i try to echo the html fetched, the output seem to be different from the original page, not all images show up. Please i would like to know if there is a solution. My code <?php //Get the url $url = "http://www.google.com"; //Get the html of url function get_data($url) { $ch = curl_init(); $timeout = 5; //$userAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US)AppleWebKit/525

file_get_contents Adding numbers from 2 text files

只愿长相守 提交于 2019-12-23 07:04:50
问题 I'm currently using a cronjob to cache a number into text from an API, I have two text files with numbers in them and I want to add both together like 16+4 and it prints at 20 I have no Idea how I would do this and would be really glad if someone could provide an example if It can be done. 回答1: Like this : <?php $file1 = '/path/to/file/file1.txt'; $file2 = '/path/to/file/file2.txt'; if(is_file($file1) && is_file($file2)) { $value1 = trim(file_get_contents($file1)); $value2 = trim(file_get

Error in PHP on https wrapper

戏子无情 提交于 2019-12-23 05:50:46
问题 I am getting the following error and I am hosting the a local server using WAMP and using version 5.6.19 of PHP Warning: file_get_contents(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? 回答1: I think what you can try is to: Install php5-openssl Restart Apache afterwards. It will likely to solve that problem. And there's also another possible solution: You can find the "php.ini" file, and open it, you will find the line: extension=php_openssl.dll

Error Installing Composer on Windows 7 64-bit with Wampserver 2.5

荒凉一梦 提交于 2019-12-23 04:17:13
问题 I'm trying to install the Composer on W7 64x. Using the installer for Windows that the site Composer provides (Composer-setup.exe). I have installed the Wampserver 2.5 with php5.5.12 and Apache2.4.9. The openssl is enabled in php.ini. I'm having the following errors in the installation: Download failed: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed file_get_contents(): Failed to

How to download a file over HTTP and store its content in a String in Java

人盡茶涼 提交于 2019-12-23 02:45:08
问题 I'm trying to download a file over HTTP and store its contents in a String, as the title says. My approach is thus: URL u = new URL("http://url/file.txt"); ByteArrayBuffer baf = new ByteArrayBuffer(32); InputStream in = (InputStream) u.getContent(); BufferedInputStream bis = new BufferedInputStream(in); int buffer; while((buffer = bis.read()) != -1){ baf.append((byte)buffer); } bis.close(); in.close(); The code fails when it tries to read from the stream, reporting the stream is closed. Now

file_get_contents show characters of utf-8 like question marks

喜夏-厌秋 提交于 2019-12-23 02:24:28
问题 $str = "https://www.google.com/search?q=sd"; echo file_get_contents($str); I'm try to load page from google with the function file_get_contents, but the output of chracters of utf-8 showing like question mark. I've tried all the possibilities introduced here: file_get_contents() converts UTF-8 to ISO-8859-1 But the problem is still not resolved. I would appreciate any help very. UPDATE: I see that the problem exists through Google, other sites content is displayed correctly. 回答1: [php] /

How to get content from specific tags when using file_get_contents

可紊 提交于 2019-12-23 01:39:28
问题 For example i have one .txt file, called cache.txt. It contains some information, and i need to get content from <span class="date">**THESE**</span> tags. Any ideas? Thanks. 回答1: You can use Simple HTML DOM Example: cache.txt <span class="abc">Lorem Ipsum</span> <span class="date">THESE</span> <span class="def">Dolor sit amet</span> file.php <?php include 'simple_html_dom.php'; $html = file_get_html('cache.txt'); echo $html->find('span[class=date]',0); //Output: THESE ?> 回答2: **Check this out

laravel file_get_contents of a route get no response

微笑、不失礼 提交于 2019-12-22 10:58:45
问题 I have a route: Route::group(array('prefix' => 'playlist'), function() { Route::get('raw/{id}', array('as'=>'rawPlaylist', 'uses'=>'PlaylistsController@raw')); }); When I open the URL: http://localhost:8000/playlist/raw/1 Everything is fine and the page will load and show me the view. In a controller I get the URL: $url = URL::route('rawPlaylist', 1); The problem: I want read the view and store the whole view into a variable: $html = file_get_contents($url); echo $url is http://localhost:8000

simplexml_load_file not working

纵然是瞬间 提交于 2019-12-22 05:17:30
问题 I have this piece of code below which works fine on my remote hosted server, but isnt for some reason working on my local linux machine. Ive tried using file_get_contents as well to get the restful service but it also returns false. Does anyone know Why this is happening? thanks :) $xml_data = simplexml_load_file("****"); if ($xml == FALSE) { echo "Failed loading XML\n"; foreach (libxml_get_errors() as $error) { echo "\t", $error->message; } } 回答1: You are getting this error because remote

file_get_contents get Cookies

拟墨画扇 提交于 2019-12-22 01:33:12
问题 I'm trying to develop a full PHP web browser that can handle cookies. I've created the following class: <?php class Browser { private $cookies = ''; private $response_cookies = ''; private $content = ''; /** * Cookie manager * @Description : To set or get cookies as Array or String */ public function set_cookies_json($cookies) { $cookies_json = json_decode($cookies, true); $cookies_array = array(); foreach ($cookies_json as $key => $value) { $cookies_array[] = $key .'='.$value; } $this-