简体   繁体   中英

php replace special character from the variable value

I have a variable

$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

Use str_replace like this

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

Hope this helps.

Use str_replace function.

<?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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM