Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Analysis of commonly used string output methods in php

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "php common string output method analysis," interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let Xiaobian take you to learn "php common string output method analysis" bar!

This article describes php common string output methods. Share it with everyone for reference, as follows:

1. echo Usage: echo can be output directly, or echo() can be output, no return value

$string="bold text";echo $string;//echo "";//echo($string);//same effect echo "";echo "This ", "is ", " echo test!" ";//echo Output multiple string echo separated by commas"";

2. print Usage: Same as above echo, only print runs slower than echo, and can only output one string at a time, always returns 1

$string="bold text";print $string;//print "";//print($string);//effect as above print "";

3. printf: Format output string

/*%% -Returns a percent sign %%b -Binary number %c -Character corresponding to ASCII value %d -Signed decimal number (negative, 0, positive) %e -scientific notation using lowercase (e.g. 1.2e+2) %E -scientific notation using capital letters (e.g. 1.2E+2) %u -unsigned decimal number (greater than or equal to 0) %f -floating point number (local setting) %F -floating point number (non-local setting) %g -shorter %e and %f%G -shorter %E and %f%o -octal number %s -string %x -hexadecimal number (lowercase letter) %X-hexadecimal number (uppercase letter)*/$num= 23; printf("printf Output floating-point number: %f",$num);//Output: 23.00000printf ("");printf("printf Output floating-point number of 2 decimal places: %1\$.2f printf Output no decimal places: %1\$u",$num);//Output: 23.00printf("");

4. sprintf:

$name="Tom";$age=20;$printstr=sprintf("sprintf output: his name is %s, age is %u",$name,$age);echo $printstr;//output: his name is Tom, age is 20 to this, I believe everyone has a deeper understanding of "php common string output method analysis", may wish to actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report