java程序员学php -9. 字符串处理

PHP                     JAVA标准库或commons-lang的StringUtils

==================================

trim($str)  ———  str.trim()

strtoupper($str)—–  str.toUpperCase()

ucfirst($str) ——-  StringUtils.capitalize(str)

explode(‘;’,$str) —- StringUtils.split(str, ";")

join(‘;’, $str)   —  StringUtils.join(str, ";")

substr($str, 3)   —  str.substring(3)

substr($str, -4)  —   无

$str1 == $str2    — str1.equals(str2)

strlen($str)      —  str.length()

strstr($str,’o’)  —  str.contains("o")

stristr($str,’o’) —  str.contains("o") || str.contains("O")

strpos($str, ‘o’) —  str.indexOf(‘o’)

strrpos($str,’o’) —  str.lastIndexOf(‘o’)

str_replace($str, —  StringUtils.replace("str", "abc", "ABC")

  ‘abc’, ‘ABC’)   

str_replace(      —  无

  $str_array,

  $target_array,

  $replacement_array)

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.