printf和sprintf的应用
程序员文章站
2022-03-18 22:52:52
...
c: %c
d: %df: %f', 80,80, 80, 80); echo '
'; printf('%0.2f
%+d
%0.2f
', 8, 8, 1235.456); printf('the cost of %d %s at $%0.2f each is $%0.2f.', 4, 'brooms', 8.50, (4*8.50)); echo '
'; $tax = 30; printf('The tax rate is %0.2f%%', $tax);
Sprint可以把查询和数据很好的分开代码
$y['parent_id']); } usort($tasks, 'parent_sort'); echo 'Sorting Multidimensional Arrays 1])) { $parent_id = $_POST['parent_id']; } $q = sprintf("INSERT INTO tasks (parent_id, task) VALUES (%d, '%s')", $parent_id, mysqli_real_escape_string($db, strip_tags($_POST['task']))); $r = mysqli_query($db, $q); if(mysqli_affected_rows($db) == 1) { echo '任务添加成功
'; } else { echo '任务添加失败
'; } } ?>
当前的任务列表
- ';
foreach ($tasks as $task) {
echo "
- {$task['task']} \n"; } echo '