Я столкнулся с некоторыми проблемами здесь.Во-первых, я создал форму, форму даты.Предлагая пользователю ввести дату в. После чего, используя функцию, чтобы прочитать дату и поместить маркер в Google Map API.В рамках которого мне дали файл журнала (report.txt), я хотел бы использовать функцию, чтобы «поймать» ту же дату (в файле журнала), а затем получить IP-адрес в ней, используя веб-службы для полученияlat & long и поместите маркер в Google Map API.
PS, я знаю, это звучит сложно, но в конце концов, я просто хотел бы знать, как я могу «сопоставить» дату (функцию, которую я создал) с датой (в файле журнала)а затем grep IP-адрес.Спасибо!
Ниже мой код.
<script type="text/javascript">
var locations = [[0,0],[1,1]];
<?php
//opening the report.txt
$report = fopen('C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\report.txt', 'r') or exit("Unable to open report.txt");
//while not the end of the file
while(!feof($report))
{
//if the fgets($report) which is a line in the file matches the regular expression, the matched text will be stored into $matches, which is an array.
if (preg_match("/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/", fgets($report), $matches))
{
//opening a URL now, joining the IP address with a part of the URL to call the web service, and reading it
$ipaddrloc = fopen('http://freegeoip.appspot.com/json/'.$matches[0], 'r');
//while not the end of the page
while(!feof($ipaddrloc))
{
$var = fgets($ipaddrloc); //a line of the page, what is returned is in JSON format
$lat = json_decode($var)->latitude; //the "latitude part" of the returned info
$long = json_decode($var)->longitude; //the "longitude part" of the returned info
print "locations.push([".$lat.",".$long."]);"; //push both the values into the array that you created
}
}
}
fclose($report); //close the report.txt
fclose($ipaddrloc); //close the URL
?>
</script>
<head>
//Read date value
function checkDate(Date)
{
var date = /^(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$/;
if (date.test(Date))
{
for (var i = 0; i < locations.length; i++) {
new google.maps.Marker({
position: new google.maps.LatLng(locations[i][0], locations[i][1]),
map: map,
title:"Specified Location"
});
}
}
else
{
alert("Invalid Date");
}
}
</head>
<body>
<form onsubmit ="return false;">
<input type="text" name="Date" placeholder="YYYY-MM-DD">
<input type="button" value="Search Date" onclick="checkDate(this.form.Date.value);">
</form>
</body>