PHP:将HTML生成为纯文本并放入文本框问题
PHP: Generate HTML as plaintext and put in a textbox issue
在这里引用上一个问题
现在我遇到了一些问题,即使回复产生了预期的结果。
我得到了这 3 页:
Page1.php
// This page contain two columns, one for the form that take the
variables, and other one that contain the iframe that must to display the plaintext
Page2.php
// Cutted code that take $_GET variables and store in $_SESSION
$html = file_get_contents('page3.php');
echo '<textarea readonly style="border:none;resize:none" rows="50" cols="116" value="'. $html .'"></textarea>';
Page3.php
// This is the file page3.php that must to be in plaintext, but first
it must take the variables from $_SESSION and complete the code
现在我得到了纯文本文件,但是变量没有被传递,因为我已经将它们存储在会话中。我得到了 $var 而不是值。
并且文本框只显示文件的一半,不显示 <link>
和整个 <style>
标签。
<textarea>
没有value
.
您需要在标签内回显该变量。
$html = "Text here";
echo '<textarea readonly style="border:none;resize:none" rows="50" cols="116">'. $html .'</textarea>';
"it must take the variables from $_SESSION and complete the code"
另请注意,您使用的是 sessions。确保 session 开始时在该页面的顶部有 session_start();
,对于可能使用 session 的任何其他页面。
示例:
session_start();
if(isset($_SESSION['var'])){
$_SESSION['var'] = "var";
}
else{
echo "Session is not set.";
}
N.B.: 确保你在header.
之前没有输出
如果收到 headers 发送 notice/warning,请在 Stack 上查阅以下内容:
将 error reporting 添加到您的文件的顶部,这将有助于查找错误。
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Then the rest of your code
旁注:显示错误只应在暂存阶段进行,绝不能在生产阶段进行。
测试成功的例子,回显var
inside <textarea>
:
<?php
session_start();
if(isset($_SESSION['var'])){
$_SESSION['var'] = "var";
$var = $_SESSION['var'];
}
else{
echo "Session is not set.";
}
// $html = "Text here";
$html = $var;
echo '<textarea readonly style="border:none;resize:none" rows="50" cols="116">'. $html .'</textarea>';
编辑:
根据以下模型将 GET 数组分配给 sessions 个数组。
<?php
session_start();
$_GET ['lb1'] = "lb1";
$lb1 = $_GET ['lb1'];
$_GET ['lb1'] = $_SESSION["lb1"];
$_SESSION["lb1"] = $lb1;
//echo "Hey LB1 " . $lb1;
$lb1_session = $lb1;
$_GET ['lb2'] = "lb2";
$lb2 = $_GET ['lb2'];
$_GET ['lb2'] = $_SESSION["lb2"];
$_SESSION["lb2"] = $lb2;
//echo "Hey LB2" . $lb2;
$lb2_session = $lb2;
$html = $lb1_session . "\n". $lb2_session;
echo '<textarea readonly style="border:none;resize:none" rows="50" cols="116">'. $html .'</textarea>';
?>
<a href="check_get_sessions.php">Check GET sessions</a>
check_get_sessions.php
<?php
session_start();
if(isset($_SESSION['lb1'])){
$lb1_session = $_SESSION['lb1'];
echo $lb1_session;
}
if(isset($_SESSION['lb2'])){
$lb2_session = $_SESSION['lb2'];
echo $lb2_session;
}
$html = $lb1_session . "\n". $lb2_session;
echo '<textarea readonly style="border:none;resize:none" rows="50" cols="116">'. $html .'</textarea>';
这是我能给你的最好的了。
做 $html = $lb1_session . "\n". $lb2_session;
你可以使用 "\n"
作为每个要回显的变量之间的分隔符。或者,如果需要,<br>
;选择权在你。
上面将$html
变量分配给链式变量。您可以添加其他可能需要添加的$lb3, $lb4, $lb5
等
祝你好运! (好运)
在这里引用上一个问题
现在我遇到了一些问题,即使回复产生了预期的结果。
我得到了这 3 页:
Page1.php
// This page contain two columns, one for the form that take the
variables, and other one that contain the iframe that must to display the plaintext
Page2.php
// Cutted code that take $_GET variables and store in $_SESSION
$html = file_get_contents('page3.php');
echo '<textarea readonly style="border:none;resize:none" rows="50" cols="116" value="'. $html .'"></textarea>';
Page3.php
// This is the file page3.php that must to be in plaintext, but first
it must take the variables from $_SESSION and complete the code
现在我得到了纯文本文件,但是变量没有被传递,因为我已经将它们存储在会话中。我得到了 $var 而不是值。
并且文本框只显示文件的一半,不显示 <link>
和整个 <style>
标签。
<textarea>
没有value
.
您需要在标签内回显该变量。
$html = "Text here";
echo '<textarea readonly style="border:none;resize:none" rows="50" cols="116">'. $html .'</textarea>';
"it must take the variables from $_SESSION and complete the code"
另请注意,您使用的是 sessions。确保 session 开始时在该页面的顶部有 session_start();
,对于可能使用 session 的任何其他页面。
示例:
session_start();
if(isset($_SESSION['var'])){
$_SESSION['var'] = "var";
}
else{
echo "Session is not set.";
}
N.B.: 确保你在header.
之前没有输出如果收到 headers 发送 notice/warning,请在 Stack 上查阅以下内容:
将 error reporting 添加到您的文件的顶部,这将有助于查找错误。
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Then the rest of your code
旁注:显示错误只应在暂存阶段进行,绝不能在生产阶段进行。
测试成功的例子,回显var
inside <textarea>
:
<?php
session_start();
if(isset($_SESSION['var'])){
$_SESSION['var'] = "var";
$var = $_SESSION['var'];
}
else{
echo "Session is not set.";
}
// $html = "Text here";
$html = $var;
echo '<textarea readonly style="border:none;resize:none" rows="50" cols="116">'. $html .'</textarea>';
编辑:
根据以下模型将 GET 数组分配给 sessions 个数组。
<?php
session_start();
$_GET ['lb1'] = "lb1";
$lb1 = $_GET ['lb1'];
$_GET ['lb1'] = $_SESSION["lb1"];
$_SESSION["lb1"] = $lb1;
//echo "Hey LB1 " . $lb1;
$lb1_session = $lb1;
$_GET ['lb2'] = "lb2";
$lb2 = $_GET ['lb2'];
$_GET ['lb2'] = $_SESSION["lb2"];
$_SESSION["lb2"] = $lb2;
//echo "Hey LB2" . $lb2;
$lb2_session = $lb2;
$html = $lb1_session . "\n". $lb2_session;
echo '<textarea readonly style="border:none;resize:none" rows="50" cols="116">'. $html .'</textarea>';
?>
<a href="check_get_sessions.php">Check GET sessions</a>
check_get_sessions.php
<?php
session_start();
if(isset($_SESSION['lb1'])){
$lb1_session = $_SESSION['lb1'];
echo $lb1_session;
}
if(isset($_SESSION['lb2'])){
$lb2_session = $_SESSION['lb2'];
echo $lb2_session;
}
$html = $lb1_session . "\n". $lb2_session;
echo '<textarea readonly style="border:none;resize:none" rows="50" cols="116">'. $html .'</textarea>';
这是我能给你的最好的了。
做 $html = $lb1_session . "\n". $lb2_session;
你可以使用 "\n"
作为每个要回显的变量之间的分隔符。或者,如果需要,<br>
;选择权在你。
上面将$html
变量分配给链式变量。您可以添加其他可能需要添加的$lb3, $lb4, $lb5
等
祝你好运! (好运)