search
HomeBackend DevelopmentPHP TutorialThe second day of php practice_PHP tutorial
The second day of php practice_PHP tutorialJul 14, 2016 am 10:10 AM
addfunctionphpsuperiorWritebackActual combatInfluencemethodAdd tomessage boardreturn



1. I wrote the add method on my message board


[php] function add(){
//After adding, return the number of affected items. If it is greater than 0, it means the addition is successful
If($this->db->data($_POST)->add()>0){
            echo "Added successfully";
// echo "<script>location.reload()</script>";//Prevent repeated submission of the refreshed form
Header("HTTP/1.1 303 See Other");
        Header("Location: "); //Redirect to the root directory
exit;
                                                        }else {
            die($this->db->error());//Add failure output error message
}  
}

function add(){

//After adding, return the number of affected items. If it is greater than 0, it means the addition is successful
If($this->db->data($_POST)->add()>0){
echo "Added successfully";
//echo "<script>location.reload()</script>";//Prevent repeated submission of the refreshed form
Header("HTTP/1.1 303 See Other");
Header("Location: "); //Redirect to the root directory
exit;
 
}else {
Die($this->db->error());//Add failure output error message
}  
}Corresponding submission form


[html] 

 
   
 
         
                         
                             
                             
                         
                         
                             
                             
                         
                         
                             
                             
                         
                         
                             
                             
                         
       
用户名
留言内容
电子邮箱email:
 
             
                     
               
 
           
 
 


 

   
                       
                           
                           
                       
                       
                           
                           
                       
                       
                           
                           
                       
                       
                           
                           
                       
  
用户名
留言内容
电子邮箱 email:

           
                   
               

   

2. Modified the MYSQL operation class so that data automatically processes the passed data, compares whether the field exists, and does not add it if it does not exist.


[php] // +-------------------------------------------------- -----------------------
// |MySQL operation class
// +-------------------------------------------------- -----------------------
// |@微梁QQ:496928838
// +-------------------------------------------------- -----------------------
class MySQL{
       
Private $db_mysql_hostname;
Private $db_mysql_username;
Private $db_mysql_password;
Private $db_mysql_database;
Private $db_mysql_port;
Private $db_mysql_charset;
       
Private $query_list = array();
       
//Number of queries
Public $query_count = 0;
//Query start time
Public $query_start_time;
       
//Current query ID
protected $queryID;
//Current connection
protected $conn;
// Number of transaction instructions
protected $transTimes = 0;
// Return or affect the number of records
protected $numRows = 0;
// Error message
protected $error = '';
       
Public function __construct($hostname_or_conf,$username,$password,$database,$port = '3306',$char = 'utf8'){
If(is_array($hostname_or_conf)){
                 $this->db_mysql_hostname = $hostname_or_conf['hostname'];
                $this->db_mysql_username = $hostname_or_conf['username'];
                $this->db_mysql_password = $hostname_or_conf['password'];
                 $this->db_mysql_database = $hostname_or_conf['database'];
                 $this->db_mysql_port = isset($hostname_or_conf['port'])?$hostname_or_conf['port']:'3306';
                 $this->db_mysql_charset = isset($hostname_or_conf['charset'])?$hostname_or_conf['charset']:'utf8';
                                                                              }elseif(!empty($hostname_or_conf)||!empty($username)||!empty($password)||!empty($database))
                                                                                      $this->db_mysql_hostname = $hostname_or_conf;
                   $this->db_mysql_username = $username;
$this->db_mysql_password = $password;
                    $this->db_mysql_database = $database;
                    $this->db_mysql_port = $port;
$this->db_mysql_charset = $char;
                                                                             }else{
                die('configuration error.');
         } 
$this->connect();
}  
       
