1

I have a string variable which also has some PHP code in it. The code in the string var is getting run whenever I am displaying the string with echo. Is there anything (function) which can escape the meaning of PHP code while I use it with string?

Please help?

2
  • Could you post your code? Echoing the php code should not execute it. Commented Jul 1, 2010 at 10:37
  • I got confuse actually, that code had a meta tag refresh, which was executing and page was getting loaded whenever I try to load that page. It's fixed, what a silly mistake. Yes you guys are right, we can't execute php code in echo. Anyways, thank you all guys. Commented Jul 6, 2010 at 10:05

3 Answers 3

4

Using single quotes

echo 'foo is $foo'; 

will return foo is $foo

For more references: http://php.net/manual/en/function.echo.php

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

Comments

2

If you are already outputting the string, you might want to substitute echo for:

1 Comment

very interesting, cookie for you.
0

You can't execute PHP code by echo it to web browser by HTTP.

I mean you think about HTML, you can use htmlspecialchars to escape html code and print it without parse by browser like a HTML code.

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.