Home > Backend Development > PHP8 > body text

Functions commonly used in php development

爆肝混世大魔王-流笙 第五人格服务
Release: 2021-03-30 11:36:23
Original
259 people have browsed it

$createtime = date( "Y-m-d H:i:s" );echo"$createtime ";//时间
Copy after login

The time function outputs the current hour, minute and second. For example, this function can record the time of publishing an article and displaying the post in the data field.

 $h = is_null( $c );  //判断数据是不是空
Copy after login

Judge whether the data is empty. Usually this function parameter is placed in a variable. Judgment

 exit;//终止后面的程序
Copy after login

When this function is executed, the following code will not be executed

cookie( 'email' );//获取cookie
Copy after login

Get the cookie of the currently visited URL. The parameter is the string cookie name

  $vv=substr($valueStr,-43);//从后面截取43个字符	
Copy after login

Intercept the desired characters from the current string. Usually parameter 1 is placed in the variable string. Parameters 2 and 3 fill in where to intercept and how much to intercept. You can only fill in two parameters.

echo PHP_VERSION;if(version_compare(PHP_VERSION,&#39;5.4.0&#39;)<0){exit
(&#39;您的PHP版本为&#39;.PHP_VERSION.&#39;!我们的程序要求是PHP版本不低于5.4.0
!&#39;);}//要求php版本5.4.0
Copy after login

Judge PHP Is the version consistent with the current PHP application? To use this function, just modify the PHP version string parameter. For example, if you change the parameter version of this case to 8.0, you must require version 8.0 or above to execute our website normally. If you use the management of this website If the member's server does not have the corresponding PHP version environment, our prompt will be output and all codes will not be executed.

$valueStr = &#39;&#39;;	
foreach ( $a as $v ) {
$valueStr .= "" . $v[ &#39;images&#39; ] . ""; //循环拼接添加数据数组转为
字符串   	}
Copy after login

This small traversal code is often used. For example, if you check the database, the object contains an array. At that time, you can traverse the forech parameter 2 in this way, that is, the obtained object contains an array and converted into a two-dimensional array. If you want to convert it into a string, you can also splice it like this. Usually, in this case, $v[''images] is a database Field Because $v has been converted into an array, you can directly access this field like this. Many times when doing development, we like to query the database information as a two-dimensional array because we need to do traversal rendering. This case is easy to understand

getcwd();//获取当前目录
Copy after login

This function can get all the current directory paths. Many frameworks do not have the original directory structure. We can use this function to get the directory and then splice a string to get the path you want

isset( $_POST[ &#39;email&#39; ]  )//判断数组有没有定义
Copy after login

To determine whether this array is defined, the parameter is to put an array value, which can be a variable or the obtained value

echo strlen($valueStr);//获取字符串长度	
Copy after login

To get the number of parameters in the string, just put a variable string

$d=date(&#39;Y-m-d&#39;);	$dd=strtotime($d);//把普通时间转化为时间戳
Copy after login

Convert the time format year, month and day into the timestamp format

$vvc = end( $v );//获取最后一个数组的一条数据
Copy after login

Get the last key value of the array. The parameter is an array or a variable array

if ( !empty( $id[ 0 ] ) ) {
			
            }   //判断数据有没有
Copy after login

Judge whether the data exists

The above is the detailed content of Functions commonly used in php development. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
1
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template