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

Cách xóa ký tự (') trong mảng chuỗi và hiển thị kết quả trong một chuỗi PHP

Giả sử mảng chuỗi:

$full_name = '["John Doe","David Miller","Adam Smith"]';

Muốn đầu ra chuỗi đơn:

John Doe, David Miller, Adam Smith

Dùng json_decode().

Ví dụ

<!DOCTYPE html> <html> <body> <?php 
$full_name = '["John Doe","David Miller","Adam Smith"]';
$full_name = json_decode($full_name);
$filterData = array_filter(array_map('trim', $full_name));
$output = implode(', ', $filterData);
echo "The Result in one string=", $output;
?> </body> </html>

Kết quả

The Result in one string=John Doe, David Miller, Adam Smith