Summary of types of PHP printing functions_PHP tutorial
In PHP printing function 1 echo()
can output multiple strings at the same time and can have multiple parameters. , parentheses are not required, and there is no return value.
PHP printing function 2 print()
can only output one string and one parameter at the same time, requires parentheses, and has a return value. When its execution fails, it returns flase. The usage of print is very similar to that of C language, so % in the output content will be specially interpreted.
PHP printing function 3 die();
has two functions: first output the content, and then exit the program . (Commonly used in linked servers and databases)
mysql_connect("locahost","root","root") or die("Linked server failed!");
PHP printing function 4 printf();
printf("Parameter 1", Parameter 2): Parameter 1 = output format; Parameter 2 = output variable. ($s: according to string; $d: according to integer; $b: according to binary; $x: according to hexadecimal; $o: according to octal; $f: according to floating point)
<ol class="dp-xml"><li class="alt"><span><span class="tag"><</span><span> ?php </span></span></li><li><span>$</span><span class="attribute">num</span><span>=</span><span class="attribute-value">100</span><span>.001; </span></li><li class="alt"><span>printf("%d",$num); //100 </span></li><li><span>printf("%s",$num); //100.001 </span></li><li class="alt"><span>printf("%s---%d---%b---%x---%o---%f",$num,$num,$num,$num,$num,$num) </span></li><li><span>//100.001---100---1100100---64---144---1001.00100 </span></li><li class="alt"><span>printf("%.2f",$num); //100.00 (小数点保留2位) </span></li><li><span>printf("%.1f",$num); //100.0 (小数点保留1位) </span></li><li class="alt"><span>printf("%`#10s",$num); //###100.001 </span></li><li><span>printf("%`@10s",$num); //@@@100.001 </span></li><li class="alt"><span>printf("%`_10s",$num); //___100.001 </span></li><li><span>printf("%`#-10s",$num); //100.001### </span></li><li class="alt"><span>printf("%`@-10s",$num); //100.001@@@ </span></li><li><span>printf("%`_-10s",$num); //100.001___ </span></li><li class="alt"><span>printf("%`#20s",$num); //#############100.001 </span></li><li><span class="tag">?></span><span> </span></span></li></ol>
PHP printing function 5 sprintf();
This cannot be output directly, assign it to a first variable, and then output the variable.
<ol class="dp-xml"><li class="alt"><span><span class="tag"><</span><span> ?php </span></span></li><li><span>$</span><span class="attribute">num</span><span>=</span><span class="attribute-value">100</span><span>.001; </span></li><li class="alt"><span>$</span><span class="attribute">a</span><span>=</span><span class="attribute-value">sprintf</span><span>("%d",$num); </span></li><li><span>echo $a; //100 </span></li><li class="alt"><span class="tag">?></span><span> </span></span></li></ol>
PHP printing function 6 print_r();
Function: only For output array.
PHP printing function 7 var_dump();
Function: Output the content, type or string content, type, length of the variable. Often used for debugging.
<ol class="dp-xml"><li class="alt"><span><span class="tag"><</span><span> ?php </span></span></li><li><span>$</span><span class="attribute">a</span><span>=</span><span class="attribute-value">100</span><span>; </span></li><li class="alt"><span>var_dump($a); //int(3) 100 </span></li><li><span class="tag">?></span><span> </span></span></li></ol>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

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

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.
