1

私は名前のリストを持っているページtest.phpを持っています:

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

別のページtest1.php?id=name2では、結果は次のようになります。

332345

私はこのPHPコードを試しました:

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

コードがこのように使用されている場合

<?php 
    $Text=file_get_contents("test.php")
    ;preg_match_all('/name3=\'([^\']+)\'/',$Text,$Match); 
    $fid=$Match[1][0]; 
    echo $fid; ?>

結果は良好です

558645

しかし、結果が bee の場合、このように GET メソッドで'/name3=\'fromの名前を変更できるようにしたいです。;preg_match_all('/name3=\'([^\']+)\'/',$Text,$Match)test1.php?id=name4434544

4

2 に答える 2

0

このコードを試してください:

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

これは機能します。

編集:

<?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 "There is no name selected.";
}

 ?>
于 2013-04-30T07:16:52.547 に答える