Home >Backend Development >PHP Tutorial > java软件工程师学php -9. 字符串处理

java软件工程师学php -9. 字符串处理

WBOY
WBOYOriginal
2016-06-13 13:10:38938browse

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)

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn