function DateAdd($date, $int, $unit = "d") { //Increase of time (can also be improved to hours, minutes and seconds) You can increase it and make it up when you have time) $dateArr = explode("-", $date); $value[$unit] = $int; return date("Y-m-d", mktime(0,0,0, $dateArr[1] + $value['m'], $dateArr[2] + $value['d'], $dateArr[0] + $value['y'])); } function GetWeekDay( $date) { //Calculate the day of the week for the given date $dateArr = explode("-", $date); return date("w", mktime(0,0,0,$dateArr[1] ,$dateArr[2],$dateArr[0])); } ?> Detailed source reference: http://www.jb51.net/article/22199.htm
function check_date( $date) { //Check whether the date is a legal date $dateArr = explode("-", $date); if (is_numeric($dateArr[0]) && is_numeric($dateArr[1]) && is_numeric($dateArr [2])) { return checkdate($dateArr[1],$dateArr[2],$dateArr[0]); } return false; } function check_time($time) { //Check whether the time is Legal time $timeArr = explode(":", $time); if (is_numeric($timeArr[0]) && is_numeric($timeArr[1]) && is_numeric($timeArr[2])) { if ( ($timeArr[0] >= 0 && $timeArr[0] <= 23) && ($timeArr[1] >= 0 && $timeArr[1] <= 59) && ($timeArr[2] >= 0 && $timeArr[2] <= 59)) return true; else return false; } return false; } Detailed source reference: http://www.jb51.net/article /22199.htm
function DateDiff($date1, $date2, $unit = "") { //Time comparison function, returns the number of seconds, minutes, hours or days between two dates switch ($unit ) { case 's': $dividend = 1; break; case 'i': $dividend = 60; break; case 'h': $dividend = 3600; break; case ' d': $dividend = 86400; break; default: $dividend = 86400; } $time1 = strtotime($date1); $time2 = strtotime($date2); if ($time1 && $ time2) return (float)($time1 - $time2) / $dividend; return false; } ?> Detailed source reference: http://www.jb51.net/article/22199.htm
Time comparison issue Give a simple example: For example, a forum uses a new image to mark the posts published on that day. Method 1: Copy the code as follows:
//$db->rows[$i][date] is the datetime field value in the database. $today=time(); $theDay= date("Y-m-d H:i:s",$today-24*3600); $newTag=$db->rows[$i][date]>=$theDay?"":""; //Method 2: $newTag=$db->rows[$i][date]>=date("Y-m-d 00:00:00 ")?"":""; ?>
Copy the code as follows: //Extract the variables submitted by the page and browser, the function Equivalent to opening global variables in PHP.INI
Copy the code as follows: //Quick page redirection
function turntopage($url="index.php",$ info = "The page is redirecting...",$second=2){ print "nnThe page is redirecting....n"; print " n"; print "n"; print "nn"; print "
Copy the code as follows: //Convert each row and column of the HTML table into an array and collect table data < ? function get_td_array($table) { $table = preg_replace("'
//Get the content in the specified tag function get_tag_data($str, $start, $end){ If ( $ start == '' || $end == '' ){ return $str[0]; } //Convert each row of the HTML table to a CSV format array function get_tr_array($table) { $table = preg_replace("'
]*?> 'si",'"',$table); $table = str_replace("
",'",',$table); $table = str_replace(""," {tr} ", $ table); // Remove the html mark
//Convert each row and column of the HTML table into an array and collect table data function get_td_array($table) { ;'si","",$table); $table = preg_replace("'
//Static page generation function function phptohtm($filefrom,$fileto,$u2u=1){ if($u2u==1){ $data=PHP_Read($ filefrom); }else{ $data=$filefrom; } PHP_Write($fileto,$data); return true; } ?>
Specify condition information quantity retrieval function
//Specify condition information quantity retrieval function function rec_exist($table,$where){ $query="select count(*) as num from $table ".$where; $result=mysql_query ($query) or die(nerror(1)); $rowcount=mysql_fetch_array($result); $num=$rowcount["num"]; if ($num==0){ return false; } Return $num; } ?>
Directory deletion function
//Directory deletion function function del_DIR($directory){ $mydir=dir($directory) ; while($file=$mydir->read()){ if((is_dir("$directory/$file")) AND ($file!=".") AND ($file!=".." )){ del_DIR("$directory/$file"); }else{ if(($file!=".") AND ($file!="..")){ unlink("$directory /$file"); //echo "unlink $directory/$file ok "; } } }
$mydir->close(); rmdir($directory); //echo " rmdir $directory ok "; } ?>
Directory name legality detection function
// Directory name legality detection function isen($str){ $ret=""; for ($i=0;$i $p=ord(substr($str,$i,1)); if(($p<48 & $p!=45 & $p!=46) || ($ p>57 & $p<65) || ($p>90 & $p<97 & $p!=95) || $p>122){ nerror("Does not meet the specification! "); } $ret.=chr($p); } return $ret; } ?>
paging function
//分页函式 function splitlist($HALT,$LRLIST,$ECHOCNT,$paper,$table,$where,$page_id,$userid){ global $splitstr,$sumcnt; if($paper=="" || $sumcnt==""){ $query = "select count(*) as num from $table $where"; $result = mysql_query($query); $row = mysql_fetch_array($result); $sumcnt=$row["num"]; if($sumcnt==0){ nerror("该版内还没有选择发布新闻 !"); } $paper=1; }
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
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,
Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.
The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.
How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...
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.
Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...