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

PHP outputs one or more string function print()

黄舟
Release: 2023-03-16 22:38:02
Original
2050 people have browsed it

Example

Output some text:

<?php 
print "Hello world!"; 
?>
Copy after login

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)
Copy after login

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;
?>
Copy after login

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!";
?>
Copy after login

Example 3

Connect two string variables:

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

Example 4

Output the value of the array:

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

Example 5

Output some text:

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

实例 6

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

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


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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template