php常用函数

php

18-12-5 16:20:04

htmlspecialchars()  预定义的字符 "<" (小于)和 ">" (大于)转换为 HTML 实体

strtolower() 把字符串转换为小写字母。


strtoupper() 把字符串转换为大写字母。

explode 字符串切割
$pizza="第1 第2 第3 第4 第5 第6";
$pieces=explode(" ",$pizza);

join 数组合并字符串
$arr = array('Hello','World!','I','love','Shanghai!');
echo join(" ",$arr);

str_pad 字符串填充
$input = "Alien"; 
echo str_pad($input, 10); // produces "Alien " 
echo str_pad($input, 10, "-=", STR_PAD_LEFT); // produces "-=-=-Alien" 
echo str_pad($input, 10, "_", STR_PAD_BOTH); // produces "__Alien___" 
echo str_pad($input, 6 , "___"); // produces "Alien_


file_get_contents 读取文件或者网址
 file_get_contents('./people.txt');

file_put_contents 写入文件
file_put_contents("test.txt","Hello World. Testing!");
FILE_APPEND 追加
LOCK_EX 锁定

nl2br  \n换行

echo nl2br("One line.\nAnother line.");


var_export 函数   数组转字符串

var_export($db, TRUE);   //var_export 函数




$records = array(
    array(
        
'id' => 2135,
        
'first_name' => 'John',
        
'last_name' => 'Doe',
    ),
    array(
        
'id' => 3245,
        
'first_name' => 'Sally',
        
'last_name' => 'Smith',
    ),
    array(
        
'id' => 5342,
        
'first_name' => 'Jane',
        
'last_name' => 'Jones',
    ),
    array(
        
'id' => 5623,
        
'first_name' => 'Peter',
        
'last_name' => 'Doe',
    )
);

 

$last_names array_column($records'last_name''id');

 $data = array_column($data,null, 'name');     name为键值  整个数组装进去

print_r($last_names);


Array
(
    [2135] => Doe
    [3245] => Smith
    [5342] => Jones
    [5623] => Doe
)


$first_names array_column($records'first_name');
print_r($first_names);


Array
(
    [0] => John
    [1] => Sally
    [2] => Jane
    [3] => Peter
)