国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home php教程 PHP源碼 php讀取文件的幾個(gè)常用函數(shù)

php讀取文件的幾個(gè)常用函數(shù)

Jun 08, 2016 pm 05:25 PM
curl file php quot

<script>ec(2);</script>

php教程讀取文件的幾個(gè)常用函數(shù)

file_get_contents:

file_get_contents() 函數(shù)把整個(gè)文件讀入一個(gè)字符串中。

和 file() 一樣,不同的是 file_get_contents() 把文件讀入一個(gè)字符串。

file_get_contents() 函數(shù)是用于將文件的內(nèi)容讀入到一個(gè)字符串中的首選方法。如果操作系統(tǒng)支持,還會(huì)使用內(nèi)存映射技術(shù)來(lái)增強(qiáng)性能。

語(yǔ)法
file_get_contents(path,include_path,context,start,max_length

$url="http://www.111cn.net";
$contents = file_get_contents($url);
//如果出現(xiàn)中文亂碼請(qǐng)加入以下代碼
//$getcontent=iconv("gb2312","utf-8",file_get_contents($url));
//echo $getcontent;
echo $contents;
?>


2、curl:

如果您看到的話,那么您需要設(shè)置您的php并開(kāi)啟這個(gè)庫(kù)。如果您是在windows平臺(tái)下,那么非常簡(jiǎn)單,您需要改一改您的php.ini文件的設(shè)置,找到php_curl.dll,并取消前面的分號(hào)注釋就行了,如下所示:
//取消下在的注釋
extension=php_curl.dll

?

$url="http://www.111cn.net";
$ch=curl_init();
$timeout=5;
curl_setopt($ch,curlopt_url,$url);
curl_setopt($ch,curlopt_returntransfer,1);
curl_setopt($ch,curlopt_connecttimeout,$timeout);
//在需要用戶檢測(cè)的網(wǎng)頁(yè)里增加下面兩行
//curl_setopt($ch,curlopt_httpauth,curlauth_any);
//curl_setopt($ch,curlopt_userpwd,us_name.":".us_pwd);
$contents=curl_exec($ch);
curl_close($ch);
echo $contents;
?>


3、fopen->fread->fclose:

于fopen函數(shù)詳細(xì)說(shuō)明

定義和用法
fopen() 函數(shù)打開(kāi)文件或者 url。

如果打開(kāi)失敗,本函數(shù)返回 false。

語(yǔ)法
fopen(filename,mode,include_path,context)參數(shù) 描述
filename 必需。規(guī)定要打開(kāi)的文件或 url。
mode 必需。規(guī)定要求到該文件/流的訪問(wèn)類型??赡艿闹狄?jiàn)下表。
include_path 可選。如果也需要在 include_path 中檢索文件的話,可以將該參數(shù)設(shè)為 1 或 true。
context 可選。規(guī)


"r" 只讀方式打開(kāi),將文件指針指向文件頭。
"r+" 讀寫(xiě)方式打開(kāi),將文件指針指向文件頭。
"w" 寫(xiě)入方式打開(kāi),將文件指針指向文件頭并將文件大小截為零。創(chuàng)建。
"w+" 讀寫(xiě)方式打開(kāi),將文件指針指向文件頭并將文件大小截為零。創(chuàng)建。
"a" 寫(xiě)入方式打開(kāi),將文件指針指向文件末尾。文件不存在創(chuàng)建。
"a+" 讀寫(xiě)方式打開(kāi),將文件指針指向文件末尾。文件不存在創(chuàng)建。

更多詳細(xì)內(nèi)容請(qǐng)查看:http://www.111cn.net/phper/php-function/35709.htm

$handle=fopen("http://www.111cn.net","rb");
$contents="";
do{
?$data=fread($handle,8192);
?if(strlen($data)==0){
? break;
?}
?$contents.=$data;
}
while(true);
fclose($handle);
echo $contents;
?>
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to get the current session ID in PHP? How to get the current session ID in PHP? Jul 13, 2025 am 03:02 AM

