douxiong0668 2016-11-22 14:11 采纳率: 100%
浏览 33

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},"
${"text1" . $p}");
    fwrite(${"relace" . $p},"
${"text2" . $p}");
    fwrite(${"relace" . $p},"
${"text3" . $p}");
    fwrite(${"relace" . $p},"
${"text4" . $p}");
    fwrite(${"relace" . $p},"
${"text5" . $p}");
    fclose(${"relace" . $p});
    ?>

This Code works only if variable is static ${"group" . $p}->$group="xxxxxxx"; but when is reading by for it will sucessfully echo but will not work with that function ${"group" . $p} function is acting like nothing in that variable.function dont want accept array as string and this not too group[$p] but is not empty ,i dont know why function is accepting only variables like $group = "54.112.55.111"; in array is same but its not working

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
    • ¥20 西门子S7-Graph,S7-300,梯形图
    • ¥50 用易语言http 访问不了网页
    • ¥50 safari浏览器fetch提交数据后数据丢失问题
    • ¥15 matlab不知道怎么改,求解答!!
    • ¥15 永磁直线电机的电流环pi调不出来
    • ¥15 用stata实现聚类的代码
    • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
    • ¥20 docker里部署springboot项目,访问不到扬声器
    • ¥15 netty整合springboot之后自动重连失效