從 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
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP