FAQ Database Discussion Community


preg_match_all undefined offset error

php,regex,file-get-contents,preg-match-all
Probably there is a regex error here, but I am unable to solve it. I am getting "Undefined offset: 0" error and can't get the value of the title. Here's my code. INEEDTHISONE is the title I want to fetch. for ($j = 1; $j <= 1; $j++) { for...

file_get_contents not working for some domains

php,fopen,file-get-contents
As a part of the requirement I need to find out whether a domain is parked or not. As there is no efficient way to find out this, I'm going to check the DOM for phrases like "Buy this domain", "may be for sale".. etc. I found some parked domains...

How to get content of div ( from external url) without loading the whole website

php,jquery,html,curl,file-get-contents
I'm trying to get the content of a div from an external url, but i don't want to load the whole website. Because i have to load a lot of data from many websites and it has to be very fast... Thank you in advance!...

PHP Warning: file_get_contents(http://ipecho.net/plain): failed to open stream: Connection timed out in

php,warnings,file-get-contents
I have an error here and I don't know where the problem is exactly. I am trying to make a PHP file and deny anyone to use the script except the IP that I have entered into the code: $pass = '192.168.x.x'; //here is the ip of the client if...

Cakephp: file_get_contents, curl and HttpSocket do not work

php,api,cakephp,curl,file-get-contents
I'm using Cakephp 2.6.1 and I would like to use an extern api. For this, I must request an url like that: $json = file_get_contents($url); $data = json_decode($json); I try with file_get_contents, curl and HttpSocket. And i have that error: php_network_getaddresses: getaddrinfo failed: Name or service not known I check...

file_get_contents against symfony2

php,symfony2,file-get-contents
I have a file_get_contents($myUrl) call from a flat PHP script that isn't working. If I run $myUrl in a browser it works fine, if I do it over the file_get_contents() it behaves as if the url is incorrect or incomplete. The myUrl looks like this https://login.myApp.com/getWifiSettings/ofBoSf593f Where the last part...

Extracting the value from webpage using simple html dom

php,html,web-scraping,file-get-contents
I have searched over net and found the way to extract data using simple html dom but it's giving me the following error: Warning: file_get_contents(http://www.flipkart.com/moto-g-2nd-gen/p/itme6g3wferghmv3): failed to open stream: HTTP request failed! HTTP/1.1 500 Server Error in C:\Users\Abhishek\Desktop\editor\request\simple_html_dom.php on line 75 Fatal error: Call to a member function find() on...

Proper way of using file_get_contents() PHP function

php,curl,error-handling,file-get-contents
I have some troubles with file_get_contents() function: if the remote file redirected to another URI I get script interruption and repetition of script output: Code: $context = stream_context_create(['http'=>['timeout'=>10]]); $url = 'http://example.com/'; echo "URL: $url\n"; $page = file_get_contents($url,FALSE,$context); echo "Page size: ".strlen($page); Output: URL: http://example.com/ URL: http://example.com/ (make note that the...

Link facebook share count with file_get_contents

php,facebook,count,share,file-get-contents
I'm tring do get the total number of sharing a link on facebook with the function "file_get_contents". This is my code: $url = x; $data = file_get_contents('http://graph.facebook.com/?id=".$url'); $obj = json_decode($data, true); $like_no = intval($obj->{'shares'}); echo $like_no; I tried this and it doesn't work. But file_get_contents is enabled on my server...

Timeout for file_get_contents don't works in PHP

php,file-get-contents,connection-timeout
I created a class to englobe some HTTP methods in PHP. Here, I have a method for HTTP POST public function post ($content, $timeout=null) { $timeInit = new DateTime(); $this->method = 'POST'; $header = array(); $header['header'] = null; $header['content'] = is_array($content) ? http_build_query($content) : $content; $header['method'] = $this->method; if ($timeout...

Grab price from URL

php,dom,file-get-contents,simple-html-dom
I'm trying to get a price from any given URL using simple-html-dom. The example code i used, which works well is from here: http://www.sanwebe.com/2013/06/extract-url-content-like-facebook-with-php-and-jquery //Include PHP HTML DOM parser (requires PHP 5 +) include_once("Includes/simple_html_dom.inc.php"); //get URL content $get_content = file_get_html($get_url); Getting the title works fine: //Get Page Title foreach($get_content->find('title') as...

Get content of page after redirects

php,parsing,curl,file-get-contents
I am trying parse from webpage but I cant load web in PHP because this page is reloading maybe three times. I tried everything with curl but it show me empty result. Thank you. https://cestovnelistky.studentagency.sk/Booking/from/PRAHA/to/BRATISLAVA/tarif/REGULAR/departure/20150511/retdep/20150511/return/false/ropen/false/credit/false/class/2?22#search-results ...

file_get_contents() working on localhost but not working on online server

file-get-contents
$result = file_get_contents(ADMIN_URL.'/content/'.$name.'.php'); if($result){ echo "YES";exit; }else{ echo "NO";exit; } Output is NO, where ADMIN_URL is "turkjammat.com/demo/administrator/" and $name is mardumshumari which makes url in file_get_contents() funciton "turkjammat.com/demo/administrator/content/mardumshumari.php" and the file is there in above url, this code is working fine in my local xamp server but when i deploying...

Strange result from file_get_contents

php,file-get-contents
<?php $content = file_get_contents('http://www.inc.com/patricia-fletcher/how-to-avoid-the-most-common-start-up-marketing-mistakes.html'); var_dump($content); ?> Why returns this? If I replace the URL with http://google.com everything seems to be fine....

Open txt file and insert it's content into table accordingly

php,file-get-contents
I want to read contents of a text file and insert the contents into a table This is the content of the text file -------------------------------- Text file contents -------------------------------- [playlist] mode=play Title1=Radio 1|United Kingdom File1=http://www.test.com/0001 Title2=Radio 2 |United States File2=http://www.test.com/0002 Title3=Radio 3|United Kingdom File3=http://www.test.com/0003 NumberOfEntries=3 Version=2 ------------------------------- And store in...

How to echo the source code of multiple files using file_get_contents PHP?

php,html,directory,echo,file-get-contents
<textarea placeholder="Source code of file" class="source"> <?php echo ($thesource) ?> </textarea> <?php $blacklist = array("one.jps", "two.txt", "four.html"); if ($handle = opendir('.')) { while (false !== ($entry = readdir($handle))) { if ($entry != "." && $entry != ".." && !in_array($entry, $blacklist)) { $thesource = file_get_contents($entry); echo "<div class='post' <p>$entry</p> </div> ";...

Use php to show custom pages to each individual

php,joomla,file-get-contents,joomla3.0
I am creating a website on Joomla and want to have a private page for each individual user. If anyone knows of the best way to do this apart from giving each individual their own group, this is the way I would like to try: I want to create a...

Avoid file_get_contents of a file giving me headers before the contents

php,http-headers,file-get-contents
I've created a file with file_put_contents() with a text "En un lugar de la mancha". I want to get that file from another php using file_get_contents and (for instance) print the output. The problem is that I'm getting also the headers: Content-type: text/html X-Powered-By: PHP/4.3.9 En un lugar de la...

How to read a text file and search for a certain string before a colon and then show the content after the colon?

php,regex,file,preg-match,file-get-contents
I have a file that contains something like this: test:fOwimWPu0eSaNR8 test2:vogAqsfXpKzCfGr I would like to be able to search the file for say test and it set the string after the : to a variable so it can be displayed, used etc. Here is the code I have so far...

PHP Get last five words from .txt-file using file_get_contents

javascript,php,string,output,file-get-contents
I'm looking for a functioning way of reading the last, say, 5 words from a .txt file using file_get_contents while long-polling. I've tried to work on a solution using the commented code below, but it breaks the long-polling – which works fine when displaying the full contents of a .txt-file....

Use File_Get_Contents to grab site, then remove header and display site?

php,file-get-contents
In the below code, I've tried using the file get contents command to get the website content and output it, and but its showing a blank page when I run it. <html> <?php $site = "http://facebook.com"; echo $file_get_contents[$site]; ?> <html> After this, I wanted to use header('X-Frame-Options: GOFORIT'); or something...

file_get_contents() expects parameter 1 to be a valid path

image,codeigniter,model-view-controller,controller,file-get-contents
My image is uploading to images/news successfully. I want to now save that image in the database. but it keeps giving me the above error. My model query is correct because i use it to insert other data and it works. How can i save the image into the database...

Json returns null value

php,json,curl,file-get-contents
I want to get Json data from Carquery API. But none of my code worked. First i tried to get the data using curl. This is my code $loginUrl = 'http://www.carqueryapi.com/api/0.3/?callback=?&cmd=getTrims&year=2015'; $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL,$loginUrl); $result=curl_exec($ch); curl_close($ch); var_dump(json_decode($result)); It returned null. And then...

XSS and file_get_contents?

php,xss,file-get-contents
My url is like page.php?path=content/x/y/z/aaa.md. Is the following php code XSS-secure? include "Parsedown.php"; function path_purifier($path) { if(substr($path, 0, 8) !== "content/") return null; if (strpos($path,'..') !== false) return null; return "./" . $path; } $parsedown = new Parsedown(); $path = $_GET['path']; $path = path_purifier($path); echo $parsedown->text(file_get_contents($path)); Thanks for your attention...

PHP cant use file_get_html() in AliExpress

php,html,url,file-get-contents
i have been trying to use file_get_html() in AliExpress but i am getting an error. When i try to use the following, everything works: $url = "http://pt.aliexpress.com/br_home.htm"; $retorno = file_get_html($url); When i try to use this, everything collapses: $url = "http://pt.aliexpress.com/item/2015-Hot-Men-s-Fashion-Casual-Slim-Fit-Suit-Jacket-Solid-Color-High-Quality-Masculine-Blazer/32272100970.html?s=p"; $retorno = file_get_html($url); And I get the error:Warning:...

Php newline in Linux (ubuntu) show ^M

php,ubuntu,file-get-contents
I'm running a PHP script on a Ubuntu server. I'm reading a config file with PHP, do some preg_replaces and write back to that file. Doing that with file_get_contents and file_put_contents. But when I do that I see ^M at the end of each line. Why is it there and...

How do can I read a file from a website when it returns 'The requested URL was rejected. Please consult with your administrator.'?

php,xml,file-get-contents
I want to read an xml file from this web page http://www.marketwire.com/rss/mwAS.xml and when I run this piece of code: <?php $json = file_get_contents('http://www.marketwire.com/rss/mwAS.xml'); $xml = json_decode($json, TRUE); print_r($json); print_r($xml); ?> I get this result: " Request Rejected The requested URL was rejected. Please consult with your administrator. Your support...

How to get dynamic url from file_get_contents in PHP

php,file-get-contents
I have a code of php: <?php include('simple_html_dom.php'); $sContent = file_get_contents('http://iztv.com.tr/yayinakisiGunler.aspx?id=1'); $DOM = str_get_html($sContent); foreach($DOM -> find('table tr') as $tr) { $saat = $tr -> find('td', 0)->innertext; $program = $tr -> find('td', 1)->innertext; $rating = $tr -> find('td', 2) -> find('img', 0); if($rating) { $rating = $tr -> find('td', 2)...

file_get_contents now working as expected - external domain works same domain doesn't

php,xml-parsing,file-get-contents
This is a wordpress blog rss feed From domain1, when using this script it will work for domain2 but not domain1. From domain2, when using this script it works for both domain2 and domain1 my assumption is that it must be a permissions error, but I don't know what is...

Pre process file before file_get_contents

php,preprocessor,file-get-contents
I was wondering, in PHP, if there was a way to get PHP to pre-process a file before writing it to a string. Example: I have index.php, which instantiates a class which calls file_get_contents depending on what GET parameter has been passed in via the .htaccess. I have some variables...

php file_get_contents($url) & turns into &

php,url,file-get-contents,ampersand
I am trying to make a request to the coinbase api like this $url = "https://api.exchange.coinbase.com/products/BTC-USD/candles?start=".date($format,$starting_date)."&end=".date($format,$ending_date)."&granularity=".$granularity; and then I pass that in file_get_contents($url) but it gives me an error file_get_contents(https://api.exchange.coinbase.com/products/BTC-USD/candles?start=2015-05-07&amp;end=2015-05-08&amp;granularity=900): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request. the problem ofcourse...

PHP - Changing charset for arabic characters using file_get_contents

php,utf-8,file-get-contents,arabic
I am getting an arabic translation using google, this is my code: header('Content-Type: text/html; charset=UTF-8'); $page=file_get_contents("http://www.google.com/translate_t?langpair=en|ar&text=hello",FILE_TEXT); $page=substr($page,strpos($page,"TRANSLATED_TEXT")+strlen("TRANSLATED_TEXT")+2); $page=substr($page,0,strpos($page,"';INPUT_TOOL_PATH")); echo mb_detect_encoding($page); // edited 2015/05/26 echo mb_convert_encoding($page, 'UTF-8', 'ISO-8859-6'); If you follow the link on the file_get_contents function, you will see...

file_get_contents replace declared variables

php,file-get-contents
I need to open a file which contains php and html code and change some declared variables to user selected values: The file begins: <?php mb_internal_encoding("UTF-8"); ?> <div class="redshop_product td"><!-- for <?php echo basename(__FILE__, '.php')?> //--> <!-- REDshop entry for A Bigger Bundle /title --> <?php $outofstock=1; $explanation="Expected back in...

PHP file_put_contents get file extension/type

php,file-get-contents
It's possible to get extension of a file with file_put_contents in PHP? I want to download files from a server using php with cycle, but each file has a different type and I want to know if there is a way to understand the extension of each file? Code sample:...

Why can't save the web page into my /var/www directory?

php,linux,file,file-get-contents,document-root
The document root is /var/www, I want to download the web page into /var/www/php.html <?php $url = "http://php.net"; $html_content = file_get_contents($url); $fp = fopen("php.html","a"); fwrite($fp,$html_content); fclose($fp); echo $html_content; ?> I can get the web page in firefox, but where is my php.html file ?...

Read a file selected by user in Javascript?

javascript,jquery,file-get-contents,readfile
I have looked around for a while and still haven't found a satisfactory simple answer to this (thought as popular) problem. The solutions are either directed to sending the file directly to the back-end or way too complex. I have this: $("#"+id+" input").change(function() { file = $(this).prop('files')[0] var reader =...

how to insert form query into $html = file_get_contents_curl();

php,html,forms,variables,file-get-contents
Hi i'm trying to use a form submission data in file_get_contents_curl() i want to make a form where you submit an url and get to look up meta tags on that website here's my code: <form method="post" action="index.php"> <input type="text" name="test"> <input type="submit"> </form></center> <?php function file_get_contents_curl($url) { $ch =...

file_get_contents failed to open stream: Connection closed?

php,file-get-contents
Implementation (url is a valid and running url): $html = file_get_contents($url); Hey guys I am programming a crawler in php and sometimes file_get_contents returns the following error: failed to open stream: Connection closed This doesn't always occur, so when it does it confuses me a tad. Would this be an...