Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> PHP

Xóa dấu phẩy từ chuỗi trong PHP

Để xóa dấu phẩy, dùng thay thế. Dùng str_replace() trong PHP.

Giả sử chuỗi có dấu phẩy:

$name = "John,Smith";

Kết quả sau xóa dấu phẩy:

JohnSmith

Ví dụ

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

Kết quả

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