久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放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. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      php怎么去掉字符串中的所有空格

      php去掉字符串中所有空格的方法:1、使用str_replace()函數(shù),語法“str_replace(" ","",$str)”;2、用preg_replace()函數(shù),語法“preg_replace('/s+/','',$str)”。

      php怎么去掉字符串中的所有空格

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

      php去掉字符串中所有空格的方法

      • 使用 str_replace() 函數(shù)去掉所有空格

      • 使用 preg_replace() 函數(shù)去除所有空格

      1、使用 str_replace() 函數(shù)

      我們使用內(nèi)置函數(shù) str_replace() 來替換字符串或數(shù)組中的子字符串。替換后的字符串作為一個參數(shù)傳遞。使用該函數(shù)的正確語法如下。

      str_replace($searchString, $replaceString, $originalString, $count);

      內(nèi)置函數(shù) str_replace() 有四個參數(shù)。它的詳細參數(shù)如下

      參數(shù) 說明
      $searchString 強制 它是我們要查找和替換的子字符串或數(shù)組
      $replaceString 強制 它是我們要放在 $searchString 的位置的字符串。函數(shù)將檢查 $searchString 的出現(xiàn)情況,并用 $replaceString 替換。該函數(shù)將檢查 $searchString 的出現(xiàn)情況,然后用 $replaceString 替換它。它也可以是一個 array。
      $originalString 強制 它是原始的字符串,我們想從中找到一個子字符串或一個字符來替換。
      $count 可選 它告訴人們對 $originalString 進行替換的總次數(shù)

      這個函數(shù)返回所有替換后得到的最終字符串。

      下面的程序顯示了我們?nèi)绾问褂?str_replace() 函數(shù)從給定的字符串中刪除所有空格。

      <?php  header("Content-type:text/html;charset=utf-8"); $searchString = " "; $replaceString = ""; $originalString = "This is a programming tutorial";    $outputString = str_replace($searchString, $replaceString, $originalString);  echo "原字符串:".$originalString."<br>";   echo "去除空格后的字符串:".$outputString;     ?>

      php怎么去掉字符串中的所有空格

      我們傳遞了一個空格字符作為 $searchString 和一個空字符串作為 $replaceString。輸出將是沒有空格的字符串。

      現(xiàn)在,如果我們傳入 $count 參數(shù),函數(shù)將告訴我們這個字符串的替換次數(shù)。

      <?php  header("Content-type:text/html;charset=utf-8"); $searchString = " "; $replaceString = ""; $originalString = "This is a programming tutorial";    $outputString = str_replace($searchString, $replaceString, $originalString, $count);  echo "原字符串:".$originalString."<br>";   echo "去除空格后的字符串:".$outputString."<br>";  echo "替換字數(shù):".$count;  ?>

      php怎么去掉字符串中的所有空格

      2、使用 preg_replace() 函數(shù)

      也可以使用 preg_replace() 函數(shù)來刪除字符串中的所有空格。這個函數(shù)不僅可以刪除空格字符,還可以刪除字符串中的制表符。使用這個函數(shù)的正確語法如下。

      preg_replace($regexPattern, $replacementVar, $original, $limit, $count)

      函數(shù) preg_replace() 接受五個參數(shù). 它的詳細參數(shù)如下

      參數(shù) 說明
      $regexPattern 強制 它是我們將在原始字符串或數(shù)組中搜索的模式
      $replacementVar 強制 它是我們用來替換搜索值的字符串或數(shù)組
      $original 強制 它是一個字符串或數(shù)組,我們要從其中找到值并替換它。
      $limit 可選 這個參數(shù)限制了替換的數(shù)量
      $count 可選 這個參數(shù)告訴了我們對原始字符串或數(shù)組進行替換的總次數(shù)

      我們將使用模式 /s+/ 來查找空格。從字符串中刪除空格的程序如下。

      <?php  header("Content-type:text/html;charset=utf-8");  $originalString = "This is a programming tutorial";    $outputString = preg_replace('/s+/', '', $originalString);  echo "原字符串:".$originalString."<br>";   echo "去除空格后的字符串:".$outputString."<br>";  ?>

      php怎么去掉字符串中的所有空格

      我們知道這個字符串的總替換次數(shù)是 4,現(xiàn)在我們將限制替換次數(shù)。

      <?php  header("Content-type:text/html;charset=utf-8"); $searchString = " "; $replaceString = ""; $limit = 2; $originalString = "This is a programming tutorial";    $outputString = preg_replace('/s+/', '', $originalString,$limit);  echo "原字符串:".$originalString."<br>";   echo "去除空格后的字符串:".$outputString."<br>";   ?>

      php怎么去掉字符串中的所有空格

      可以看出只替換了兩次。

      推薦學習:《PHP視頻教程》

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