file-get-contents

How to include files with HTTPS - PHP

I made a form process and broke the code up into different files to stay clean and organized. Now I am setting up the form for https security. Do all the files I pull into my page have to be called as https as well? In which case I can no longer use include(); as it no longer allows relative paths? Is the solution to use file_get_cont...

Get content between two strings PHP

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? #...

Looping and file_get_contents in PHP

Hello, I have written a page that will scan a site and then extract certain code from the source. That part is working successfully, however I want to run this over multiple pages and dump the details into a database. I am stuggling to get the loop working, this is what I currently have (please be gentle this is my first attempt at anyt...

php regex for link url

Hay guys i need help on a regex. I'm using file_get_contents() to get the source of a page, i want to then loop through the source and find all the and extract all the HREF values into an array. Thanks ...

PHP - Custom errors

Hi all, I'm trying to read a file when ever an error occurs within my scripts so I can throw a custom error page. When using ob_start/set_error_handler I am unable to use file_get_contents or ob_start within the callback to get the contents of my error template. Does anyone know how I can output my custom template (and using eval) wi...

file_get_contents and file_put_contents with large files

Hi there! I'm trying to get file contents, replace some parts of it using regular expressions and preg_replace and save it to another file: $content = file_get_contents('file.txt', true); $content_replaced = preg_replace('/\[\/m\]{1}\s+(\{\{.*\}\})\s+[\x{4e00}-\x{9fa5}]+/u', 'replaced text', $contents); if ($content_replaced) { fi...

Handling delays when retrieving files from remote server in PHP

Hello, I am working with PHP to access files and photos from remote servers. I am mostly using the file_get_contents() and copy() functions. Sometimes accessing a small text file or photo is almost instant, but other times it seems to get "stuck" for a minute on the same exact file. And sometimes it actually causes my script to hang,...

PHP file_get_contents causes page to be inaccessible

Hi, I'm trying to use file_get_contents in php to display an RSS feed. However, when I try to load the page, it fails (as if waiting for something to complete). If I remove the code and save the file again, the page still refuses to work for 5 minutes or so, after which, it goes back to normal. Can anyone help shed any light on what is ...

file_get_contents() GET request not showing up on my webserver log

I've got a simple php script to ping some of my domains using file_get_contents(), however I have checked my logs and they are not recording any get requests. I have $result = file_get_contents($url); echo $url. ' pinged ok\n'; where $url for each of the domains is just a simple string of the form http://mydomain.com/, echo verifie...

Image doesn't display using readfile / file_get_contents

if(preg_match('/^[a-zA-Z0-9]+\.(gif|jpe?g)$/',$row['filename'],$matches) && is_readable($row['filepath'].$row['filename'])){ echo header('Content-Type: image/'.$matches[1]); echo header('Content-Length: '.filesize($row['filepath'].$row['filename'])); echo file_get_contents($row['filepath'].$row['filename']); } else ...

Ignore data within a certain set of characters with PHP

Not sure what this is called, but is there a way I can pull data from a file, echo it, but ignore data within a certain set of characters? <?php echo file_get_contents('test.txt'); ?> Would it be possible to ignore the data in between the asterisks, and the asterisks themselves when I echo out the final function? ...

Checking a string against a pattern

I want to check posted content against a pattern. I am having trouble setting up this preg_match (or array?). The pattern being... TEXTHERE:TEXTHERE TEST:TEST FILE:FILE AND TEXTHERE:TEXTHERE TEST:TEST FILE:FILE I want to check for either pattern, the one with the whitespace and the one with the line break. If the posted content is...

PHP - Drop down list to display .txt contents

I have a form that has a drop down list of song titles. I want to be able to click on one of the song titles and the lyrics be loaded on the same page. The lyrics are contained within .txt files in a folder called "Lyrics". Example: Drop down list contains: Song1 Song2 Song3 etc. When the user clicks on the song, the contents of th...

PHP string within JavaScript

I currently am trying to echo the contents of a text file within JavaScript. Everything works but there is a problem. The text within the text contains apostrophes, which is throwing everything off. Below is a portion of the code that I am using. I am using this code for MANY text files. I have considered changing each apostrophe to...

file_get_contents with https?

I'm working on setting up credit card processing and needed to use a workaround for CURL, and the following code worked fine when I was using the test server (which wasn't calling an SSL URL), but now when I am testing it on the working server with https, it doesn't work ("failed to open stream"). function send($packet, $url) { $ctx =...

file_get_contents with query string

i am trying to send email from php i have one php file with all values & other php template file. (both files are on same server) i am using file_get_contents to get contents of php template file for example $url="emil_form.php"; $a="uname"; if(($Content = file_get_contents($url. "?uname=".$a)) === false) { $Content = ""; ...

good way to go about doing page excerpts

Hi, I'm looking to achieve the effect facebook has when you put a link into a message - they scrape the title and some images from it. I noticed they also do it extremely quickly. (they must cache some of the re-sent items?) Does anyone have any ideas on how to approach this with PHP? Can I somehow quickly grab the <title> block of the...

PHP readfile or file_get_contents in a loop

there may be other ways to do this but I'm looking for an fairly easy set-up because it's basically a one-time process. I have 50 state directories with a handful of txt files in each one. I want to step into each directory, "read" each file (and then do a mysql insert of each file) I've tried a few variations, but each time I try to ...

file_get_contents() Breaks Up UTF-8 Characters

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...

PHP curl and file_get_contents returns the main website located on the server when I enter a valid URL without DNS resolution

When I call the following: file_get_contents('http://whgfdw.ca'); or $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://whgfdw.ca'); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_exec($ch); The return value is the HTML of the homepage of the main site located on the local (dedicated) w...