<?php
// 如果 $_GET['user'] 不存在返回 'nobody',否则返回 $_GET['user'] 的值
$username = $_GET['user'] ?? 'nobody';
// 类似的三元运算符
$username = isset($_GET['user']) ? $_GET['user'] : 'nobody';
?>
是否存在字符
public function pe_indexof($str, $needle)
{
$pos = strpos($str,$needle);
return (strlen($pos)==1)? strlen($pos) : -1;
}
/** 使用案例 **/
if($this->pe_indexof(“http://192.168.0.0.1”,'http://')>=1) {
echo "包含http://";
}
else {
echo "不包含http://";
}
数据库端口
mysqli_connect(host,username,password,dbname,port,socket);
$db_port = '1234'; // 设置端口
if ($this->link_type == 'mysqli') {
$this->link = mysqli_connect($db_host.$db_port, $db_user, $db_pw);
}
else {
$this->link = mysql_connect($db_host.$db_port, $db_user, $db_pw);
}