0

I'm using the following function:

<body onload="testing(<?php print "'". $_SESSION['data'] . "'"; ?>);">

if $_SESSION['data'] = "My name is function" then it works fine but

if $_SESSION['data'] = "Calling jackson's function" then it gives error.

Can you tell me how can i pass an argument which may contain characters like

$_SESSION['data'] = "Calling jackson's function"

into the testing function parameters.

2 Answers 2

2

Escape them with addslashes()

echo "'" . addslashes($_SESSION['data']) . "'";
Sign up to request clarification or add additional context in comments.

Comments

1

You could do:

<body onload="testing(<?php print "'". addslashes($_SESSION['data']) . "'"; ?>);">

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.