PHP 字符串函数

PHP print()函数是开发中常用的字符串函数之一,用于输出一个或多个字符串。

注意:print() 函数实际上并不是一个函数,所以不需要使用括号.

语法

int print ( string $arg );
参数说明必须/可选
string指定一个或多个要发送输出的字符串。必填

示例1

<?php
$str = "Hello PHP";
print $str;
?>

输出:

Hello PHP

示例2

<?php
$str = "Hello PHP!";
print $str;
print "<br>It is Server Side Scripting Language";
?>

输出:

Hello PHP! It is Server Side Scripting Language

示例3

<?php
$str1="Hello PHP!";
$str2="PHP is server side scripting language";
print $str1 . " " . $str2;
?> 

输出:

Hello PHP! PHP is server side scripting language

示例4

<?php
$age=array("JOHN"=>"35");
print "JOHN is " . $age['JOHN'] . " years old.";
?>

输出:

JOHN is 35 years old.