PHP, add a newline with implode

后端 未结 4 2026
忘了有多久
忘了有多久 2020-12-06 06:16

I\'m trying to add a newline \\n, in my foreach statement with implode.

My code:

$ga->requestReportData($profileId,array(\'country\'),a         


        
4条回答
  •  醉梦人生
    2020-12-06 06:45

    Many others claim you use the wrong order, that's only partial right, because the docs only recommend this, but you don't have to:

    implode() can, for historical reasons, accept its parameters in either order. For consistency with explode(), however, it may be less confusing to use the documented order of arguments.

    I think your problem is caused by how browsers interpret HTML. They don't care about newlines, they're like a normal space for them.

    To show these linebreaks, you can use

    . You could also use nl2br(implode(..)) or nl2br(implode(..), true) if you're writing XHTML.

提交回复
热议问题