當前位置:首頁 » 編程語言 » php獲得內容

php獲得內容

發布時間: 2024-04-15 07:13:56

『壹』 php主要學習什麼內容

  • 基礎語法:學習 PHP 的基本語法,如變數、數據類型、控制結構、函數等。

  • Web 基礎:了解 Web 的基本概念,如 HTTP、HTML、CSS、JavaScript 等。

  • 頁面動態生成:學習如何使用 PHP 在伺服器端動態生成頁面。

  • 資料庫操作:學習如何使用 PHP 與資料庫(如 MySQL)進行交互,如讀寫數據、執行查詢等。

  • 項目實戰:完成一個或多個 PHP 項目,練習您所學的知識。

  • 框架:學習使用 PHP 框架(如 Laravel、Symfony 等)開發 Web 應用。

  • 安全:學習如何保護 PHP 程序免受安全漏洞的影響。

『貳』 PHP怎麼獲取裡面的內容

1、用file_get_contents,以get方式獲取內容。

『叄』 php獲取網頁源碼內容有哪些辦法

可以參考以下幾種方法:

方法一: file_get_contents獲取

<span style="white-space:pre"></span>$url="http://www..com/";

<span style="white-space:pre"></span>$fh= file_get_contents

('http://www.hxfzzx.com/news/fzfj/');<span style="white-space:pre"></span>echo $fh;

拓展資料

PHP(外文名:PHP: Hypertext Preprocessor,中文名:「超文本預處理器」)是一種通用開源腳本語言。語法吸收了C語言、Java和Perl的特點,利於學習,使用廣泛,主要適用於Web開發領域。PHP 獨特的語法混合了C、Java、Perl以及PHP自創的語法。它可以比CGI或者Perl更快速地執行動態網頁。

用PHP做出的動態頁面與其他的編程語言相比,PHP是將程序嵌入到HTML(標准通用標記語言下的一個應用)文檔中去執行,執行效率比完全生成HTML標記的CGI要高許多;PHP還可以執行編譯後代碼,編譯可以達到加密和優化代碼運行,使代碼運行更快。

『肆』 php獲取指定網頁內容

一、用file_get_contents函數,以post方式獲取url

<?php

$url='http://www.domain.com/test.php?id=123';

$data=array('foo'=>'bar');

$data= http_build_query($data);

$opts=array(

'http'=>array(

'method'=>'POST',

'header'=>"Content-type: application/x-www-form-urlencoded " .

"Content-Length: " .strlen($data) ." ",

'content'=>$data

)

);

$ctx= stream_context_create($opts);

$html= @file_get_contents($url,'',$ctx);

二、用file_get_contents以get方式獲取內容

<?php

$url='http://www.domain.com/?para=123';

$html=file_get_contents($url);

echo$html;

?>

三、用fopen打開url, 以get方式獲取內容

<?php

$fp=fopen($url,'r');

$header= stream_get_meta_data($fp);//獲取報頭信息

while(!feof($fp)) {

$result.=fgets($fp, 1024);

}

echo"url header: {$header} <br>":

echo"url body: $result";

fclose($fp);

?>

四、用fopen打開url, 以post方式獲取內容

<?php

$data=array('foo2'=>'bar2','foo3'=>'bar3');

$data= http_build_query($data);

$opts=array(

'http'=>array(

'method'=>'POST',

'header'=>"Content-type: application/x-www-form-

urlencoded Cookie:cook1=c3;cook2=c4 " .

"Content-Length: " .strlen($data) ." ",

'content'=>$data

)

);

$context= stream_context_create($opts);

$html=fopen('http://www.test.com/zzzz.php?id=i3&id2=i4','rb',false,$context);

$w=fread($html,1024);

echo$w;

?>

五、使用curl庫,使用curl庫之前,可能需要查看一下php.ini是否已經打開了curl擴展

<?php

$ch= curl_init();

$timeout= 5;

curl_setopt ($ch, CURLOPT_URL,'http://www.domain.com/');

curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT,$timeout);

$file_contents= curl_exec($ch);

curl_close($ch);

echo$file_contents;

?>

『伍』 php如何讀取文本指定的內容

php讀取文件內容:
-----第一種方法-----fread()--------
<?php
$file_path = "test.txt";
if(file_exists($file_path)){
$fp = fopen($file_path,"r");
$str = fread($fp,filesize($file_path));//指定讀取大小,這里把整個文件內容讀取出來
echo $str = str_replace("\r\n","<br />",$str);
}
?>

