我想將字符串中的空格替換爲換行符。preg_replace空間與樹枝斷行
以前
1 2 3 4
後的preg_replace:
1
2
3
4
這是我的代碼:
$m_cart = preg_replace('/\s/', '\n', $session->get('cart'));
return $this->render('FooSiteBundle:Site:bar.html.twig', array('cart' => $m_cart));
和T他是我與觀點枝杈:
{{ cart }}
結果:
\n1\n2\n3\n4
,但我想有
1
2
3
4
它在我的源代碼中正常工作,但不能在我的html頁面中工作 – 2012-08-09 20:02:43
如果你想要的是HTML中的不同行,你需要添加
而不是\ n – 2012-08-09 20:08:52
@Alex它被Twig – JamesHalsall 2012-08-09 20:20:50