php中sprintf函数怎么用

用法:1、新建一个php示例文件;2、在文件中添加html架构代码;3、在body标签中添加php代码并使用sprintf函数;4、通过浏览器观察效果即可。

php中sprintf函数怎么用

php中sprintf函数的用法

具体使用方法:

1.新建一个php示例文件。

2.在文件中添加html架构代码。

<!DOCTYPE html>
<html>
    <head>
        <title>php</title>
    </head>
    <body>
    </body>
</html>
登录后复制

3.在body标签中添加php代码并使用sprintf函数。

<?php
$number = 2;
$str = "Shanghai";
$txt = sprintf("There are %u million cars in %s.",$number,$str);
echo $txt;
?>
登录后复制

把百分号%符号替换成一个作为参数进行传递的变量。

4.通过浏览器观察效果即可。

sprintf定义:

sprintf()函数可以把格式化的字符串写入变量中。

以上就是php中sprintf函数怎么用的详细内容,更多请关注php中文网其它相关文章!

https://www.php.cn/faq/698595.html

发表回复

Your email address will not be published. Required fields are marked *