從 PHP 中的字串中刪除逗號?


要刪除逗號,可以替換它。要替換,請在 PHP 中使用 str_replace()。

假設以下是我們帶有逗號的輸入字串 

$name="John,Smith";

我們希望刪除上述字串中的逗號後的輸出是 

JohnSmith

示例

PHP 程式碼如下

 即時演示

<!DOCTYPE html>
<html>
<body>
<?php
$name="John,Smith";
$result = str_replace(',', '', $name);
echo "The actual value is=",$name,"<br>";
echo "After removing the comma(,)=",$result,"<br>";
?>
</body>
</html>

輸出

將產生以下輸出

The actual value is=John,Smith
After removing the comma(,)=JohnSmith

更新於:13-Oct-2020

10K+ 瀏覽量

開啟你的職業生涯

完成課程取得認證

開始吧
廣告
© . All rights reserved.