3

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

3
  • 1
    Please share us the code you have tried. Commented Apr 15, 2016 at 11:11
  • @pupil I just fetching data using php 7 and mysqli . Here is variable to fetch all school names. E.G 1: Raichand_International....school. E.G 2: Latin_Girls__School** Now I want to replace comma* and **underscore Commented Apr 15, 2016 at 11:16
  • replace the comma and underscores with which character? your question made it sound like you wanted to replace them with your $school_name var. Commented Apr 15, 2016 at 11:52

3 Answers 3

3

Use str_replace like this

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

Hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

2

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

4 Comments

It's working but the is a other problem . E.G 1: Raichand_International..and..school I want to replace and to & . I was successfully replaced and but I can't echo &
Also preg_replace() useful to you.
can you write demo ?
I have written it in online editor you can check there. Click here. eval.in/553897 @GourabMazumder
0

Try this:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.