[英]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.