duanchun2349 2014-12-21 16:41
浏览 115
已采纳

php urlencode不起作用或者是别的东西

I am trying my hand in PHP and got stuck with the urlencode. Please see the two code

first document@

<HTML>
   <HEAD>
      <TITLE>My Movie Site</TITLE>
   </HEAD>
   <BODY>
    <?php 

    // delete as per page 34 define ('FAVMOVIE', 'The life of Brian'); 
    echo    'My favorite movie is ';
    echo    $_GET['favmovie'];
    echo '<br/>';
    $movierate = 5;
    echo 'My movie rating for this movie is: ';
    echo $movierate;
    ?>

   </BODY>
</HTML>

Second document

<HTML>

   <HEAD>

   <TITLE>Find my Favorite Movie!</TITLE>

   </HEAD>

   <BODY>
            <?php 

                $myfavmovie = urlencode ('Life of Brian');
                echo    '<a href = "http://php.aryapratinidhisabha.org.uk?favmovie=$myfavmovie\">'  ;
                echo    'Click here to see information about my favorite movie!' ;
                echo    '</a>'  ;

            ?>

   </BODY>

</HTML>

I am getting the following result all the time:

In the first line: "My favorite movie is $myfavmovie\"

In the second line: "My movie rating for this movie is: 5"

My questoins are:

  1. Why am I not getting in the first line: "My favorite movie is Life of Brian"?
  2. The book says that in the url the result should be "http://php.aryapratinidhisabha.org.uk/?favmovie=$Life+of+Brian instead it gives this http://php.aryapratinidhisabha.org.uk/?favmovie=$myfavmovie. Why is that?

Thanks,

Naveen

  • 写回答

2条回答 默认 最新

  • dqu3974 2014-12-21 16:42
    关注

    You should use double apostrophes. Variables aren't evaluated between single ones.

    This way:

    echo    "<a href = \"http://php.aryapratinidhisabha.org.uk?favmovie=$myfavmovie\">"  ;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 VB.NET2022如何生成发布成exe文件
  • ¥30 matlab appdesigner私有函数嵌套整合
  • ¥15 给我一个openharmony跑通webrtc实现视频会议的简单demo项目,sdk为12
  • ¥15 vb6.0使用jmail接收smtp邮件并另存附件到D盘
  • ¥30 vb net 使用 sendMessage 如何输入鼠标坐标
  • ¥15 关于freesurfer使用freeview可视化的问题
  • ¥100 谁能在荣耀自带系统MagicOS版本下,隐藏手机桌面图标?
  • ¥15 求SC-LIWC词典!
  • ¥20 有关esp8266连接阿里云
  • ¥15 C# 调用Bartender打印机打印