php實用函式

2022-02-02 03:25:58 字數 1569 閱讀 3442

將查詢字串解析到變數中:

<?

phpparse_str("name=bill&age=60");

echo $name."

";echo $age;

?>

執行結果:

bill

60

陣列引數:

<?

phpparse_str("name=bill&age=60",$myarray);

print_r($myarray);

?>

執行結果:

array ( [name] => bill [age] => 60 )

對正則匹配的內容用**函式執行的結果進行替換:

// 將文字中的年份增加一年.

$text = "april fools day is 04/01/2002\n";

$text.= "last christmas was 12/24/2001\n";

// **函式

function next_year($matches)

/\d/) 匹配到的內容 : 在上面的文字中是 04/01/ 和 12/24/

//$matches[1]是(\d) 匹配到的內容 : 在上面的文字中是 2002 和 2001

return $matches[1].($matches[2]+1);

}echo preg_replace_callback(

"|(\d/\d/)(\d)|",

"next_year",

$text);

當json_decode解碼無效時,可以試下這個函式。

例項

把預定義的 html 實體 "<"(小於)和 ">"(大於)轉換為字元:

<?php

$str = "this is someboldtext.";

echo htmlspecialchars_decode($str);

?>

上面**的 html 輸出如下(檢視源**):

this is someboldtext.

上面**的瀏覽器輸出如下:

this is some bold text.

④array_map

對陣列裡面的每個元素執行**方法並且返回,。

todo  array_map

function sum($n)

return $sum;

}$array=array(125,1545,1211,100);

var_dump(array_map("sum",$array));

⑤array_search

array_search() 函式在陣列中搜尋某個鍵值,並返回對應的鍵名。

<?

php$a=array("a"=>"red","b"=>"green","c"=>"blue");

echo array_search("red",$a);

?>

PHP 實用函式4

輸出關於php和當前請示的資訊頁面 int phpinfo void 返回當前php版本號 string phpversion void 列印出為本php專案做出貢獻的人員的清單 string phpcredits void 可將 var 轉成整數型別。base 是轉換的基底,預設值為10。轉換的變...

PHP 實用函式5

把乙個數字的二進位制表示形式轉化成十六進製制 string bin2hex string tring 除去字串結尾處的空格 string rtrim string string rtrim的別名 string chop string string 程式設計客棧 從字串的兩頭除去空格 string t...

PHP實用的功能函式

1 2 獲取類 物件的方法列表 3 param unknown argument 類 物件 4 param array string filter 過濾 5 return array 類似 6 78function class get methods argument,filter null 25 ...