0

I need to "escape" certain characters in a string variable. My approach is to split the string into an array by a single char, loop over array and if the char matches special char, add "\" in front of it. But some part of the following code is incorrect and it crashes the page.

$arrayInput = str_split($newInput);
$command = "";

foreach($arrayInput as $character) {
    echo "$character";
    if($character == "<"){
        $character = "\<"
    } else if ($character == ">")  {
        $character = "\>"
    } else {
    }
    command += $character;
} 
user1418018
  • 189
  • 1
  • 4
  • 17

0 Answers0