i<($start+$length); $i++) { $substr .= $str[$i]; } }
if ($length < 0) { for ($i=$start; $i<(strlen($str)+$length); $i++) { $substr .= $str[$i]; } } return $substr; } // }}}
// {{{ strrev() /** * Reversal string order * * @param string $str need reversal string variable * @return string reversal string * @version v0.1 www.knowsky.com * @create 2005-5-24 * @modified 2005-5-24 * @author heiyeluren <hyeiyeluren@163.com> */ function strrev1($str) { if ($str == '''') return 0; for ($i=(strlen($str)-1); $i>=0; $i--) { $rev_str .= $str[$i]; } return $rev_str; } // }}}
// {{{ strcmp() /** * String comparison * * @param string $s1 first string * @param string $s2 second string * @return int return -1,str1 < str2; return 1, str1 > str2, str1 = str2, * return 0, other, return false * @version v0.1 * @create 2005-5-24 * @modified 2005-5-24 * @author heiyeluren <hyeiyeluren@163.com> */ function strcmp1($s1, $s2) { if (strlen($s1) < strlen($s2)) return -1; if (strlen($s1) > strlen($s2)) return 1;
for ($i=0; $i<strlen($s1); $i++) { if ($s1[$i] == $s2[$i]) continue; else return false; } return 0; } // }}}
// {{{ strchr(), strstr(), strpos() /** * Find first occurrence of a string * * @param string $str parent string * @param string $substr need match sub string * @return int return find sub string at parent string first place, * f not find, return false * @version v0.4 * @create 2005-5-24 * @modified 2005-5-29 * @author heiyeluren <hyeiyeluren@163.com> */ function strchr1($str, $substr) { $m = strlen($str); $n = strlen($substr);
if ($m < $n) return false;
for ($i=0; $i<=($m-$n+1); $i++) { $sub = substr($str, $i, $n); if (strcmp($sub, $substr) == 0) return $i; } return false; } // }}}
// {{{ str_replace() /** * Replace all occurrences of the search string with the replacement string * * @param string $substr need replace sub string variable * @param string $newsubstr new sub string * @param string $str operate parent string * @return string return replace after new parent string * @version v0.2 * @create 2005-5-24 * @modified 2005-5-29 * @author heiyeluren <hyeiyeluren@163.com> */ function str_replace1($substr, $newsubstr, $str) { $m = strlen($str); $n = strlen($substr); $x = strlen($newsubstr);
if (strchr($str, $substr) == false) return false;
for ($i=0; $i<=($m-$n+1); $i++) { $i = strchr($str, $substr); $str = str_delete |