dongshuming7131 2017-09-14 10:10
浏览 29
已采纳

为什么PHP echo printf添加意外符号[重复]

This question already has an answer here:

I have php code:

$searchTitlePersonType = ($isTravelAgency == true ? "tourists" : "persons"); 
var_dump($searchTitlePersonType); // Right behavior

The same time, when I try to implement it on my template:

<?php
    echo printf( $this->translate("Поиск %s"), $searchTitlePersonType ); 
?>

I'm taking different unexpected numbers at the end of string: "tourists33" or "persons27". It's not depend of coding page of string and there is a lot of people who find the way to resolve it - do not combine echo printf in one line of code, but here my question about this problem: WHY does it happen?

Links:

php printf adds number to output

PHP printf adds something after formatted string

</div>
  • 写回答

1条回答 默认 最新

  • drbouzlxb92333332 2017-09-14 10:13
    关注

    You are confusing some things here. echo printf as a construct does not make sense, since printf already prints.

    What you are seeing, is that printf does its job, and then echo prints the result of printf, which is the length of the printed string.

    So, instead, you can use sprintf, which returns the formatted string instead of printing it, or you can skip the echo part of your program.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