Summary of commonly used output functions in PHP, PHP output function
Echo (); " Output content ";
You can output multiple strings at the same time, multiple parameters, no parentheses, no return values.
print (); Has a return value of 1, 0 tangent can only contain one parameter
You can only output one string at a time, one parameter, a parenthesis, a return value, and flase when its execution fails.
Print is used in a very similar way to the C language, so there is a special explanation for the% in the output content.
Copy the Code code as follows:
$a =print (' Hi ');
echo $a;
—————————-
Hi 1//1 is the value of $a.
—————————–
Die (); Generally used for database connection judgment, once the execution of Die () after the content will not be executed
Die (); and exit () difference.
There are two functions: output the content first, then exit the program. (commonly used in linked servers, databases)
Copy the Code code as follows:
Mysql_connect ("Locahost", "root", "root") or Die ("link server failed!") “);
printf (); As with the C language, you can format the output
printf (); F = Format formatted
printf ("parameter 1″, parameter 2): Parameter 1 = output by what format; parameter 2= output variable.
(% s: by string;%d: by integer type;%b: press binary;% x: Press 16 to enter;%x: Press 16 to capitalize the output;%o: press octal;% f: float type)
function, returns the number of output characters, and then formats the text for later output, such as:
Copy the Code code as follows:
printf ("$%01.2f", 43.2); $43.20
$ represents a populated character
0 indicates that the number of digits does not affect the original value in the case of
1 indicates the total width of the output
2 indicates the number of decimal digits, there is rounding
%f is indicated as a floating-point number
formatting commands and descriptions:
Percent percentage mark, not convert.
The%b integer is converted into binary.
The%c integer is converted to the corresponding ASCII character.
%d integers are converted to 10 decimal.
%f times the precision number into floating point numbers.
%o The integer is turned into octal.
The%s integer is converted to a string.
%x integers are converted to lowercase 16 rounding.
%x integers are converted to uppercase 16 rounding.
Copy the Code code as follows:
<?php
$num = 100.001;
printf ("%d", $num); 100
printf ("%s", $num); 100.001
printf ("%s-%d-%b-%x-%o-%f", $num, $num, $num, $num, $num, $num)
100.001-100-1100100-64-144-1001.00100
printf ("%.2f", $num); 100.00 (decimal point reserved 2 digits)
printf ("%.1f", $num); 100.0 (decimal point reserved 1 digits)
printf ("% ' #10s", $num); #10s
printf ("% #10s", $num); 10s
?>
sprintf; Store the output in a variable
This cannot be output directly, first assigning a variable, and then outputting the variable.
Copy the Code code as follows:
<?php
$num = 100.001;
$a =sprintf ("%d", $num);
echo $a; 100
?>
Print_r (); For output arrays
Function: Used only for output arrays.
Copy the Code code as follows:
$a = Array (1, 2, Array ("A", "B", "C"));
Print_r ($a);
Return:
Copy the Code code as follows:
Array ([0] = 1 [1] = 2 [2] = = Array ([0] + a [1] = + b [2] = c))
var_dump (); Can output any Content
Output variable capacity, type, or string content, type, length. Commonly used to debug.
Copy the Code code as follows:
<?php
$a = 100;
Var_dump ($a); Int (100)
$a = 100.356;
Var_dump ($a); Float (100.356)
?>
Var_export ();
Returns the structure information about the variable passed to the function, similar to Var_dump (), unlike the PHP code whose returned representation is valid.
You can return the value of a variable by setting the second argument of the function to true.
Copy the Code code as follows:
<?php
$a = Array (1, 2, Array ("A", "B", "C"));
Var_export ($a);
/*
Output:
Array (
0 = 1,
1 = 2,
2 =
Array (
0 = ' a ',
1 = ' B ',
2 = ' C ',
),
)
*/
$b = 3.1;
$v = Var_export ($b, TRUE);
Echo $v;
/*
Output:
3.1
*/
?>
Simplified usage:
Copy the Code code as follows:
<?php
$color = "Red";
?>
Roses is <?= $color?>
PHP Common functions
Master some of the often used functions, this is not difficult, more than a few times to remember
And then, if you don't, check the manual.
In fact, every PHP do not have to remember all the functions, but often use the few are to remember, otherwise too outrageous.
The manual is important.
All right, your question, one answer.
The function must be used frequently in the work.
The function must be very important.
Often using functions will speed up the function learning efficiency, for example, to do a case, the function can be used to use, you will remember a lot of functions
Commonly used functions are string processing, arrays of the processing of this kind of
PHP Common functions
In fact, there is no need to go around the so-called "common functions", so-called commonly used is different, someone often use a function, but does not mean that you will always use. PHP function A lot, standing PHP help manual is the key, encountered unfamiliar on the check, check the number of times, naturally become "common".
In general, the functions of strings, arrays, and database classes are relative to the use of more than one category.
Here is a list of functions, for reference only.
============================================
=============================== Time Date ===============================
Y returns the last two digits of the year, the Y-year four digits, the M-month number, and the M-month English. D Month Date number, D week a few English
$date =date ("y-m-d");
Include,include_once.require,require_once
Require ("file.php") will be read into the file specified by require before the PHP program executes, if the error is fatal.
The Include ("file.php") can be placed anywhere in the PHP program, and the PHP program will read into the include specified file when it is executed, such as an error prompting
=============================== Output Print ===============================
sprintf ("%d", "3.2");//format only, return formatted string, not output.
printf ("%d", "3.2");//format and output
Print ("3.2");//Output only
echo "Nihao", "AA";//can output multiple strings
Print_r (Array ("A", "B", "C"));//The array's key values and elements are displayed sequentially
=============================== commonly used String functions ===============================
Gets the string length, the number of characters, the space is also counted
$STR = "Sdaf SD";
$len =strlen ($STR);
Use the string in the first argument to concatenate each element in the following array and return a string.
$str =implode ("-", Array ("A", "B", "C"));
String segmentation method, return an array, with the characters in the first argument to split the following string, the specified characters are truncated before and after the character, if the specified character at the beginning or end of the returned array of the beginning or end of the element is an empty string
A null value is returned to the corresponding element of the array without splitting it into a string. The last limit returns the length of the array, which is not limited, and is always split down.
$array =explode ("A", "ASDD ... Remaining full text >>
http://www.bkjia.com/PHPjc/882915.html www.bkjia.com true http://www.bkjia.com/PHPjc/882915.html techarticle php commonly used in the OUTPUT function summary, PHP output function echo (); "Output content"; You can output multiple strings at the same time, multiple parameters, no parentheses, no return value. Prin ...