<?php
$str = " This line contains\tliberal \r\n use of whitespace.\n\n";
// 移除前後空白字
$str = trim($str);
// 移除重覆的空白
$str = preg_replace('/\s(?=\s)/', '', $str);
// 移除非空白的間距變成一般的空白
$str = preg_replace('/[\n\r\t]/', ' ', $str);
// Echo out: 'This line contains liberal use of whitespace.'
echo "<pre>{$str}</pre>";
?>
// 原文出處 : http://myphplogs.blogspot.com/2007/10/php_128.html
全站熱搜
留言列表