search
HomeBackend DevelopmentPHP TutorialPHP common library functions

1) Time and date

mainly involves time() and date();

<?php //获取时间戳
echo time();
echo &#39;<br/>';
//echo date_default_timezone_get();
//设置时区
date_default_timezone_set('Asia/Shanghai');
//按指定格式输出数据
echo date('Y-m-d H:i:s');
echo '<br>';
//将时间戳转为日期
echo date('Y-m-d H:i:s','2000');
2) Operation of json format data:

mainly involves json_encode() and json_decode();

<?php //将数组转成json格式的数据
$arr=array(2,7,9,&#39;hello&#39;,&#39;jason&#39;,array(&#39;name&#39;=>'lily','age'=>23));
print_r($arr);
echo '<br>';
echo json_encode($arr);

//将键值对对象转成json格式的数据
$obj=array('h'=>'hello','w'=>'world',array(3,5,7));
echo '<br>';
print_r($obj);
echo '<br>';
echo json_encode($obj);

//将json格式的数据转成键值对对象
$objJson='{"h":"hello","w":"world","0":[5,7,8]}';
$myObj=json_decode($objJson);
echo '<br>';
print_r($myObj);
echo '<br>';
echo $myObj->w;
3) File operations:

fopen(), fwrite(), fclose(), fgets(), file_get_contents(), etc.;

<?php /**
 * 写数据
 */
//创建文件标识,注:加@可忽略php的警告
$wf=@fopen(&#39;data&#39;,&#39;w&#39;);
if($wf){
    //写入数据到文件
    fwrite($wf,&#39;oh my god&#39;);
//关闭文件流
    fclose($wf);
}else{
    echo &#39;创建文件失败&#39;;
}
/**
 * 读数据
 */
$rf=@fopen('data','r');
//fgets()只读一行
while(!feof($rf)){
    $c
    echo $content;
}
fclose($rf);
//php提供了一个直接获取文件所有内容的方法
echo file_get_contents('data');
4) Generate pictures, for more methods click php image method

<?php //创建图像文件
$img=imagecreate(400,300);
//设置图像的背景色
imagecolorallocate($img,0,0,255);
//绘制一个椭圆 
imageellipse($img,100,100,80,40,imagecolorallocate($img,255,0,0));
//设置头信息来指明图像所属的mime类型
header(&#39;Content-Type:image/png&#39;);
//显示图像
imagepng($img);


5) Watermark pictures

<?php //载入文件
$img=imagecreatefrompng(&#39;header.png&#39;);
//在图片指定位置写上文字
imagestring($img,5,5,5,&#39;I am not a bitch&#39;,imagecolorallocate($img,255,0,0));
//设置头信息来指明mime类型
header(&#39;Content-Type:image/png&#39;);
//显示图像
imagepng($img);

For more details, please refer to the PHP Chinese manual

Copyright statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.

The above has introduced the commonly used library functions of PHP, including related content. I hope it will be helpful to friends who are interested in PHP tutorials.

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
五个精选的Go语言开源项目,带你探索技术世界五个精选的Go语言开源项目,带你探索技术世界Jan 30, 2024 am 09:08 AM

在当今科技快速发展的时代,编程语言也如雨后春笋般涌现出来。其中一门备受瞩目的语言就是Go语言,它以其简洁、高效、并发安全等特性受到了许多开发者的喜爱。Go语言以其强大的生态系统而著称,其中有许多优秀的开源项目。本文将介绍五个精选的Go语言开源项目,带领读者一起探索Go语言开源项目的世界。KubernetesKubernetes是一个开源的容器编排引擎,用于自

深入解析JWT(JSON Web Token)的原理及用法深入解析JWT(JSON Web Token)的原理及用法Jan 10, 2023 am 10:55 AM

本篇文章给大家带来了关于JWT的相关知识,其中主要介绍了什么是JWT?JWT的原理以及用法是什么?感兴趣的朋友,下面一起来看一下吧,希望对大家有帮助。

Go语言开发必备:5个热门框架推荐Go语言开发必备:5个热门框架推荐Mar 24, 2024 pm 01:15 PM

《Go语言开发必备:5个热门框架推荐》Go语言作为一门快速、高效的编程语言,受到越来越多开发者的青睐。为了提高开发效率,优化代码结构,很多开发者选择使用框架来快速搭建应用。在Go语言的世界中,有许多优秀的框架可供选择。本文将介绍5个热门的Go语言框架,并提供具体的代码示例,帮助读者更好地理解和使用这些框架。1.GinGin是一个轻量级的Web框架,拥有快速

php输出json无法解析的原因和解决方法【总结】php输出json无法解析的原因和解决方法【总结】Mar 23, 2023 pm 04:35 PM

PHP作为一种常见的编程语言,在web开发中使用广泛,其与前端交互的方式也多种多样。其中,输出Json数据是一种常见的交互方式,但有时候会碰到Json无法解析的问题。为什么会出现无法解析的情况呢?下面列举了几个可能的原因。

php如何将xml转为json格式?3种方法分享php如何将xml转为json格式?3种方法分享Mar 22, 2023 am 10:38 AM

当我们处理数据时经常会遇到将XML格式转换为JSON格式的需求。PHP有许多内置函数可以帮助我们执行这个操作。在本文中,我们将讨论将XML格式转换为JSON格式的不同方法。

使用Golang的Web框架Echo框架实现分布式任务调度使用Golang的Web框架Echo框架实现分布式任务调度Jun 24, 2023 am 11:49 AM

随着互联网的发展和信息技术的进步,大数据时代已经来临,数据分析、机器学习等领域也得到了广泛的应用。在这些领域中,任务调度是一个不可避免的问题。如何实现高效的任务调度,对于提高效率至关重要。在本篇文章中,将介绍如何使用Golang的Web框架Echo框架实现分布式任务调度。一、介绍Echo框架Echo是一个高性能、可伸缩、轻量级的GoWeb框架。它基于HTT

聊聊怎么使用Node将Excel转为JSON聊聊怎么使用Node将Excel转为JSONNov 28, 2022 pm 08:02 PM

怎么使用Node将Excel转为JSON?下面本篇文章给大家介绍一下Node中转换Excel成JSON的方法,希望对大家有所帮助!

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决Jun 13, 2016 am 10:23 AM

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code<form name="myform"

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 Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

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.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment