php替换变量值中的特殊字符


php replace special character from the variable value

我有一个变量

$school_name;

它正在从服务器获取许多数据,我想将逗号下划线短划线替换为变量值和echo但是问题是我无法替换它请支持修复错误感谢

像这个一样使用str_replace

$result = str_replace(array(',','-','_'), $shool_name, $yourStringFromServer);

希望这能有所帮助。

使用str_replace函数。

<?php
$result = "GOOD_AFTERNOON-TODAY,FINE";
$shool_name = "test";
$result = str_replace(array(',','-','_'), $shool_name, $result );
echo $result;
?>

输出

GOODtestAFTERNOONtestTODAYtestFINE

报到编辑器:单击此处

对于AND,请替换为&

<?php
$result = "Raichand_International..and..school";
$shool_name = "&";
$result = str_replace(array('and'), $shool_name, $result );
echo $result;
?>

输出

Raich&_International..&..school

试试这个:

str_replace(array(',','_','-'), $shool_name, $result);