Search code examples
phpdrupal-7

I want to change the value of a string


I have a string that has value Grade 1.I want to change it to grade_1

here is my code.

         $gradeselection="Grade 1";          //it is getting value from a select box .this is just for understanding.

I have used preg_replace but not getting the solution.


Solution

  • Instead of preg_replace you can use str_replace
    try this one

    echo str_replace("Grade 1","grade_1",$gradeselection);