PHP变量从数组到函数

时间:2016-11-22 14:11:56

标签: php

<?
$dir4 = "report/";
$dh4  = opendir($dir4);
$giCity = geoip_open("geoip/GeoLiteCity.dat", GEOIP_STANDARD);
while (false !== ($filename4 = readdir($dh4))) {
    $files4[] = $filename4;
    sort($files4);
}
for ($p = 2; $p < count($files4); ++$p){
    ${"name" . $p} = pathinfo($files4[$p], PATHINFO_FILENAME);
    ${"idset" . $p} = substr("${"name" . $p}", 7, strpos("${"name" . $p} ", '-'));
    ${"soubor" . $p} = fopen("report/$files4[$p]", "r");
    ${"ipset" . $p}=fgets(${"soubor" . $p});
    ${"ipset2" . $p} = substr("${"ipset" . $p}", strpos("${"ipset" . $p}", ','));
    ${"ipset" . $p}= str_replace("${"ipset2" . $p}", "", "${"ipset" . $p}");
    ${"stav" . $p}=fgets(${"soubor" . $p});
    ${"ver" . $p}=fgets(${"soubor" . $p});
    ${"group" . $p}=fgets(${"soubor" . $p});
    ${"ipl" . $p}=fgets(${"soubor" . $p});
    ${"hw" . $p}=fgets(${"soubor" . $p});
    ${"stavh" . $p} = substr("${"stav" . $p}", 0, strpos("${"stav" . $p}", '['));
    ${"stav" . $p}= str_replace("${"stavh" . $p}", "", "${"stav" . $p}");
    fclose(${"soubor" . $p});
    //MAP loading START

    ${"record" . $p} = geoip_record_by_addr($giCity, ${"group" . $p});
    ${"lat" . $p} = ${"record" . $p}->latitude;
    ${"long" . $p} = ${"record" . $p}->longitude;


    ${"relace" . $p} = fopen("map.dat", "a");
    ${"text1" . $p} = '<script>';
    ${"text2" . $p} ='var showPosition = function (position) {';
    ${"text3" . $p} = 'var userLatLng = new google.maps.LatLng('."${"lat" . $p}".','."${"long" . $p}".');';
    ${"text4" . $p} = ' var marker = new google.maps.Marker({ position: userLatLng,title: \'BOT\',map: map });} ';
    ${"text5" . $p} = 'navigator.geolocation.getCurrentPosition(showPosition); </script>';
    fwrite(${"relace" . $p},"\n${"text1" . $p}");
    fwrite(${"relace" . $p},"\n${"text2" . $p}");
    fwrite(${"relace" . $p},"\n${"text3" . $p}");
    fwrite(${"relace" . $p},"\n${"text4" . $p}");
    fwrite(${"relace" . $p},"\n${"text5" . $p}");
    fclose(${"relace" . $p});
    ?>

此代码仅在变量为静态${"group" . $p}->$group="xxxxxxx";时起作用,但在读取时它将成功回显但不能与该函数一起使用${"group" . $p}函数在该变量中的作用与此无关。函数不想要接受数组作为字符串,这不是组[$ p]但不是空的,我不知道为什么函数只接受变量,如$ group =&#34; 54.112.55.111&#34 ;;在数组中相同,但它不起作用

0 个答案:

没有答案