private function connect(){
$server = $this->db_mysql_hostname.':'.$this->db_mysql_port;
        $this->conn = mysql_connect($server,$this->db_mysql_username,$this->db_mysql_password,true) or die('Connect MySQL DB error!'); 
        mysql_select_db($this->db_mysql_database,$this->conn) or die('select db error!'); 
        mysql_query("set names " . $this->db_mysql_charset, $this->conn); 
    } 
    /**
+------------------------------------------------- ----------
* Set data object value
+------------------------------------------------- ----------
* @access public
+------------------------------------------------- ----------
*table,where,order,limit,data,field,join,group,having
+------------------------------------------------- ----------
​​*/ 
    public function table($table){ 
        $this->query_list['table'] = $table; 
        return $this; 
    } 
     
    public function where($where){ 
        $this->query_list['where'] = $where; 
        return $this; 
    } 
     
    public function order($order){ 
        $this->query_list['order'] = $order; 
        return $this; 
    } 
     
    public function limit($offset,$length){ 
        if(!isset($length)){ 
            $length = $offset; 
            $offset = 0; 
        } 
        $this->query_list['limit'] = 'limit '.$offset.','.$length; 
        return $this; 
    } 
     
    public function data($data){ 
        //读取数据表字段,然后处理表单数据  
        $dataList = $this->getFields($this->query_list['table']); 
        $arr=array(); 
        foreach ($dataList as $key=>$value) { 
            if (array_key_exists ($key,$data) ) { 
                $arr[$key]=$data[$key]; 
            } 
             
        } 
        //var_dump($arr);  
        /*
        if(is_object($data)){
            $data   =   get_object_vars($data);
        }elseif (is_string($data)){
            parse_str($data,$data);
        }elseif(!is_array($data)){
            //Log:DATA_TYPE_INVALID
        }
        */ 
        $this->query_list['data'] = $arr; 
        return $this; 
    } 
    public function field($fields){ 
        $this->query_list['fields'] = $fields; 
        return $this; 
    } 
    public function join($join){ 
        $this->query_list['join'] = $join; 
        return $this; 
    } 
    public function group($group){ 
        $this->query_list['group'] = $group; 
        return $this; 
    } 
    public function having($having){ 
        $this->query_list['having'] = $having; 
        return $this; 
    } 
    /**
+------------------------------------------------- ----------
* Query
+------------------------------------------------- ----------
* @access public
+------------------------------------------------- ----------
* @param
+------------------------------------------------- ----------
​​*/ 
    public function select(){ 
        $select_sql = 'select '; 
        $fields = isset($this->query_list['fields'])?$this->query_list['fields']:'*'; 
        $select_sql.=$fields; 
        $select_sql.= ' from `'.$this->query_list['table'].'` '; 
         
        isset($this->query_list['join'])?($select_sql.=$this->query_list['join']):''; 
        isset($this->query_list['where'])?($select_sql.=' where '.$this->query_list['where']):''; 
        isset($this->query_list['group'])?($select_sql.=' group by'.$this->query_list['group']):''; 
        isset($this->query_list['having'])?($select_sql.=' mysql having '.$this->query_list['having']):''; 
        isset($this->query_list['order'])?($select_sql.=' order by '.$this->query_list['order']):''; 
        isset($this->query_list['limit'])?($select_sql.=' '.$this->query_list['limit']):''; 
         
        return $this->query($select_sql); 
    } 
    /**
+------------------------------------------------- ----------
* Add
+------------------------------------------------- ----------
* @access public
+------------------------------------------------- ----------
* @param
+------------------------------------------------- ----------
​​*/ 
    public function add(){ 
        $add_sql = 'insert into `'.$this->query_list['table'].'` ('; 
         
        $data = $this->query_list['data']; 
        $value = $field = ''; 
        foreach($data as $k=>$v){ 
            $field .= '`'.$k.'`,'; 
            if(is_numeric($v)) 
                $value .= $v.','; 
            else 
                $value .= '''.$v.'','; 
        } 
        $add_sql .= rtrim($field,',').') values ('.rtrim($value,',').')'; 
 
    //  echo 'add_sql'.$add_sql;  
        return $this->execute($add_sql); 
    } 
    /**
+------------------------------------------------- ----------
* Delete
+------------------------------------------------- ----------
* @access public
+------------------------------------------------- ----------
* @param
+------------------------------------------------- ----------
​​*/ 
    public function delete(){ 
        $del_sql = 'delete from `'.$this->query_list['table'].'` where '.$this->query_list['where']; 
         
        if(isset($this->query_list['order'])) 
            $del_sql .= 'order by '.$this->query_list['order']; 
        if(isset($this->query_list['limit'])) 
            $del_sql .= ' '.$this->query_list['limit']; 
             
        return $this->execute($del_sql); 
         
    } 
    /**
+------------------------------------------------- ----------
* Update
+------------------------------------------------- ----------
* @access public
+------------------------------------------------- ----------
* @param
+------------------------------------------------- ----------
​​*/ 
    public function update(){ 
        $update_sql = 'update `'.$this->query_list['table'].'` set '; 
        $data = $this->query_list['data']; 
         
        foreach($data as $k=>$v){ 
            if(is_numeric($v)) 
                $update_sql .= '`'.$k.'` ='.$v.','; 
            else 
                $update_sql .= '`'.$k.'` =''.$v.'','; 
        } 
        $update_sql = rtrim($update_sql,','); 
        if(isset($this->query_list['where'])) 
            $update_sql .= ' where '.$this->query_list['where']; 
        if(isset($this->query_list['order'])) 
            $update_sql .= ' order by '.$this->query_list['order']; 
        if(isset($this->query_list['limit'])) 
            $update_sql .= ' '.$this->query_list['limit']; 
         
        return $this->execute($update_sql); 
         
    } 
     /**
     +----------------------------------------------------------
* Execute the query and return the data set
+------------------------------------------------- ----------
* @access public
+------------------------------------------------- ----------
* @param string $sql sql command
*/
Public function query($sql) {
If ( !$this->conn ) return false;
           $this->queryStr = $sql;
//Release the previous query results
If ( $this->queryID ) { $this->free(); }
                                   
           $this->query_start_time = microtime(true);
                                   
           $this->queryID = mysql_query($sql, $this->conn);
$this->query_count++;
If ( false === $this->queryID ) {
$this->error();
             return false;
         } else {
$this->numRows = mysql_num_rows($this->queryID);
              return $this->getAll();
         } 
}  
/**
+------------------------------------------------- ----------
* Execution statement
+------------------------------------------------- ----------
* @access public
+------------------------------------------------- ----------
* @param string $sql sql command
+------------------------------------------------- ----------
​​*/
Public function execute($sql) {
If ( !$this->conn ) return false;
           $this->queryStr = $sql;
//Release the previous query results
If ( $this->queryID ) { $this->free(); }
                                   
           $this->query_start_time = microtime(true);
                                   
                $result =     mysql_query($sql, $this->conn);  
$this->query_count++;
If (false === $result) {
$this->error();
              return false;
         } else {
                   $this->numRows = mysql_affected_rows($this->conn);
              return $this->numRows;
         } 
}  
/**
+------------------------------------------------- ----------
* Get all query data
+------------------------------------------------- ----------
* @access private
+------------------------------------------------- ----------
* @return array
​​*/
Private function getAll() {
//Return the data set
         $result = array();
If($this->numRows >0) {
            while($row = mysql_fetch_assoc($this->queryID)){ 
                $result[]   =   $row; 
            } 
            mysql_data_seek($this->queryID,0); 
        } 
        return $result; 
    } 
    /**
+------------------------------------------------- ----------
* Get the field information of the data table
+------------------------------------------------- ----------
* @access public
+------------------------------------------------- ----------
​​*/ 
    public function getFields($tableName) { 
        $result =   $this->query('SHOW COLUMNS FROM `'.$tableName.'`'); 
        $info   =   array(); 
        if($result) { 
            foreach ($result as $key => $val) { 
                $info[$val['Field']] = array( 
                    'name'    => $val['Field'], 
                    'type'    => $val['Type'], 
                    'notnull' => (bool) ($val['Null'] === ''), // not null is empty, null is yes  
                    'default' => $val['Default'], 
                    'primary' => (strtolower($val['Key']) == 'pri'), 
                    'autoinc' => (strtolower($val['Extra']) == 'auto_increment'), 
                ); 
            } 
        } 
        return $info; 
    } 
    /**
+------------------------------------------------- ----------
* Get database table information
+------------------------------------------------- ----------
* @access public
+------------------------------------------------- ----------
​​*/ 
    public function getTables($dbName='') { 
        if(!empty($dbName)) { 
           $sql    = 'SHOW TABLES FROM '.$dbName; 
        }else{ 
           $sql    = 'SHOW TABLES '; 
        } 
        $result =   $this->query($sql); 
        $info   =   array(); 
        foreach ($result as $key => $val) { 
            $info[$key] = current($val); 
        } 
        return $info; 
    } 
 
    /**
     +----------------------------------------------------------
     * 最后次操作的ID
     +----------------------------------------------------------
     * @access public
     +----------------------------------------------------------
     * @param 
     +----------------------------------------------------------
     */ 
     public function last_insert_id(){ 
        return mysql_insert_id($this->conn); 
    } 
    /**
* Execute a
with result set count ​​*/ 
    public function count($sql){ 
        return $this->execute($sql); 
    } 
    /**
+------------------------------------------------- ----------
* Start transaction
+------------------------------------------------- ----------
* @access public
+------------------------------------------------- ----------
* @return void
+------------------------------------------------- ----------
​​*/ 
    public function startTrans() { 
        if ($this->transTimes == 0) { 
            mysql_query('START TRANSACTION', $this->conn); 
        } 
        $this->transTimes++; 
        return ; 
    } 
 
    /**
+------------------------------------------------- ----------
* Submit transaction
+------------------------------------------------- ----------
* @access public
+------------------------------------------------- ----------
* @return boolen
+------------------------------------------------- ----------
​​*/ 
    public function commit() 
    { 
        if ($this->transTimes > 0) { 
            $result = mysql_query('COMMIT', $this->conn); 
            $this->transTimes = 0; 
            if(!$result){ 
                throw new Exception($this->error()); 
            } 
        } 
        return true; 
    } 
 
    /**
+------------------------------------------------- ----------
* *Transaction rollback
+------------------------------------------------- ----------
* @access public
+------------------------------------------------- ----------
* @return boolen
+------------------------------------------------- ----------
​​*/ 
    public function rollback() 
    { 
        if ($this->transTimes > 0) { 
            $result = mysql_query('ROLLBACK', $this->conn); 
            $this->transTimes = 0; 
            if(!$result){ 
                throw new Exception($this->error()); 
            } 
        } 
        return true; 
    } 
    /**
+------------------------------------------------- ----------
* Error message
+------------------------------------------------- ----------
* @access public
+------------------------------------------------- ----------
* @param
+------------------------------------------------- ----------
​​*/ 
     public function error() { 
        $this->error = mysql_error($this->conn); 
        if('' != $this->queryStr){ 
            $this->error .= "n [ SQL语句 ] : ".$this->queryStr; 
        } 
        return $this->error; 
    } 
    /**
+------------------------------------------------- ----------
* Release query results
+------------------------------------------------- ----------
* @access public
+------------------------------------------------- ----------
​​*/ 
    public function free() { 
        @mysql_free_result($this->queryID); 
        $this->queryID = 0; 
        $this->query_list = null; 
    } 
    /**
+------------------------------------------------- ----------
*Close connection
+------------------------------------------------- ----------
* @access public
+------------------------------------------------- ----------
* @param
+------------------------------------------------- ----------
​​*/ 
    function close(){ 
        if ($this->conn && !mysql_close($this->conn)){ 
            throw new Exception($this->error()); 
        } 
        $this->conn = 0; 
        $this->query_count = 0; 
    } 
    /**
+------------------------------------------------- ----------
* Destruction method
+------------------------------------------------- ----------
* @access public
+------------------------------------------------- ----------
​​*/ 
    function __destruct(){ 
         $this->close(); 
    } 

// +-------------------------------------------------- -----------------------
// |MySQL operation class
// +-------------------------------------------------- -----------------------
// |@微梁QQ:496928838
// +-------------------------------------------------- -----------------------
class MySQL{

private $db_mysql_hostname;
private $db_mysql_username;
private $db_mysql_password;
private $db_mysql_database;
private $db_mysql_port;
private $db_mysql_charset;

private $query_list = array();

//Number of queries
public $query_count = 0;
//Query start time
public $query_start_time;

//Current query ID
protected $queryID;
//Current connection
protected $conn;
//Number of transaction instructions
protected $transTimes = 0;
//Return or affect the number of records
protected $numRows = 0;
// Error message
protected $error = '';

public function __construct($hostname_or_conf,$username,$password,$database,$port = '3306',$char = 'utf8'){
if(is_array($hostname_or_conf)){
$this->db_mysql_hostname = $hostname_or_conf['hostname'];
$this->db_mysql_username = $hostname_or_conf['username'];
$this->db_mysql_password = $hostname_or_conf['password'];
$this->db_mysql_database = $hostname_or_conf['database'];
$this->db_mysql_port = isset($hostname_or_conf['port'])?$hostname_or_conf['port']:'3306';
$this->db_mysql_charset = isset($hostname_or_conf['charset'])?$hostname_or_conf['charset']:'utf8';
 
}elseif(!empty($hostname_or_conf)||!empty($username)||!empty($password)||!empty($database))
{
$this->db_mysql_hostname = $hostname_or_conf;
$this->db_mysql_username = $username;
$this->db_mysql_password = $password;
$this->db_mysql_database = $database;
$this->db_mysql_port = $port;
$this->db_mysql_charset = $char;
 
}else{
Die('configuration error.');
}
$this->connect();
}

private function connect(){
$server = $this->db_mysql_hostname.':'.$this->db_mysql_port;
$this->conn = mysql_connect($server,$this->db_mysql_username,$this->db_mysql_password,true) or die('Connect MySQL DB error!');
mysql_select_db($this->db_mysql_database,$this->conn) or die('select db error!');
mysql_query("set names " . $this->db_mysql_charset, $this->conn);
}
/**
+------------------------------------------------- ----------
* Set data object value
+------------------------------------------------- ----------
* @access public
+------------------------------------------------- ----------
*table,where,order,limit,data,field,join,group,having
+------------------------------------------------- ----------
​​*/
public function table($table){
$this->query_list['table'] = $table;
return $this;
}

public function where($where){
$this->query_list['where'] = $where;
return $this;
}

public function order($order){
$this->query_list['order'] = $order;
return $this;
}

public function limit($offset,$length){
if(!isset($length)){
$length = $offset;
$offset = 0;
}
$this->query_list['limit'] = 'limit '.$offset.','.$length;
return $this;
}

 public function data($data){
  //读取数据表字段,然后处理表单数据
  $dataList = $this->getFields($this->query_list['table']);
  $arr=array();
  foreach ($dataList as $key=>$value) {
   if (array_key_exists ($key,$data) ) {
    $arr[$key]=$data[$key];
   }
   
  }
  //var_dump($arr);
  /*
  if(is_object($data)){
   $data   =   get_object_vars($data);
  }elseif (is_string($data)){
   parse_str($data,$data);
  }elseif(!is_array($data)){
   //Log:DATA_TYPE_INVALID
  }
  */
  $this->query_list['data'] = $arr;
  return $this;
 }
 public function field($fields){
  $this->query_list['fields'] = $fields;
  return $this;
 }
 public function join($join){
  $this->query_list['join'] = $join;
  return $this;
 }
 public function group($group){
  $this->query_list['group'] = $group;
  return $this;
 }
 public function having($having){
  $this->query_list['having'] = $having;
  return $this;
 }
 /**
+------------------------------------------------- ----------
* Query
+------------------------------------------------- ----------
* @access public
+------------------------------------------------- ----------
* @param
+------------------------------------------------- ----------
​​*/
 public function select(){
  $select_sql = 'select ';
  $fields = isset($this->query_list['fields'])?$this->query_list['fields']:'*';
  $select_sql.=$fields;
  $select_sql.= ' from `'.$this->query_list['table'].'` ';
  
  isset($this->query_list['join'])?($select_sql.=$this->query_list['join']):'';
  isset($this->query_list['where'])?($select_sql.=' where '.$this->query_list['where']):'';
  isset($this->query_list['group'])?($select_sql.=' group by'.$this->query_list['group']):'';
  isset($this->query_list['having'])?($select_sql.=' mysql having '.$this->query_list['having']):'';
  isset($this->query_list['order'])?($select_sql.=' order by '.$this->query_list['order']):'';
  isset($this->query_list['limit'])?($select_sql.=' '.$this->query_list['limit']):'';
  
  return $this->query($select_sql);
 }
 /**
+------------------------------------------------- ----------
* Add
+------------------------------------------------- ----------
* @access public
+------------------------------------------------- ----------
* @param
+------------------------------------------------- ----------
​​*/
 public function add(){
  $add_sql = 'insert into `'.$this->query_list['table'].'` (';
  
  $data = $this->query_list['data'];
  $value = $field = '';
  foreach($data as $k=>$v){
   $field .= '`'.$k.'`,';
   if(is_numeric($v))
    $value .= $v.',';
   else
    $value .= '''.$v.'',';
  }
  $add_sql .= rtrim($field,',').') values ('.rtrim($value,',').')';

 // echo 'add_sql'.$add_sql;
  return $this->execute($add_sql);
 }
 /**
+------------------------------------------------- ----------
* Delete
+------------------------------------------------- ----------
* @access public
+------------------------------------------------- ----------
* @param
+------------------------------------------------- ----------
​​*/
 public function delete(){
  $del_sql = 'delete from `'.$this->query_list['table'].'` where '.$this->query_list['where'];
  
  if(isset($this->query_list['order']))
   $del_sql .= 'order by '.$this->query_list['order'];
  if(isset($this->query_list['limit']))
   $del_sql .= ' '.$this->query_list['limit'];
   
  return $this->execute($del_sql);
  
 }
 /**
+------------------------------------------------- ----------
* Update
+------------------------------------------------- ----------
* @access public
+------------------------------------------------- ----------
* @param
+------------------------------------------------- ----------
​​*/
 public function update(){
  $update_sql = 'update `'.$this->query_list['table'].'` set ';
  $data = $this->query_list['data'];
  
  foreach($data as $k=>$v){
   if(is_numeric($v))
    $update_sql .= '`'.$k.'` ='.$v.',';
   else
    $update_sql .= '`'.$k.'` =''.$v.'',';
  }
  $update_sql = rtrim($update_sql,',');
  if(isset($this->query_list['where']))
   $update_sql .= ' where '.$this->query_list['where'];
  if(isset($this->query_list['order']))
   $update_sql .= ' order by '.$this->query_list['order'];
  if(isset($this->query_list['limit']))
   $update_sql .= ' '.$this->query_list['limit'];
  
  return $this->execute($update_sql);
  
 }
  /**
+------------------------------------------------- ----------
* Execute the query and return the data set
+------------------------------------------------- ----------
* @access public
+------------------------------------------------- ----------
* @param string $sql sql command
​​*/
    public function query($sql) {
        if ( !$this->conn ) return false;
        $this->queryStr = $sql;
        //释放前次的查询结果
        if ( $this->queryID ) {    $this->free();    }
       
        $this->query_start_time = microtime(true);
       
        $this->queryID = mysql_query($sql, $this->conn);
        $this->query_count++;
        if ( false === $this->queryID ) {
            $this->error();
            return false;
        } else {
            $this->numRows = mysql_num_rows($this->queryID);
            return $this->getAll();
        }
    }
 /**
+------------------------------------------------- ----------
* Execution statement
+------------------------------------------------- ----------
* @access public
+------------------------------------------------- ----------
* @param string $sql sql command
+------------------------------------------------- ----------
​​*/
    public function execute($sql) {
        if ( !$this->conn ) return false;
        $this->queryStr = $sql;
        //释放前次的查询结果
        if ( $this->queryID ) {    $this->free();    }
       
        $this->query_start_time = microtime(true);
       
        $result =   mysql_query($sql, $this->conn) ;
        $this->query_count++;
        if ( false === $result) {
            $this->error();
            return false;
        } else {
            $this->numRows = mysql_affected_rows($this->conn);
            return $this->numRows;
        }
    }
 /**
+------------------------------------------------- ----------
* Get all query data
+------------------------------------------------- ----------
* @access private
+------------------------------------------------- ----------
* @return array
​​*/
    private function getAll() {
        //返回数据集
        $result = array();
        if($this->numRows &g

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
php怎么把负数转为正整数php怎么把负数转为正整数Apr 19, 2022 pm 08:59 PM

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

php怎么实现几秒后执行一个函数php怎么实现几秒后执行一个函数Apr 24, 2022 pm 01:12 PM

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php怎么除以100保留两位小数php怎么除以100保留两位小数Apr 22, 2022 pm 06:23 PM

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

php字符串有没有下标php字符串有没有下标Apr 24, 2022 am 11:49 AM

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

php怎么根据年月日判断是一年的第几天php怎么根据年月日判断是一年的第几天Apr 22, 2022 pm 05:02 PM

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

php怎么读取字符串后几个字符php怎么读取字符串后几个字符Apr 22, 2022 pm 08:31 PM

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

php怎么替换nbsp空格符php怎么替换nbsp空格符Apr 24, 2022 pm 02:55 PM

方法:1、用“str_replace("&nbsp;","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\&nbsp\;||\xc2\xa0)/","其他字符",$str)”语句。

php怎么查找字符串是第几位php怎么查找字符串是第几位Apr 22, 2022 pm 06:48 PM

查找方法:1、用strpos(),语法“strpos("字符串值","查找子串")+1”;2、用stripos(),语法“strpos("字符串值","查找子串")+1”。因为字符串是从0开始计数的,因此两个函数获取的位置需要进行加1处理。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.