doujie7346 2014-03-20 16:39
浏览 32
已采纳

PHP不会以速记方式输出值

I have a weird issue where I am trying to use PHP in shorthand to output a value saved in the session. (Basically, if you type in a username and email address when signing up, but you get the email address wrong, instead of it clearing the username field it should persist and then you only have to recorrect the incorrect details.)

This is what I have for the output:

value="<?=$usern_value;?>"

Which is in my input:

<input type="text" id="inputUser" name="username" placeholder="Username" value="<?=$usern_value;?>" />

But it outputs this instead:

enter image description here

This is where the value of $usern_value is created:

<?php 
   if(isset($_SESSION['status']['register']['username'])){
        $usern_value = $_SESSION['status']['register']['username'];
   } else {
        $usern_value = "";
   }
?>
  • 写回答

5条回答 默认 最新

  • doutuo1939 2014-03-20 16:41
    关注

    Try like this

    value="<?php echo $usern_value;?>"
    

    Because may be shorthand is not enabled in your php version.I so you need to enable the short_open_tag option in the configuration file php.ini.You can try one of the following

    • set the directive short_open_tag = On in your php.ini (the recommended way);
    • call ini_set("short_open_tag", 1); in your code;
    • add the following line to your .htaccess file:

      php_value short_open_tag 1

    It's not recommend you use short tags (<? ?>). You should use the full length tags (<?php ?>). The short syntax is deprecated, and if you want to make your application portable, it's possible that short open tags are not allowed on another server and hence your application will break.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图