Home Backend Development PHP Tutorial The third day of php practical combat_PHP tutorial

The third day of php practical combat_PHP tutorial

Jul 14, 2016 am 10:10 AM
jquery php Revise content Actual combat layout Compare special effects of



I made a new layout and it feels more comfortable than before.

The special effects of jquery have also been modified. Move to the content area and change the color of the text to a beautiful blue. Remove it.


[javascript] // JavaScript Document
$(document).ready(function(e) {
$user=$("div .user");
$text=$("div .text");
       
$("div .content").each(function(index){
         $(this).mousemove(function(){
                                                                  $user.eq(index).css("color","#0A8CD2");

// $user.eq(index).css("background","#FFE6AD");
// $text.eq(index).css("background","#FFFDF6");
                                                                  }).mouseout(function(){
                                                                  $user.eq(index).css("color","#000");

// $user.eq(index).css("background","#E6F0F9");
// $text.eq(index).css("background","#F8FBFD");
        });
});

       
});

// JavaScript Document
$(document).ready(function(e) {

$user=$("div .user");

$text=$("div .text");

$("div .content").each(function(index){
$(this).mousemove(function(){

$user.eq(index).css("color","#0A8CD2");

// $user.eq(index).css("background","#FFE6AD");
// $text.eq(index).css("background","#FFFDF6");

}).mouseout(function(){

$user.eq(index).css("color","#000");

// $user.eq(index).css("background","#E6F0F9");
// $text.eq(index).css("background","#F8FBFD");

});

});


});

A time field has been added to the database, with type int and length 11;

When adding a message, call the time() function to return the ux timestamp,

When reading from the database, call the date() function

[php] date('Y-m-d H:i:s',$value['time']);//Convert timestamp to date

date('Y-m-d H:i:s',$value['time']);//Convert timestamp to date
Then also added a paging code


[php] function index() {

Include "page.class.php";
                                                                    $rows = $this->db->count('select * from data');

$page = new Page($rows, 5, "");

$page -> set("head", "Message");
$page -> set("first", "Homepage")
-> set("prev", "previous page")
-> set("next", "next page")
-> set("last", "last page");

$list=$this->db
->order('id DESC')
->limit($page->getLimit())
->select();
       
$this->assign("page",$page->fpage(0,3,4,5,6));
$this->assign("list",$list);
$this->assign("title", "My Message Board"); //Assign the title variable to the header template header.tpl
       

$this->display(); //Including replacing the variables in the template and outputting the template page
}

function index() {

include "page.class.php";

       
$rows = $this->db->count('select * from data');

$page = new Page($rows, 5, "");


$page -> set("head", "Message");
$page -> set("first", "Homepage")
-> set("prev", "previous page")
-> set("next", "next page")
-> set("last", "last page");

$list=$this->db
->order('id DESC')
->limit($page->getLimit())
->select();
 
$this->assign("page",$page->fpage(0,3,4,5,6));
$this->assign("list",$list);
$this->assign("title", "My Message Board"); //Assign the title variable to the header template header.tpl
 

$this->display(); //Including replacing the variables in the template and outputting the template page
}
The effect is pretty good.

page.class.php source code is attached

