简体   繁体   English

打印PHP代码

[英]print the php code

i want to simple like this 我想这样简单

echo "$_POST['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 参考: http : //php.net/manual/en/language.types.string.php

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

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

If you have a variable $x='abc' and you do 如果您有一个变量$ x ='abc'并且

echo '$x' it prints $x echo '$x'它打印$x

and if you do 如果你这样做

echo "$x" it prints abc echo "$x"它打印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. 有关更多信息,请参见http://php.net/manual/en/function.echo.php

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. 当使用双引号时,PHP将尝试在字符串内部扩展变量引用。 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. 您也可以使用单引号防止变量扩展,但是如果您需要实际打印单引号,则需要使用反斜杠来转义单引号。

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. 如果您希望它不错,可以在它周围加上<pre></pre>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM