带有HTML标记的字符串中的变量PHP

时间:2016-03-01 01:23:01

标签: php html string

我需要将此字符串传递给HTML。我现在有这个:

  if(empty($_SESSION['usuario'])){
     $html = '<form class="form-inline formulario5" action="datos.php" enctype="multipart/form-data" method="post">
        <div class="form-group">
            <label for="user">Usuario</label>
            <input type="text" class="form-control" id="user" placeholder="" name="user"/>
        </div>
        <div class="form-group">
            <label for="password">Contraseña</label>
            <input type="password" class="form-control" id="password" placeholder="" name="password"/>
        </div>
        <button type="submit" class="btn btn-success">Log-In</button>
        </form>';
  }else{
        $html = '<h3><?$_SESSION['usuario']?></h3>';
  }

对于这个HTML:

<div class="container">
    <h1>Producto</h1>
    <h2 class="absorver">App</h2>
    <?echo $html?>
    <hr />
</div>

问题是我无法通过$ _SESSION传递$ html。

1 个答案:

答案 0 :(得分:0)

试试这个:

 if(empty($_SESSION['usuario'])){
 $html = '<form class="form-inline formulario5" action="datos.php" enctype="multipart/form-data" method="post">
    <div class="form-group">
        <label for="user">Usuario</label>
        <input type="text" class="form-control" id="user" placeholder="" name="user"/>
    </div>
    <div class="form-group">
        <label for="password">Contraseña</label>
        <input type="password" class="form-control" id="password" placeholder="" name="password"/>
    </div>
    <button type="submit" class="btn btn-success">Log-In</button>
    </form>';
}
else
{
    $sess = $_SESSION['usuario'];
    $html = "<h3>". $sess . "</h3>";
}