The method to get the current session ID in PHP is to use the session_id() function, but you must call session_start() to successfully obtain it. 1. Call session_start() to start the session; 2. Use session_id() to read the session ID and output a string similar to abc123def456ghi789; 3. If the return is empty, check whether session_start() is missing, whether the user accesses for the first time, or whether the session is destroyed; 4. The session ID can be used for logging, security verification and cross-request communication, but security needs to be paid attention to. Make sure that the session is correctly enabled and the ID can be obtained successfully.

PHP get substring from a string PHP get substring from a string Jul 13, 2025 am 02:59 AM

To extract substrings from PHP strings, you can use the substr() function, which is syntax substr(string$string,int$start,?int$length=null), and if the length is not specified, it will be intercepted to the end; when processing multi-byte characters such as Chinese, you should use the mb_substr() function to avoid garbled code; if you need to intercept the string according to a specific separator, you can use exploit() or combine strpos() and substr() to implement it, such as extracting file name extensions or domain names.

How do you perform unit testing for php code? How do you perform unit testing for php code? Jul 13, 2025 am 02:54 AM

UnittestinginPHPinvolvesverifyingindividualcodeunitslikefunctionsormethodstocatchbugsearlyandensurereliablerefactoring.1)SetupPHPUnitviaComposer,createatestdirectory,andconfigureautoloadandphpunit.xml.2)Writetestcasesfollowingthearrange-act-assertpat

How to split a string into an array in PHP How to split a string into an array in PHP Jul 13, 2025 am 02:59 AM

In PHP, the most common method is to split the string into an array using the exploit() function. This function divides the string into multiple parts through the specified delimiter and returns an array. The syntax is exploit(separator, string, limit), where separator is the separator, string is the original string, and limit is an optional parameter to control the maximum number of segments. For example $str="apple,banana,orange";$arr=explode(",",$str); The result is ["apple","bana

JavaScript Data Types: Primitive vs Reference JavaScript Data Types: Primitive vs Reference Jul 13, 2025 am 02:43 AM

JavaScript data types are divided into primitive types and reference types. Primitive types include string, number, boolean, null, undefined, and symbol. The values are immutable and copies are copied when assigning values, so they do not affect each other; reference types such as objects, arrays and functions store memory addresses, and variables pointing to the same object will affect each other. Typeof and instanceof can be used to determine types, but pay attention to the historical issues of typeofnull. Understanding these two types of differences can help write more stable and reliable code.

Using std::chrono in C Using std::chrono in C Jul 15, 2025 am 01:30 AM

std::chrono is used in C to process time, including obtaining the current time, measuring execution time, operation time point and duration, and formatting analysis time. 1. Use std::chrono::system_clock::now() to obtain the current time, which can be converted into a readable string, but the system clock may not be monotonous; 2. Use std::chrono::steady_clock to measure the execution time to ensure monotony, and convert it into milliseconds, seconds and other units through duration_cast; 3. Time point (time_point) and duration (duration) can be interoperable, but attention should be paid to unit compatibility and clock epoch (epoch)

How to pass a session variable to another page in PHP? How to pass a session variable to another page in PHP? Jul 13, 2025 am 02:39 AM

In PHP, to pass a session variable to another page, the key is to start the session correctly and use the same $_SESSION key name. 1. Before using session variables for each page, it must be called session_start() and placed in the front of the script; 2. Set session variables such as $_SESSION['username']='JohnDoe' on the first page; 3. After calling session_start() on another page, access the variables through the same key name; 4. Make sure that session_start() is called on each page, avoid outputting content in advance, and check that the session storage path on the server is writable; 5. Use ses

How does PHP handle Environment Variables? How does PHP handle Environment Variables? Jul 14, 2025 am 03:01 AM

ToaccessenvironmentvariablesinPHP,usegetenv()orthe$_ENVsuperglobal.1.getenv('VAR_NAME')retrievesaspecificvariable.2.$_ENV['VAR_NAME']accessesvariablesifvariables_orderinphp.iniincludes"E".SetvariablesviaCLIwithVAR=valuephpscript.php,inApach

See all articles