Get the App
SLTechnology News&Howtos  ›  Development  › 

Analysis of commonly used string output methods in php

Shulou Source: shulou.com Published: 2022-06-03 19:55:20 10月31日 Update

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!

Tags: Output characters strings methods commonly used points analysis content hexadecimal decimal name uppercase letters lowercase decimal age effects text plus or minus science Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn MariaDB Xiaomi MySQL Apple