PHP字符串操作与正则表达式

字符串的整理

chop()
ltrim()
rtrim()
trim()

字符串的格式化

  1. 使用HTML格式化:nl2br()
    nl2br() // new line to <br>
  2. 为打印输出而格式化字符串
    print()
    printf()
void printf(string format [, mixed args])

sprintf()

string sprintf(string format [, mixed args])
  1. 格式化字符串以便存储 addslashes()和stripslashes()

用字符串函数连接和分割字符串

  1. 使用函数explode() implode()和join()
    $email_array = explode('@', $email) 将字符串分割成数组
    implode('@', $email_array) 将字符串数组合并
    join('@', $email_array) 将字符串数组合并

  2. 使用strtok()函数
    根据分隔字符串中的每个字符来分割

$token = strtok($feedback, )

猜你喜欢

转载自blog.csdn.net/weixin_34414196/article/details/87405839
今日推荐