Reputation: 131
I have the following code:
$name = "<test>";
$msg = "Hi $name Hope your feeling well today";
print_r ($msg);
The problem is, it will print Hi Hope your feeling well today
and skip the $name
When I tried it this way:
$name = "<test>";
$msg = "Hi ".$name." Hope your feeling well today";
print_r ($msg);
it also printed the same.
When I tried it as:
$name = "<test>";
$msg = 'Hi $name Hope your feeling well today';
print_r ($msg);
it printed Hi $name Hope your feeling well today
I need a solution so that the variable $name
will be printed as it is if starting with <
or any other PHP related code.
Upvotes: 2
Views: 54
Reputation: 219874
View the source of your web page. It is there. You don't see it because it is in brackets which the browser interprets as HTML. Since HTML tags are interpreted and not displayed, you don't see that content.
To display those brackets, you need to convert them into HTML entities. You can use the aptly named htmlentities()
function to do that.
$name = "<test>";
$msg = "Hi $name Hope your feeling well today";
echo htmlentities($msg, ENT_NOQUOTES, 'UTF-8');
Upvotes: 3