--------第二種方法------------
<?php
$file_path = "test.txt";
if(file_exists($file_path)){
$str = file_get_contents($file_path);//將整個文件內容讀入到一個字元串中
$str = str_replace("\r\n","<br />",$str);
echo $str;
}
?>
-----第三種方法------------
<?php
$file_path = "test.txt";
if(file_exists($file_path)){
$fp = fopen($file_path,"r");
$str = "";
$buffer = 1024;//每次讀取 1024 位元組
while(!feof($fp)){//循環讀取,直至讀取完整個文件
$str .= fread($fp,$buffer);
}
$str = str_replace("\r\n","<br />",$str);
echo $str;
}
?>
-------第四種方法--------------
<?php
$file_path = "test.txt";
if(file_exists($file_path)){
$file_arr = file($file_path);
for($i=0;$i<count($file_arr);$i++){//逐行讀取文件內容
echo $file_arr[$i]."<br />";
}
/*
foreach($file_arr as $value){
echo $value."<br />";
}*/
}
?>
----第五種方法--------------------
<?php
$file_path = "test.txt";
if(file_exists($file_path)){
$fp = fopen($file_path,"r");
$str ="";
while(!feof($fp)){
$str .= fgets($fp);//逐行讀取。如果fgets不寫length參數,默認是讀取1k。
}
$str = str_replace("\r\n","<br />",$str);
echo $str;
}
?>

『陸』 php thinkphp3。2怎麼獲取某資料庫欄位的內容

需要准備的材料分別是:電腦、php編輯器、瀏覽器。

1、首先,打開php編輯器,新建php文件,例如:index.php,以獲取user表name欄位為例。

『柒』 php獲取指定網頁內容

此類方法一共有三種

  1. 第一種方法

<?php

$c = curl_init();

$url = 'www.badcatxt.com';

curl_setopt($c, CURLOPT_URL, $url);

curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);

$data = curl_exec($c);
curl_close($c);

$pos = strpos($data,'utf-8');

if($pos===false){$data = iconv("gbk","utf-8",$data);}

preg_match("/<title>(.*)</title>/i",$data, $title);

echo $title[1];

?>

第二種方法:使用file()函數

<?php

$lines_array = file('http://www.badcatxt.com/');

$lines_string = implode('', $lines_array);

$pos = strpos($lines_string,'utf-8');

if($pos===false){$lines_string = iconv("gbk","utf-8",$lines_string);}

eregi("<title>(.*)</title>", $lines_string, $title);

echo $title[1];

?>

第三種方法:使用file_get_contents

<?php

$content=file_get_contents("http://www.badcatxt.com/");

$pos = strpos($content,'utf-8');

if($pos===false){$content = iconv("gbk","utf-8",$content);}

$postb=strpos($content,'<title>')+7;

$poste=strpos($content,'</title>');

$length=$poste-$postb;

echo substr($content,$postb,$length);

?>

『捌』 php獲取當前頁面用戶輸入內容的方式有哪些

獲取用戶提交過來的數據一般常用的有三種:$_GET,$_POST,$GLOBALS,這三個全局變數都是數組,數組下標是用戶提交過來的欄位名稱,比如:
<input type="text" name="number" value="123456">
則在PHP可通過如下方式獲取:
$_GET['number']
$GLOBALS['number']
如果表單是POST提交過來的可以用如下方式提取
$_POST['number']
$GLOBALS['number']
$GLOBALS全局數組不管是POST提交還是GET提交都能夠獲取到

熱點內容
解壓剃發 發布:2024-05-21 03:16:27 瀏覽:640
伺服器怎麼連接到電腦顯示屏上 發布:2024-05-21 02:38:21 瀏覽:285
織夢安裝資料庫連接失敗 發布:2024-05-21 02:37:45 瀏覽:258
python編程入門經典pdf 發布:2024-05-21 02:31:45 瀏覽:6
arm編譯添加驅動 發布:2024-05-21 02:02:28 瀏覽:476
安卓設置頁面是怎麼 發布:2024-05-21 01:32:51 瀏覽:521
學生成績管理系統資料庫設計 發布:2024-05-21 01:14:41 瀏覽:43
我的世界什麼指令直接出現伺服器 發布:2024-05-21 01:10:00 瀏覽:397
星等演算法 發布:2024-05-21 00:53:06 瀏覽:509
李興華的java視頻 發布:2024-05-21 00:49:55 瀏覽:605