开发者

print the php code

i want to simple like this

echo "$_POS开发者_高级运维T['id']" . $_POST['id'];

so how can i print this string and its value.


echo '$_POST[\'id\']' . $_POST['id'];

Single quotes ' print a literal string, variables within double quotes " are evaluated. Note that you have to escape single quotes within a single quoted string.

Alternatively escape the variable within double quotes to prevent it from being evaluated:

echo "\$_POST['id']" . $_POST['id'];

Reference: http://php.net/manual/en/language.types.string.php


echo '$_POST["id"]' . $_POST['id']

If you have a variable $x='abc' and you do

echo '$x' it prints $x

and if you do

echo "$x" it prints abc

Simply put, whatever variables you put into the double quotes get replaces by their values. If you use simple quotes the variables are not replaced.

See http://php.net/manual/en/function.echo.php for more information.


Any of these will basically do what you want:

echo "\$_POST['id']" . $_POST['id'];

echo '$_POST[\'id\']' . $_POST['id'];

echo '$_POST["id"]' . $_POST['id'];

When you use double-quotes, PHP will try to expand variable references inside of the string. You can prevent variable expansions by using backslash to escape the dollar-sign part of the variable reference.

You can also use single-quotes to prevent variable expansions but if you need to actually print a single-quote then you need to use backslash to escape the single-quote.


echo '$_POST[\'id\']' . $_POST['id'];


This doesn't specifically answer your question, but do you know about this?

print_r($_POST);

If you are just looking for some simple way to help you debug, this is very useful. If you want it nice, you can put <pre></pre> around it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