[英]php replace special character from the variable value
我有一个变量
$ school_name;
它从服务器获取许多数据,我想用变量值和echo替换逗号 , 下划线和破折号 ,但问题是我无法替换它请支持修复bug谢谢
像这样使用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
签入编辑器: 单击此处
用&替换为&。
<?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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.