我正在寻找一个
PHP函数,可以修剪一个长字符串中的每一行.
例如:
- <?PHP
- $txt = <<< HD
- This is text.
- This is text.
- This is text.
- HD;
- echo trimHereDoc($txt);
输出:
- This is text.
- This is text.
- This is text.
是的,我知道trim()函数.只是不确定如何在像heredoc这样的长字符串上使用它.
- function trimHereDoc($t)
- {
- return implode("\n",array_map('trim',explode("\n",$t)));
- }