简体   繁体   中英

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. 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 $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>'; 
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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