php输出语句print printf echo sprintf比较

作者:白雪 | 创建时间: 2023-07-21
print()语句 echo语句 printf()语句 sprintf()都是php输出语句,但稍微有点区别。下面举例说明。...
php输出语句print printf echo sprintf比较

操作方法

<?php echo "<p>Some dynamic output here</p>"; ?> <p>Some static output here</p> <?php echo "I love the summertime."; ?> echo语句是语言结构。

<?php print("<p>I love the summertime.</p>"); ?> <?php $season="summertime"; print("<p>I love the $season.</p>"); ?> print()有返回值。

printf("Bar inventory: %d bottles of tonic water.",100); //  传入二个参数: printf("%d bottles of tonic water cost $%f",100,43.20); 用来格式化数据。

$cost=sprintf("$%.2f",43.2); 不会在浏览器显示。

点击展开全文

更多推荐