trimStr、ltrimStr、rtrimStr处理 PHP TRIM是个坑问题 $len1) return trim($str); $str = ltrimStr($str, $list); $str = rtrimStr($str, $list); return $str; }}/* * ltrim 字符串 * 类似 php 函数 ltrim * @see http://ramble.3vshej.cn/p
$len1) return trim($str); $str = ltrimStr($str, $list); $str = rtrimStr($str, $list); return $str; } } /* * ltrim 字符串 * 类似 php 函数 ltrim * @see http://ramble.3vshej.cn/php-trim-is-a-pit/ PHP TRIM 是个坑 大坑 * @param string $str 源字符 * @param string $list 待清除字符 * @return string */ if ( ! function_exists('ltrimStr')) { function ltrimStr($str, $list='') { $list = (string) $list; if (!isset($list[0])) return ltrim($str); $len1 = strlen($str); $len2 = strlen($list); if ($len2 > $len1) return ltrim($str); $s = ''; do { $s = substr($str, 0, $len2); if ($s == $list) $str = substr($str, $len2); } while($s == $list); return $str; } } /* * rtrim 字符串 * 类似 php 函数 rtrim * @see http://ramble.3vshej.cn/php-trim-is-a-pit/ PHP TRIM 是个坑 大坑 * @param string $str 源字符 * @param string $list 待清除字符 * @return string */ if ( ! function_exists('rtrimStr')) { function rtrimStr($str, $list='') { $list = (string) $list; if (!isset($list[0])) return rtrim($str); $len1 = strlen($str); $len2 = strlen($list); if ($len2 > $len1) return rtrim($str); $s = ''; do { $s = substr($str, -$len2); if ($s == $list) $str = substr($str, 0, -$len2); } while($s == $list); return $str; } } ?>