Common input statements and common functions of php
这篇文章主要介绍了关于php的常用输入语句以及常用函数,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下
一、 echo语句
echo做php的人在熟悉不过了,在php文件中我们用他来输出数据。
<?php echo "hi mm"; echo "this is {$_SERVER['SCRIPT_URL']} !"; //定界符,我们用他可以输入一在堆的html,而不要考虑引号的问题 echo <<<STR <p id="search"> <form method="get" id="searchform" action="http://blog.51yip.com/"> <p> <input type="text" value="" name="s" id="s" /> <input type="submit" id="searchsubmit" value="Search" /> </p> </form> </p> STR; //定界符可以自定义,不过要成对出现,并且结束的地方要顶头 var_dump(print('test')); //结果为trueint(1),print是函数有返回值 var_dump(echo "<br>" ); //报错,echo不是函数 1? print('222'): print('11111'); //结果为222 1 ?echo '222':echo '11111'; //报错的,echo不是函数,这样的写法,我也经常范的。 ?>
从上面的例子中我们要以看出,echo可以很灵活的输出要输出的东西,输出字符串,根其他字符结合来完成输出,例如:利用{}大括号来输出数组中的数据,利用定界符来输出大段的HTML,这一点很有用的。echo他不是函数,没有返回值,这一点根print不一样。
二、 print函数
<?php print "hi mm"; print "this is {$_SERVER['SCRIPT_URL']} !"; //定界符,我们用他可以输入一在堆的html,而不要考虑引号的问题 print <<<STR <p id="search"> <form method="get" id="searchform" action="http://blog.51yip.com/"> <p> <input type="text" value="" name="s" id="s" /> <input type="submit" id="searchsubmit" value="Search" /> </p> </form> </p> STR; //定界符可以自定义,不过要成对出现,并且结束的地方要顶头 ?>
从上面的二个例子,我们可以看出,echo和print基本上没什么区别,一个不是函数,一个是函数。
三、 printf函数
格式:string printf ( string format [, mixed args])
<?php $format = "my name is %s,%04d older"; printf($format, 'tank',28); //结果为:my name is tank,28 older $format = "my name is %2\$s,%1\$d older"; printf($format, 'tank',28); //my name is 28,0 older 为什么会出现0,因为给的字符根要格式输出的字符不匹配 $format = "my name is %s,%d older"; printf($format, 'tank'); //Warning: printf() [function.printf]: Too few arguments $format = "my name is %1\$s,%1\$d older"; printf($format, 'tank'); //结构为:my name is tank,0 older ?>
下面格式类型,和printf相类似的就不说了,好多。
%d 十进制有符号整数
%u 十进制无符号整数
%f 浮点数
%s 字符串
%c 单个字符
%p 指针的值
%e 指数形式的浮点数
%x, %X 无符号以十六进制表示的整数
%o 无符号以八进制表示的整数
%g 自动选择合适的表示法
四、 print_r函数以及var_dump函数
大多数人用print_r都是用来打印数组的,其实他可以打印很多种类型的数据,数组只是其中之一,var_dump他的最大好处是什么呢,不光可以看到打印出来的数据是什么,还能让你知道他是什么类型。即使你看到的东西是一样的,但类型不一定一样。
<?php $test = array('tank'); $aaaa = "aaaaa"; print_r($test); //结果Array ( [0] => tank ) var_dump($test); //结果array(1) { [0]=> string(4) "tank" } print_r($aaaa); //结果aaaaa var_dump($aaaa); //结果string(5) "aaaaa" print_r(true); //结果1 var_dump(true); //结果bool(true) $bbb = 11; $ccc = "11"; var_dump($bbb); //结果int(11) var_dump($ccc); //结果string(2) "11" ?>
五、 exit函数和die函数
这二个函数也是我们经常用的,调试程序的时候,我们需要中断程序的执行,这个时候,就可以用这二个函数了。
<?php 1?exit("aaaaaa"):exit("bbbbbbb"); //结果aaaaaa 1?die("cccccc"):die("ddddddd"); //结果cccccc ?>
相关推荐:
The above is the detailed content of Common input statements and common functions of php. For more information, please follow other related articles on the PHP Chinese website!

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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



Alipay PHP...

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,

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...

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

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�...

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.

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo
