[英]Remove Code White-space (WordPress)
基本上,我有一個WordPress循環,我需要壓縮所有代碼,並剝離所有不必要的空格,如下所示:
<article><p>Content</p></article><article><p>Content</p></article><article><p>Content</p></article>
我使用以下方式包含循環文件:
<?php get_template_part('library/inc/loop'); ?>
只是想知道是否有一個簡單的方法,例如:
<?php trim( get_template_part('library/inc/loop') ); ?>
如果可以的話,我所有的問題都將得到解決,我們將不勝感激。 干杯!
要刪除HTML元素中的所有前導和尾隨空格,您可以使用
// Remove whitespace before '<'
$html = preg_replace('~\s+<~', '<', $html);
// Remove whitespace after '>'
$html = preg_replace('~>\s+~', '>', $html);
這將使文本內的所有空格保持不變。
我對WordPress的“后端”不太熟悉,但是您可以嘗試
str_replace(" ","",$data);//Find whitespace " " and replace with ""
澄清一下:輸出時是空格還是源代碼中的空格?
或者像您所說的那樣嘗試使用trim()。 我希望這可以幫助你。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.