PHP curl, fopen, file_get_contents instance code

Source: Internet
Author: User
Tags curl php tutorial

PHP Tutorial Curl Instance

The code is as follows Copy Code

Session_write_close ();

$pageurl = "http://www.111cn.net/index.html";
curl_setopt ($ch, Curlopt_returntransfer, 1);
curl_setopt ($ch, Curlopt_url, $pageurl);
$html = curl_exec ($ch);
Curl_close ($ch);

Then you need to fix pathing to absolute
$search = "/(Src|href|background) =" [^:,^>,^ "]*"/I ";

Preg_match_all ($search, $html, $a _matches);

PHP fopen Instance

The code is as follows Copy Code

$file = fopen ("http://www.111cn.net/", "R"); Reading remote Files

$file = fopen ("A.txt", "R");//Read local file

PHP file_get_contents

$homepage = file_get_contents (' http://www.111cn.net/'); Reading remote text
Echo $homepage;

The code is as follows Copy Code
<= PHP 5
$file = file_get_contents ('./people.txt ', true);
> PHP 5
$file = file_get_contents ('./people.txt ', File_use_include_path); Open Local text

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.