Reputation: 13
I have an array session with emails - I try to echo them to the screen and I get nothing appearing.
$_SESSION['extralistids'] = array('<[email protected]>', '<[email protected]>', '<[email protected]>', '<[email protected]>', '<[email protected]>');
echo 'You have visited this page ' . $_SESSION['extralistids'][$_SESSION['counter']] . ' -for the first time.';
I use this and it outputs fine:
$_SESSION['extralistids'] = array('abc', 'def', 'ghi', 'jkl', 'def', 'ghi', 'jkl', 'def', 'ghi', 'jkl', 'def', 'ghi', 'jkl');
I've tried replacing single quotes with double quotes - no joy. I'm doing something obviously wrong here but can't seem to spot the mistake - any thoughts where I am going wrong?
Upvotes: 1
Views: 42
Reputation: 780655
Assuming you're displaying this on a web page, you need to do:
echo 'You have visited this page ' . htmlentities($_SESSION['extralistids'][$_SESSION['counter']]) . ' -for the first time.';
because <
and >
have special meaning in HTML. The browser is treating <[email protected]>
as an HTML tag, not text to display. htmlentities
will translate that to <[email protected]>
, and then it will display as intended.
Upvotes: 1
Reputation: 219794
Nothing appears because they are wrapped in brackets (<
and >
.) which makes them look like HTML. You need to use htmlentities()
when echoing out those values so the brackets are displayed as entities and not interpreted as HTML characters.
echo 'You have visited this page ' . htmlentities($_SESSION['extralistids'][$_SESSION['counter']]) . ' -for the first time.';
Upvotes: 1