简体   繁体   English

如何将带有php标记的字符串放入php变量?

[英]How to put a string with a php tag into a php variable?

I want to include 我想包括

action="<?php echo $_SERVER['PHP_SELF']; ?>"

in $render_form variable. 在$ render_form变量中。 But the following code does not work: 但是以下代码不起作用:

<?php $render_form = '<form method="post" action="<?php echo 
  $_SERVER['PHP_SELF']; ?>">
  <input type="text" name="name">
  <br>
  <input type="submit" name="submit" value="Submit Form">
  <br> 
  </form>'; 
?>

The following code (without php tag) works: 以下代码(不带php标记)有效:

<?php $render_form = '<form method="post" action="">
  <input type="text" name="name">
  <br>
  <input type="submit" name="submit" value="Submit Form">
  <br>
  </form>'; 
?>

If I understood you, this should fit your issue 如果我了解您,这应该适合您的问题

<?php $render_form = '<form method="post" action="'. $_SERVER['PHP_SELF'] .'">
  <input type="text" name="name">
  <br>
  <input type="submit" name="submit" value="Submit Form">
  <br> 
  </form>'; 
?>

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

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