Simple html dom file_get_html not working – is there any workaround?

As I said, your example is working fine for me… But try this way using curl instead: //base url $base=”https://play.google.com/store/apps”; $curl = curl_init(); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($curl, CURLOPT_URL, $base); curl_setopt($curl, CURLOPT_REFERER, $base); curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); $str = curl_exec($curl); curl_close($curl); // Create a DOM object $html_base = new simple_html_dom(); // … Read more

file_get_contents not working?

Try this function in place of file_get_contents(): <?php function curl_get_contents($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); $data = curl_exec($ch); curl_close($ch); return $data; } It can be used just like file_get_contents(), but uses cURL. Install cURL on Ubuntu (or other unix-like operating system with aptitude): sudo apt-get install php5-curl … Read more

Get file content from URL?

Depending on your PHP configuration, this may be a easy as using: $jsonData = json_decode(file_get_contents(‘https://chart.googleapis.com/chart?cht=p3&chs=250×100&chd=t:60,40&chl=Hello|World&chof=json’)); However, if allow_url_fopen isn’t enabled on your system, you could read the data via CURL as follows: <?php $curlSession = curl_init(); curl_setopt($curlSession, CURLOPT_URL, ‘https://chart.googleapis.com/chart?cht=p3&chs=250×100&chd=t:60,40&chl=Hello|World&chof=json’); curl_setopt($curlSession, CURLOPT_BINARYTRANSFER, true); curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, true); $jsonData = json_decode(curl_exec($curlSession)); curl_close($curlSession); ?> Incidentally, if you just want … Read more

How to use CURL instead of file_get_contents?

try this: function file_get_contents_curl($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); $data = curl_exec($ch); curl_close($ch); return $data; }

Replace a whole line where a particular word is found in a text file

One approach that you can use on smaller files that can fit into your memory twice: $data = file(‘myfile’); // reads an array of lines function replace_a_line($data) { if (stristr($data, ‘certain word’)) { return “replacement line!\n”; } return $data; } $data = array_map(‘replace_a_line’, $data); file_put_contents(‘myfile’, $data); A quick note, PHP > 5.3.0 supports lambda functions … Read more