[php] /**
File: page.class.php
​​​​Perfect paging type Page
@Qq496928838
​*/
Class Page {
private $total; private $listRows; Private $ Limit; // SQL statement uses limit clauses to limit the number of records
private $uri; //Automatically obtain the request address of the url
private $pageNum; private $page;         private $config = array(
'head' => "record",
'prev' => "Previous page",
'next' => "Next page",
'first'=> "Home",
'last' => "Last page"
                                        ); Private $ listnum = 10; // The number of default layout lists

/**
​​​​​​Construction method, you can set the properties of the paging class
                                                                                                  use   use   with   using                     ’ s ’ s ’ s ’ s ’ s ‐ ‐ ‐ ‐ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​                                                                                                                                                                                                                                                   ’ s ’ s ’ s ’ s ’ s ’ ’ to ’to 1-- @Param Mixed $ Query can choose parameters to the target page, which can be an array or query string format
@param bool $ord Optional, the default value is true, the page will be displayed from the first page, false will be the last page
                     */
        public function __construct($total, $listRows=25, $query="", $ord=true){
$this->total = $total;
            $this->listRows = $listRows; 
            $this->uri = $this->getUri($query); 
            $this->pageNum = ceil($this->total / $this->listRows); 
            /*以下判断用来设置当前面*/ 
            if(!empty($_GET["page"])) { 
                $page = $_GET["page"]; 
            }else{ 
                if($ord) 
                    $page = 1; 
                else 
                    $page = $this->pageNum; 
            } 
 
            if($total > 0) { 
                if(preg_match('/D/', $page) ){ 
                    $this->page = 1; 
                }else{ 
                    $this->page = $page; 
                } 
            }else{ 
                $this->page = 0; 
            } 
             
            $this->limit = "LIMIT ".$this->getLimit(); 
        } 
 
        /**
For the information for setting the paging, you can perform coherent operations
@param string $param is the subscript of the member attribute array config
@param string $value is used to set the element value corresponding to the config subscript
               @return object                                                                                                                                                                                                                                                                       out out out of the blue can be used as a reference.                      */ 
        function set($param, $value){ 
            if(array_key_exists($param, $this->config)){ 
                $this->config[$param] = $value; 
            } 
            return $this; 
        } 
         
        /* 不是直接去调用,通过该方法,可以使用在对象外部直接获取私有成员属性limit和page的值 */ 
        function __get($args){ 
            if($args == "limit" || $args == "page") 
                return $this->$args; 
            else 
                return null; 
        } 
         
        /**
            按指定的格式输出分页
            @param  int 0-7的数字分别作为参数,用于自定义输出分页结构和调整结构的顺序,默认输出全部结构
            @return string  分页信息内容
         */ 
        function fpage(){ 
            $arr = func_get_args(); 
 
            $html[0] = " 共 {$this->total} {$this->config["head"]} "; 
            $html[1] = " 本页 ".$this->disnum()." 条 "; 
            $html[2] = " 本页从 {$this->start()}-{$this->end()} 条 "; 
            $html[3] = " {$this->page}/{$this->pageNum}页 "; 
            $html[4] = $this->firstprev(); 
            $html[5] = $this->pageList(); 
            $html[6] = $this->nextlast(); 
            $html[7] = $this->goPage(); 
 
            $fpage = '

'; 
            if(count($arr) < 1)
$arr = array(0, 1,2,3,4,5,6,7);

for($i = 0; $i < count($arr); $i++)
$fpage .= $html[$arr[$i]];

$fpage .= '
';
                return $fpage;
         } 
                                   
​ ​ ​ /* The format is 1,5,*/
function getLimit(){
If($this->page > 0)
                    return ($this->page-1)*$this->listRows.", {$this->listRows}";
                                                                                    else Return 0;
         } 

              /* Private method used inside the object to automatically obtain the current URL visited */
         private function getUri($query){                                                         $request_uri = $_SERVER["REQUEST_URI"];
$url = strstr($request_uri,'?') ? $request_uri : $request_uri.'?';
                                                                 If(is_array($query))
                        $url .= http_build_query($query);
               else if($query != "")
                     $url .= "&".trim($query, "?&");
                                   
                $arr = parse_url($url);

If(isset($arr["query"])){
                    parse_str($arr["query"], $arrs);
                   unset($arrs["page"]);
$url = $arr["path"].'?'.http_build_query($arrs);
                                                                                                                                                                                                       If(strstr($url, '?')) {
If(substr($url, -1)!='?')
$url = $url.'&';
              }else{
$url = $url.'?';
                                                                                                                                                                                                                      return $url;
         } 

                 /* Private method used inside the object to get the number of records at the beginning of the current page */
        private function start(){
If($this->total == 0)
Return 0;
                                                                                    else                    return ($this->page-1) * $this->listRows+1;
         } 

              /* Private method used inside the object to get the number of records at the end of the current page */
        private function end(){
                return min($this->page * $this->listRows, $this->total);
         } 

                               /* Private method used inside the object to obtain the operation information of the previous page and home page */
         private function firstprev(){
If($this->page > 1) {
                      $str = " {$this->config["first"]} ";
$str .= "{$this->config["prev"] } "; 
                                   return $str;                                                                                                                                                             
         } 
       
               /* Private method used inside the object to obtain page list information */
         private function pageList(){
               $linkPage = " ";
                                                                                   $inum = floor($this->listNum/2);
                                                                                                   /*List in front of the current page */ 
for($i = $inum; $i >= 1; $i--){
$page = $this->page-$i;

If($page >= 1)
                                    $linkPage .= "{$page} ";
                                                                                                                                                                 /*Information of the current page */ 
If($this->pageNum > 1)
                      $linkPage .= "{$this->page} ";
                                                                                                                                                                                                                                                                                                                                                    /*List behind the current page */ 
for($i=1; $i <= $inum; $i++){
$page = $this->page+$i;
If($page <= $this->pageNum)
                                    $linkPage .= "{$page} ";
              else break;
                                                                                                                                      $linkPage .= '
';
               return $linkPage;
         } 

              /* Private method used inside the object to obtain the operation information of the next page and the last page */
private function nextlast(){
If($this->page != $this->pageNum) {
$str = " {$this->config["next"]} ";
$str .= " {$this->config["last"]}< ;/a> ";
                             return $str;                                                                                                                                                                         } 

/ * Private method used inside the object, used to display and process form jump pages * /
        private function goPage(){
If($this->pageNum > 1) {
return ' ';
                                                                                                                                               } 

/* Private method used inside the object to obtain the number of records displayed on this page */
         private function disnum(){
If($this->total > 0){
Return $this->end()-$this->start()+1;
              }else{
Return 0;
                                                                                                                                               } 
}  

       
       
       

/**
file: page.class.php

Perfect paging type Page

@微 Cool QQ496928838
​*/
class Page {
private $total; //Total number of records in the data table
private $listRows; //Display number of rows per page
private $limit; //SQL statement uses limit clause to limit the number of records obtained
private $uri; //Automatically obtain the request address of the url
private $pageNum; //Total number of pages
private $page; //Current page
private $config = array(
        'head' => "record",
        'prev' => "Previous page",
'next' => "Next page",
        'first'=> "Home",
        'last' => "Last page"
);        // Display content in paging information, you can set it yourself through the set() method
private $listNum = 10; //The number of items displayed in the default paging list

  /**
   构造方法,可以设置分页类的属性
   @param int $total  计算分页的总记录数
   @param int $listRows 可选的,设置每页需要显示的记录数,默认为25条
   @param mixed $query 可选的,为向目标页面传递参数,可以是数组,也可以是查询字符串格式
   @param  bool $ord 可选的,默认值为true, 页面从第一页开始显示,false则为最后一页
   */
  public function __construct($total, $listRows=25, $query="", $ord=true){
   $this->total = $total;
   $this->listRows = $listRows;
   $this->uri = $this->getUri($query);
   $this->pageNum = ceil($this->total / $this->listRows);
   /*以下判断用来设置当前面*/
   if(!empty($_GET["page"])) {
    $page = $_GET["page"];
   }else{
    if($ord)
     $page = 1;
    else
     $page = $this->pageNum;
   }

   if($total > 0) {
    if(preg_match('/\D/', $page) ){
     $this->page = 1;
    }else{
     $this->page = $page;
    }
   }else{
    $this->page = 0;
   }
   
   $this->limit = "LIMIT ".$this->getLimit();
  }

  /**
   用于设置显示分页的信息,可以进行连贯操作
   @param string $param 是成员属性数组config的下标
   @param string $value 用于设置config下标对应的元素值
   @return object   返回本对象自己$this, 用于连惯操作
   */
  function set($param, $value){
   if(array_key_exists($param, $this->config)){
    $this->config[$param] = $value;
   }
   return $this;
  }
  
  /* 不是直接去调用,通过该方法,可以使用在对象外部直接获取私有成员属性limit和page的值 */
  function __get($args){
   if($args == "limit" || $args == "page")
    return $this->$args;
   else
    return null;
  }
  
  /**
   按指定的格式输出分页
   @param int 0-7的数字分别作为参数,用于自定义输出分页结构和调整结构的顺序,默认输出全部结构
   @return string 分页信息内容
   */
  function fpage(){
   $arr = func_get_args();

   $html[0] = " 共 {$this->total} {$this->config["head"]} ";
   $html[1] = " 本页 ".$this->disnum()." 条 ";
   $html[2] = " 本页从 {$this->start()}-{$this->end()} 条 ";
   $html[3] = " {$this->page}/{$this->pageNum}页 ";
   $html[4] = $this->firstprev();
   $html[5] = $this->pageList();
   $html[6] = $this->nextlast();
   $html[7] = $this->goPage();

   $fpage = '

';
   if(count($arr) < 1)
$arr = array(0, 1,2,3,4,5,6,7);

for($i = 0; $i < count($arr); $i++)
$fpage .= $html[$arr[$i]];

$fpage .= '
';
Return $fpage;
}

/* The format is 1,5,*/
function getLimit(){
If($this->page > 0)
Return ($this->page-1)*$this->listRows.", {$this->listRows}";
else
Return 0;
}

/* Private method used inside the object to automatically obtain the current URL visited */
private function getUri($query){
$request_uri = $_SERVER["REQUEST_URI"];
$url = strstr($request_uri,'?') ? $request_uri : $request_uri.'?';
 
If(is_array($query))
$url .= http_build_query($query);
else if($query != "")
$url .= "&".trim($query, "?&");

$arr = parse_url($url);

if(isset($arr["query"])){
Parse_str($arr["query"], $arrs);
​​unset($arrs["page"]);
$url = $arr["path"].'?'.http_build_query($arrs);
}
 
if(strstr($url, '?')) {
If(substr($url, -1)!='?')
$url = $url.'&';
}else{
$url = $url.'?';
}
 
Return $url;
}

/* Private method used inside the object to obtain the number of records at the beginning of the current page */
private function start(){
if($this->total == 0)
Return 0;
else
Return ($this->page-1) * $this->listRows+1;
}

/* Private method used inside the object to obtain the number of records at the end of the current page */
private function end(){
Return min($this->page * $this->listRows, $this->total);
}

/* Private method used inside the object to obtain operation information of the previous page and home page */
private function firstprev(){
if($this->page > 1) {
$str = "
{$this->config["first"]} ";
$str .= "{$this->config["prev"] } ";
Return $str;
}

}

/* Private method used inside the object to obtain page list information */
private function pageList(){
$linkPage = " ";
 
$inum = floor($this->listNum/2);
/*List in front of current page */
for($i = $inum; $i >= 1; $i--){
$page = $this->page-$i;

if($page >= 1)
$linkPage .= "{$page} ";
}
/*Information of the current page */
if($this->pageNum > 1)
$linkPage .= "{$this->page} ";
 
/*List behind the current page */
for($i=1; $i <= $inum; $i++){
$page = $this->page+$i;
If($page <= $this->pageNum)
$linkPage .= "{$page} ";
else
Break;
}
$linkPage .= '
';
Return $linkPage;
}

/* Private method used inside the object to obtain the operation information of the next page and the last page */
private function nextlast(){
if($this->page != $this->pageNum) {
$str = " {$this->config["next"]} ";
$str .= " {$this->config["last"]}< ;/a> ";
Return $str;
}
}

/* Private method used inside the object to display and process form jump pages */
private function goPage(){
If($this->pageNum > 1) {
return ' ';
}
}

/* Private method used inside the object to obtain the number of records displayed on this page */
private function disnum(){
if($this->total > 0){
Return $this->end()-$this->start()+1;
}else{
Return 0;
}
}
}




This is a very powerful paging class. Although it looks a bit ugly, it can be modified

As for mysql.class.php, I modified the limit method so that it can support one parameter and two parameters, which is more convenient to operate


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

public function limit($offset,$length=null){

if (is_null($length)) {
$this->query_list['limit']='limit '.$offset;
Return $this;
}else {
if(!isset($length)){
$length = $offset;
$offset = 0;
}
$this->query_list['limit'] = 'limit '.$offset.','.$length;
Return $this;
}

Also learned to set the time zone.

[php] date_default_timezone_set("PRC"); //Set time zone (China

date_default_timezone_set("PRC"); //Set time zone (China

Modified the mytpl.class.php template engine so that it will not cause overflow


[php] /**
File: mytpl.class.php The class name is MyTpl, which is a custom template engine
Load the template file through this class object and parse it, and output the parsed result
@Qq496928838
​*/
class MyTpl {
Public $template_dir = 'view'; //Define the directory where template files are stored
Public $compile_dir = 'view_c'; //Define the file storage directory after combining through the template engine
Public $left_delimiter = '<{'; // Embed the left delimiter symbol of dynamic data variables in the template
Public $right_delimiter = '}>'; //Embed the right delimiter of dynamic data variables in the template
          private $tpl_vars = array();                                                                                                                                                                                                                                                                                                                      
/**
The values ​​assigned in PHP will be saved to the member attribute $tpl_vars, which is used to replace the corresponding variables in the board
@Param String $ TPL_VAR requires a string parameter as a associated array. It should correspond to the variable name in the template
​​​​​​​​@param​​mixed​​$value​​​Requires a scalar type value to be assigned to the value of the variable in the template​​​ ​​​​*/
function assign($tpl_var, $value = null) {
If ($tpl_var != ''){
                   $GLOBALS[$tpl_var] = $value;
$this->tpl_vars[$tpl_var] = $value;
                                                                                                                                                                                                                   


         } 
                                   
/**
Load the template file in the specified directory, and store the replaced content to generate the combined file in another specified directory
@param string $fileName Provides the file name of the template file ​​​​*/
function display($fileName) {
                                              /* Search for template files in the specified directory */
$tplFile = $this->template_dir.'/'.$fileName;
/* If the template file to be processed does not exist, exit and report an error */
                if(!file_exists($tplFile)) {                                                         die("Template file {$tplFile} does not exist!");
                                                                                                                                                        /* Get the combined template file, the contents in this file have been replaced */
                 $fileNameMd5 = md5($fileName);

                $comFileName = $this->compile_dir."/com_".$fileNameMd5.'.php';                                              / * Determine whether the file after replacement exists or exists but has changed, you need to re -create * /
If(!file_exists($comFileName) || filemtime($comFileName) < filemtime($tplFile)) {
                                     /* Call the internal replacement template method */
                   $repContent = $this->tpl_replace(file_get_contents($tplFile)); / * Save the script file after the system combination * /
                     file_put_contents($comFileName, $repContent);
                                                                                                                                      /* Contains the processed template file and outputs it to the client */
              include($comFileName);                                    } 
                                   
/**
​​​​​​​A private method used internally, using regular expressions to replace the statements in the template file '<{ }>' with the corresponding values ​​or PHP code
@param string $content Provides the entire content string read from the template file
@Return $ repcontent Return to replacement string
​​​​*/
         private function tpl_replace($content) {
                                      /* Escape the special symbols that have regular effects among the left and right delimiter symbols. For example, <{ }>Escape<{ }> */
                 $left = preg_quote($this->left_delimiter, '/');
                 $right = preg_quote($this->right_delimiter, '/');

/* Pattern array of regular expressions matching various identifiers in the template */
             $pattern = array(                                       / * Matching variables in the template, for example, "& lt; {$ var} & gt;" * /
               '/'.$left.'s*$([a-zA-Z_x7f-xff][a-zA-Z0-9_x7f-xff]*)s*'.$right.'/i',                             / * The IF identifier in the matching template, such as "& lt; {if $ color ==" sex "} & gt; & lt; { /if} & gt;" * /
'/'.$left.'s*ifs*(.+?)s*'.$right.'(.+?)'.$left.'s*/ifs*'.$right.'/ies' ,
/ * Match the elseif identifier, such as "& lt; {elseif $ color ==" sex "} & gt;" * /
'/'.$left.'s*elses*ifs*(.+?)s*'.$right.'/ies',
/ * Match the ELSE identifier, such as "& lt; {else} & gt;" * /
‘/’.$left.’s*elses*’.$right.’/is’, 
                        /* Used to match the loop identifier in the template, used to traverse the values ​​in the array, for example "<{ loop $arrs $value }> <{ /loop}>" */
'/'.$left.'s*loops+$(S+)s+$([a-zA-Z_x7f-xff][a-zA-Z0-9_x7f-xff]*)s*'.$right.'(. +?)'.$left.'s*/loops*'.$right.'/is',
/ * Used to traverse the keys and values ​​in the array, such as "& lt; {loop $ arrs $ key = & gt; $ value} & gt; & lt; { /loop} & gt;" * /
'/'.$left.'s*loops+$(S+)s+$([a-zA-Z_x7f-xff][a-zA-Z0-9_x7f-xff]*)s*=>s*$(S+ )s*'.$right.'(.+?)'.$left.'s*/loop s*'.$right.'/is',
/ * Match the include identifier, for example, '& lt; {include "header.html"} & gt;' * /
                                                                                                                                 " );
                                                                                                /* Replace the string array matched from the template using regular expressions */
$replacement = array(
/ * Replace the variables in the template & lt ;? PHP Echo $ this-& gt; tpl_vars ["var"]; * /
                  'tpl_vars["${1}"]; ?>',                                              /* Replace the if string in the template */
'$this->stripvtags('','${2}')',                                                                                                 / * Replace the string of elseif & lt;? PHP} elseif ($ color == "sex") {? & Gt; * /
‘$this->stripvtags('',"")',
/* Replace else string                    '',                                                          /* The following two items are used to replace the loop identifier in the template with the foreach format */
'tpl_vars["${1}"] as $this->tpl_vars["${2}"]) { ?>${3}', 
'tpl_vars["${1}"] as $this->tpl_vars["${2}"] => $this->tpl_vars["${3 }"]) { ?>${4}', 
/*Replace the include string*/
               'file_get_contents($this->template_dir."/'.$GLOBALS['className'].'/${1}")'
                                                                                );
                                                                                                     /* Use regular replacement function to process */
                $s_content=$content;

               $repContent = preg_replace($pattern, $replacement, $content);                                                                                                                          /* If there are still identifiers to be replaced, recursively call yourself to replace them again */
If(preg_match('/'.$left.'([^('.$right.')]{1,})'.$right.'/', $repContent)) {                             If($s_content==$content) {
                               $repContent = $this->tpl_replace($repContent);
                                                                                                                                                                                                                                                                           /* Return the replaced string */

return $repContent;          } 
                                                                  /**
The private method used inside is used to replace the variable used in the conditional statement to the corresponding value
@Param String $ Expr provided the start marking of conditional statements in the template
                             

Statement of this Website
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

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 Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

7 PHP Functions I Regret I Didn't Know Before 7 PHP Functions I Regret I Didn't Know Before Nov 13, 2024 am 09:42 AM

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

See all articles