Home >Backend Development >PHP Tutorial >PHP outputs one or more string function print()

PHP outputs one or more string function print()

黄舟
黄舟Original
2017-11-02 13:57:432047browse

Example

Output some text:

<?php 
print "Hello world!"; 
?>

Definition and usage

print() function outputs one or more strings.

Note: The print() function is not actually a function, so you don't have to use parentheses with it.

Tip: The print() function is slightly slower than echo().

Syntax

print(strings)

Parameter Description

strings Required. One or more strings sent to the output. ​

Technical details

Return value: ​Always returns 1.

PHP version: 4+

More examples

Example 1

Output the value of the string variable ($str):

<?php
$str = "Hello world!";
print $str;
?>

Example 2

Output the value of the string variable ($str), including HTML tags:

<?php
$str = "Hello world!";
print $str;
print "<br>What a nice day!";
?>

Example 3

Connect two string variables:

<?php
$str1="Hello world!";
$str2="What a nice day!";
print $str1 . " " . $str2;
?>

Example 4

Output the value of the array:

<?php
$age=array("Peter"=>"35");
print "Peter is " . $age[&#39;Peter&#39;] . " years old.";
?>

Example 5

Output some text:

<?php
print "This text
spans multiple
lines.";
?>

实例 6

单引号和双引号的区别。单引号将输出变量名称,而不是值::

<?php
$color = "red";
print "Roses are $color";
print "<br>";
print &#39;Roses are $color&#39;;
?>


The above is the detailed content of PHP outputs one or more string function print(). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn