php urlencode htmlentities问题

时间:2014-12-08 22:08:30

标签: php urlencode html-entities

我收到了一个错误:

Warning: include(friday_set.php?x=First+Set&y=2): failed to open stream: No such file or directory in...

当我转到我的网址时 - > “friday_set.php?x = First + Set& y = 2”一切都应该出现了

我理解主要原因是我没有正确编码网址,网址无法量化字符串中的&

我的代码就是这个(类似于php manual中所描述的):

<?php
 $sel_name = 'First Set';
 $admin_id = '2';

   $query_string = 'x=' . urlencode($sel_name) . "&y=" . urlencode($admin_id);
   include ("friday_set.php?" . htmlentities($query_string));
?>

我似乎无法发现问题......任何人都有解决方案吗?

1 个答案:

答案 0 :(得分:1)

而不是解析文件URL中的变量我建议:

<?php
 $sel_name = 'First Set';
 $admin_id = '2';

   include ("friday_set.php");
?>

friday_set.php内检查直接网址为$_GET[x]或包含$sel_name

if(isset($_GET['x'])){
$sel_name=$_GET['x'];
}//else $sel_name  is just $sel_name unless you want to check its populated also