Php 从字符串中删除“,”

Php 从字符串中删除“,”,php,Php,我想从字符串中删除 $x="123,456,789"; for($i=0; $i<10; $i++){ if($x[$i]==",") $x[$i]=""; } echo $x; //123456789 (Correct) echo "<input type='text' value='$x'/>" //123?456?789 (Wrong) 它会打印吗?在黑匣子中,而不是 请参见此图,为循环设置沟渠: $x = str_replace (',','',$x);

我想从字符串中删除

$x="123,456,789";
for($i=0; $i<10; $i++){
    if($x[$i]==",") $x[$i]="";
}
echo $x; //123456789 (Correct)

echo "<input type='text' value='$x'/>" //123?456?789 (Wrong)
它会打印吗?在黑匣子中,而不是

请参见此图,为循环设置沟渠:

$x = str_replace (',','',$x);

我不知道你是否真的在这里使用for循环

只需使用替换来替换搜索的所有匹配项

$x = str_replace (',', '', $x);
无论如何,如果您只想显示数字,并且想去掉所有其他内容,请使用:

上面的行用空字符串替换除0-9之外的所有内容

$x="123,456,789"; 
$pattern = '/,/'; 
$replace = ''; 
$x= preg_replace($pattern, $replace, $x);
echo $x;

简单使用

$x = str_replace(',', '', $x); 
echo $x;

使用str_替换“,”,$x;他刚造了一台鲁布·戈德伯格机器。美好的保存一些谷歌搜索,伙计们:你的循环,但你仍然应该使用str_替换。str_替换比preg_替换快。
     $x = str_replace (',','',$x);
     echo $x;
$x = str_replace(',', '', $x); 
echo $x;