1

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?

2 Answers 2

1

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 &lt;[email protected]&gt;, and then it will display as intended.

Sign up to request clarification or add additional context in comments.

Comments

1

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.';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.