23 lines
782 B
PHP
23 lines
782 B
PHP
<?php
|
|
// File name: trimtext.inc.php
|
|
// Description: PHP subroutine to trim a textarea input
|
|
// Date: 2004-06-10
|
|
// Author: imacat <imacat@pristine.com.tw>
|
|
// Copyright: Copyright (C) 2004-2007 Pristine Communications
|
|
|
|
// trimtext: Trim a textarea input, remove excess spaces
|
|
function trimtext($a)
|
|
{
|
|
// Format the textarea input to UNIX text format
|
|
$a = str_replace("\r\n", "\n", $a);
|
|
// Trim the excess leading and trailing lines and spaces
|
|
// This is not working. Long articles may overload the PCRE limit.
|
|
//$a = preg_replace("/^(?:[^\S\n]*\n)*(.*?)\s*$/us", "\\1", $a);
|
|
$a = preg_replace("/^(?:[^\S\n]*\n)+/s", "", rtrim($a));
|
|
// Remove the excess spaces at the end of each line
|
|
$a = preg_replace("/[^\S\n]+\n/", "\n", $a);
|
|
return $a;
|
|
}
|
|
|
|
?>
|