-1

我有一个页面 test.php,其中有一个名称列表:

name1=992345&name2=332345&name3=558645&name4=434544

在另一个页面 test1.php?id=name2 ,结果应该是:

33234

我试过这个 PHP 代码:

<?php 
$Text=file_get_contents("test.php");
if(isset($_GET["id"])){
   $id = $_GET["id"];
   $regex = "/".$id."=\'([^\']+)\'/";
   preg_match_all($regex,$Text,$Match); 
   $fid=$Match[1][0]; 
   echo $fid; 
} else {
   echo "";
}

 ?>

但它不起作用。

如果列表与''

name1='992345'&name2='332345'&name3='558645'&name4='434544'

有用。如何改变工作?

4

2 回答 2

2
parse_str($Text,$data);
echo $data[$_GET["id"]];

parse_str

于 2013-05-24T14:12:57.510 回答
-1
<?php 
  $Text=file_get_contents("test.php");
  if(isset($_GET["id"])){
     $id = $_GET["id"];
     parse_str($Text,$data);
     echo $data[$id];
  } else {
     echo "";
  }

?>

这段代码应该可以工作。

于 2013-05-24T14:24:51.267 回答