新聞中心
php如何獲取網(wǎng)址中的參數(shù)
比如有一個網(wǎng)址為
成都創(chuàng)新互聯(lián)公司2013年至今,先為杜集等服務(wù)建站,杜集等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為杜集企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。
http://域名/goods.php?u=59id=24#pinglun
我想得到這個id值
可以用正則,也可以用php函數(shù)解析到數(shù)組中
用正則可以這樣
preg_match('/id=(\d+)/',$_SERVER["REQUEST_URI"],$m);//$_SERVER 這個表示當(dāng)前網(wǎng)址url
print_r($m[1]);exit;
或者用parse_url()及parse_str()函數(shù)
$cur_q=parse_url($_SERVER["REQUEST_URI"],PHP_URL_QUERY);
parse_str($cur_q,$myArray);
print_r($myArray["id"]);exit;
拓展資料
PHP(外文名:PHP: Hypertext Preprocessor,中文名:“超文本預(yù)處理器”)是一種通用開源腳本語言。語法吸收了C語言、Java和Perl的特點(diǎn),利于學(xué)習(xí),使用廣泛,主要適用于Web開發(fā)領(lǐng)域。PHP 獨(dú)特的語法混合了C、Java、Perl以及PHP自創(chuàng)的語法。它可以比CGI或者Perl更快速地執(zhí)行動態(tài)網(wǎng)頁。用PHP做出的動態(tài)頁面與其他的編程語言相比,PHP是將程序嵌入到HTML(標(biāo)準(zhǔn)通用標(biāo)記語言下的一個應(yīng)用)文檔中去執(zhí)行,執(zhí)行效率比完全生成HTML標(biāo)記的CGI要高許多;PHP還可以執(zhí)行編譯后代碼,編譯可以達(dá)到加密和優(yōu)化代碼運(yùn)行,使代碼運(yùn)行更快。
PHP的特性包括:
1. PHP 獨(dú)特的語法混合了 C、Java、Perl 以及 PHP 自創(chuàng)新的語法。
2. PHP可以比CGI或者Perl更快速的執(zhí)行動態(tài)網(wǎng)頁——動態(tài)頁面方面,與其他的編程語言相比,
PHP是將程序嵌入到HTML文檔中去執(zhí)行,執(zhí)行效率比完全生成htmL標(biāo)記的CGI要高許多;
PHP具有非常強(qiáng)大的功能,所有的CGI的功能PHP都能實(shí)現(xiàn)。
3. PHP支持幾乎所有流行的數(shù)據(jù)庫以及操作系統(tǒng)。
4. 最重要的是PHP可以用C、C++進(jìn)行程序的擴(kuò)展!
參考資料:百度百科 PHP
php里面 collect_data()是干什么的
這個文件夾下應(yīng)該還有.frm,.myd,.myi文件,這些都是mysql數(shù)據(jù)庫文件,opt是配置文件,.frm描述了表的結(jié)構(gòu),.MYD保存了表的數(shù)據(jù)記錄,.MYI則是表的索引.
使用時直接將以數(shù)據(jù)庫命名的文件夾拷貝到mysql安裝目錄的data文件夾下面就可以了.
好運(yùn)!
PHP怎么接收數(shù)據(jù)
三中接受方式:
$_GET ? ?//get過來的數(shù)據(jù)
$_POST ?//post過來的數(shù)據(jù)
file_get_contents("php://input") ? //接口過來的xml等字符串?dāng)?shù)據(jù)用這個接
這三個方法足以接受任何數(shù)據(jù)了,具體你還要百度一下用法
PHP 采集程序中常用的函數(shù)
復(fù)制代碼
代碼如下:
//獲得當(dāng)前的腳本網(wǎng)址
function
get_php_url()
{
if(!empty($_SERVER[”REQUEST_URI”]))
{
$scriptName
=
$_SERVER[”REQUEST_URI”];
$nowurl
=
$scriptName;
}
else
{
$scriptName
=
$_SERVER[”PHP_SELF”];
if(empty($_SERVER[”QUERY_STRING”]))
$nowurl
=
$scriptName;
else
$nowurl
=
$scriptName.”?”.$_SERVER[”QUERY_STRING”];
}
return
$nowurl;
}
//把全角數(shù)字轉(zhuǎn)為半角數(shù)字
function
GetAlabNum($fnum)
{
$nums
=
array(”0”,”1”,”2”,”3”,”4”,”5”,”6”,”7”,”8”,”9”);
$fnums
=
“0123456789″;
for($i=0;$i=9;$i++)
$fnum
=
str_replace($nums[$i],$fnums[$i],$fnum);
$fnum
=
ereg_replace(”[^0-9\.]|^0{1,}”,””,$fnum);
if($fnum==””)
$fnum=0;
return
$fnum;
}
//去除HTML標(biāo)記
function
Text2Html($txt)
{
$txt
=
str_replace(”
“,” ”,$txt);
$txt
=
str_replace(””,””,$txt);
$txt
=
str_replace(””,””,$txt);
$txt
=
preg_replace(”/[\r\n]{1,}/isU”,”br/\r\n”,$txt);
return
$txt;
}
//清除HTML標(biāo)記
function
ClearHtml($str)
{
$str
=
str_replace('','',$str);
$str
=
str_replace('','',$str);
return
$str;
}
//相對路徑轉(zhuǎn)化成絕對路徑
function
relative_to_absolute($content,
$feed_url)
{
preg_match('/(http|https|ftp):\/\//',
$feed_url,
$protocol);
$server_url
=
preg_replace(”/(http|https|ftp|news):\/\//”,
“”,
$feed_url);
$server_url
=
preg_replace(”/\/.*/”,
“”,
$server_url);
if
($server_url
==
”)
{
return
$content;
}
if
(isset($protocol[0]))
{
$new_content
=
preg_replace('/href=”\//',
‘href=”‘.$protocol[0].$server_url.'/',
$content);
$new_content
=
preg_replace('/src=”\//',
'src=”‘.$protocol[0].$server_url.'/',
$new_content);
}
else
{
$new_content
=
$content;
}
return
$new_content;
}
//取得所有鏈接
function
get_all_url($code){
preg_match_all('/a\s+href=[”|\']?([^”\'
]+)[”|\']?\s*[^]*([^]+)\/a/i',$code,$arr);
return
array('name'=$arr[2],'url'=$arr[1]);
}
//獲取指定標(biāo)記中的內(nèi)容
function
get_tag_data($str,
$start,
$end)
{
if
(
$start
==
”
||
$end
==
”
)
{
return;
}
$str
=
explode($start,
$str);
$str
=
explode($end,
$str[1]);
return
$str[0];
}
//HTML表格的每行轉(zhuǎn)為CSV格式數(shù)組
function
get_tr_array($table)
{
$table
=
preg_replace(”‘td[^]*?'si”,'”‘,$table);
$table
=
str_replace(”/td”,'”,',$table);
$table
=
str_replace(”/tr”,”{tr}”,$table);
//去掉
HTML
標(biāo)記
$table
=
preg_replace(”‘[\/\!]*?[^]*?'si”,””,$table);
//去掉空白字符
$table
=
preg_replace(”‘([\r\n])[\s]+'”,””,$table);
$table
=
str_replace(”
“,””,$table);
$table
=
str_replace(”
“,””,$table);
$table
=
explode(”,{tr}”,$table);
array_pop($table);
return
$table;
}
//將HTML表格的每行每列轉(zhuǎn)為數(shù)組,采集表格數(shù)據(jù)
function
get_td_array($table)
{
$table
=
preg_replace(”‘table[^]*?'si”,””,$table);
$table
=
preg_replace(”‘tr[^]*?'si”,””,$table);
$table
=
preg_replace(”‘td[^]*?'si”,””,$table);
$table
=
str_replace(”/tr”,”{tr}”,$table);
$table
=
str_replace(”/td”,”{td}”,$table);
//去掉
HTML
標(biāo)記
$table
=
preg_replace(”‘[\/\!]*?[^]*?'si”,””,$table);
//去掉空白字符
$table
=
preg_replace(”‘([\r\n])[\s]+'”,””,$table);
$table
=
str_replace(”
“,””,$table);
$table
=
str_replace(”
“,””,$table);
$table
=
explode('{tr}',
$table);
array_pop($table);
foreach
($table
as
$key=$tr)
{
$td
=
explode('{td}',
$tr);
array_pop($td);
$td_array[]
=
$td;
}
return
$td_array;
}
//返回字符串中的所有單詞
$distinct=true
去除重復(fù)
function
split_en_str($str,$distinct=true)
{
preg_match_all('/([a-zA-Z]+)/',$str,$match);
if
($distinct
==
true)
{
$match[1]
=
array_unique($match[1]);
}
sort($match[1]);
return
$match[1];
}
本文名稱:php函數(shù)收集數(shù)據(jù) php怎么獲取數(shù)據(jù)庫中的數(shù)據(jù)
URL標(biāo)題:http://www.dlmjj.cn/article/dospcch.html