为什么在函数中返回字符串时,PHP为什么要删除第一个单词之后的空格 [英] Why does PHP remove the space after the first word when returning a string in a function

查看:40
本文介绍了为什么在函数中返回字符串时,PHP为什么要删除第一个单词之后的空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某种原因,在php函数中返回字符串时,第一个单词之后的空格将被删除.我不知道为什么.

For some reason, the space after the first word is removed when returning a string in a php function. I can't figure out why.

function something() {
   $string = "My sentence looks like this";
   return $string;
}

function something_else() {
   $output = something();
   echo $output;
}

输出"Mysentence看起来像这样"

Outputs "Mysentence looks like this"

如果我在第2行之后添加 echo $ string; ,它将正确打印 $ string .但是,第二个函数不会以这种方式输出它.

If I add echo $string; after line 2 it prints $string correctly. However, the second function does not output it that way.

此外,我可以通过将第2行更改为

Also, I am able to get it working by changing line 2 to

$string = "<strong>My sentence</strong looks like this";

推荐答案

在测试了各种浏览器之后,该问题似乎仅与MS Edge有关.它可以在Firefox,Chrome,Safari和IE中正常运行.

After testing various browsers, the issue seems related to MS Edge only. It works fine in Firefox, Chrome, Safari, and IE.

这篇关于为什么在函数中返回字符串时,PHP为什么要删除第一个单词之后的空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