[英]php replace special character from the variable value
I have a variable 我有一个变量
$school_name; $ school_name;
It's fetching many data from the server and I want to replace comma , underscore and dash to the variable value and echo but the problem is I can't replace it Please support for fix the bug Thank you 它从服务器获取许多数据,我想用变量值和echo替换逗号 , 下划线和破折号 ,但问题是我无法替换它请支持修复bug谢谢
Use str_replace like this 像这样使用str_replace
$result = str_replace(array(',','-','_'), $shool_name, $yourStringFromServer);
Hope this helps. 希望这可以帮助。
Use str_replace function. 使用str_replace函数。
<?php
$result = "GOOD_AFTERNOON-TODAY,FINE";
$shool_name = "test";
$result = str_replace(array(',','-','_'), $shool_name, $result );
echo $result;
?>
output 产量
GOODtestAFTERNOONtestTODAYtestFINE
Check in Editor: Click Here 签入编辑器: 单击此处
For AND replace with &. 用&替换为&。
<?php
$result = "Raichand_International..and..school";
$shool_name = "&";
$result = str_replace(array('and'), $shool_name, $result );
echo $result;
?>
output 产量
Raich&_International..&..school
试试这个:
str_replace(array(',','_','-'), $shool_name, $result);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.