Search code examples
phphtmlvar-dump

Unexpected output of var_dump when string contains html


I have an if statement that looks like this:

if($benchmark_one_name2 === "Russell 1000 Index"){
    $benchmark_one_name2 = "<span class='first'>Russell 1000 Index</span>";
    var_dump("this if statement is true");
}
var_dump($benchmark_one_name2);die;

Then I var_dump the value of $benchmark_one_name2 right after to see if it has been set to "<span class='first'>Russell 1000 Index</span>", but instead i get back this when I check the page:

string(25) "this if statement is true" string(45) "Russell 1000 Index" 

I think it might have something to do with the HTML inside the string, but can't seem to find anything indicating that.


Solution

  • It's outputting the value as you expect, but your browser is parsing the output as HTML. If you inspect the document you will see:

    string(25) "this if statement is true"
    string(45) "<span class="first">Russell 1000 Index</span>"