久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長(zhǎng)資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      php怎么將指定字符串替換為空

      方法:1、使用str_ireplace(),語法“str_ireplace(指定子字符串, '', 原字符串)”;2、使用substr_replace(),語法“substr_replace(原字符串,'',開始替換的位置,替換長(zhǎng)度)”。

      php怎么將指定字符串替換為空

      本教程操作環(huán)境:windows7系統(tǒng)、PHP7.1版,DELL G3電腦

      在PHP中,可以通過str_ireplace() 和 str_replace()函數(shù) 使用新的字符串替換原來字符串中指定的特定字符串,str_replace 區(qū)分大小寫,str_ireplace() 不區(qū)分大小寫。

      1、使用str_ireplace()函數(shù)替換字符串為空

      str_ireplace() 的語法如下:

      mixed str_ireplace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] )

      該函數(shù)返回一個(gè)字符串或者數(shù)組。該字符串或數(shù)組是將 subject 中全部的 search 用 replace 替換(忽略大小寫)之后的結(jié)果。參數(shù) count 表示執(zhí)行替換的次數(shù)。

      示例:替換字符串為空

      <?php $str = 'hello,world,hello,world'; $replace = ''; $search = 'hello'; echo str_ireplace($search, $replace, $str); ?>

      輸出:

      ,world,,world

      2、使用substr_replace() 函數(shù)替換字符串為空

      substr_replace() 函數(shù)的語法如下:

      mixed substr_replace ( mixed $string , mixed $replacement , mixed $start [, mixed $length ] )

      substr_replace() 在字符串 string 的副本中將由 start 和可選的 length 參數(shù)限定的子字符串使用 replacement 進(jìn)行替換。

      如果 start 為正數(shù),替換將從 string 的 start 位置開始。如果 start 為負(fù)數(shù),替換將從 string 的倒數(shù)第 start 個(gè)位置開始。

      如果設(shè)定了 length 參數(shù)并且為正數(shù),就表示 string 中被替換的子字符串的長(zhǎng)度。如果設(shè)定為負(fù)數(shù),就表示待替換的子字符串結(jié)尾處距離 string 末端的字符個(gè)數(shù)。如果沒有提供此參數(shù),那么默認(rèn)為 strlen(string)(字符串的長(zhǎng)度)。當(dāng)然,如果 length 為 0,那么這個(gè)函數(shù)的功能為將 replacement 插入 string 的 start 位置處。

      示例:替換字符串為空

      <?php $str = 'hello world!'; $replace = ''; echo substr_replace($str, $replace, 0,5); ?>

      輸出:

      world!

      推薦學(xué)習(xí):《PHP視頻教程》

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)