In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you the "what are the common functions of PHP", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "what common functions PHP has" this article.
PHP common function 1. Generate a random string function
Function random ($length) {
$hash = @ # @
$chars = @ # abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz@#
$max = strlen ($chars)-1
Mt_srand ((double) microtime () * 1000000)
For ($I = 0; $I
< $length; $i++) { $hash .= $chars[mt_rand(0, $max)]; } return $hash; } PHP常用函数2.截取一定长度的字符串 注:该函数对gb2312使用有效 function wordscut($string, $length ,$sss=0) { if(strlen($string) >$length) {if ($sss) {$length=$length-3; $addstr=@#... @ #;} for ($I = 0; $I
< $length; $i++) { if(ord($string[$i]) >{$wordscut. = $string [$I]. $string [$I + 1]; $iTunes;} else {$wordscut. = $string [$I];}} return $wordscut.$addstr;} return $string;}
PHP common function 3. Get the client ip address
Function getip () {
If (getenv ("http_client_ip")
& & strcasecmp (getenv ("http_client_ip"), "unknown")
$ip = getenv ("http_client_ip")
Else if (getenv ("http_x_forwarded_for")
& & strcasecmp (getenv ("http_x_forwarded_for"), "unknown")
$ip = getenv ("http_x_forwarded_for")
Else if (getenv ("remote_addr")
& & strcasecmp (getenv ("remote_addr"), "unknown")
$ip = getenv ("remote_addr")
Else if (isset ($_ server [@ # remote_addr@#])
& & $_ server [@ # remote_addr@#]
& & strcasecmp ($_ server [@ # remote_addr@#], "unknown"))
$ip = $_ server [@ # remote_addr@#]
Else
$ip = "unknown"
Return ($ip)
}
PHP common function 4. Create the appropriate folder
Function createdir ($dir=@#@#) {if (! is_dir ($dir)) {$temp = explode (@ # / @ #, $dir); $cur_dir = @ # @ #; for
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.