Chuyển code PHP sang VBA ? (1 người xem)

Liên hệ QC

Người dùng đang xem chủ đề này

Chuotdong

Thành viên thường trực
Tham gia
28/11/06
Bài viết
255
Được thích
60
Có cách nào để chuyển một code viết dạng file .PHP sang VBA không nhỉ, ví dụ như code sau:



<?php
/*
#
#
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
*/


$extension = pathinfo($_FILES["ppgpoine"]["name"]);

if ( ($extension['extension'] == "DAT") || ($extension['extension'] == "dat") )
{
//unexpected upload error
if ($_FILES["ppgpoine"]["error"] > 0)
{
echo "Error: " . $_FILES["ppgpoine"]["error"] . "<br />";
}
else
{
$handle = fopen($_FILES["ppgpoine"]["tmp_name"], "rb");
$contents = '';
while (!feof($handle)) {
$contents .= fread($handle, 8192);
}
fclose($handle);

//Convert to Hex
$contents = bin2hex( $contents );

//Find Header
$contents = str_replace("5050474e455f4d59504f495f3036303232322e52313200000000000000000000", "", $contents, $count);
if($count!=1)
{
echo "Error,wrong file format";
}
else
{
//store waypoint
$output="";

//Break them into each POI's size
$POI = str_split($contents, 856);

for($i=0;$i<count($POI);$i++)
{
//non null waypoint
if($POI[$i]!="00000000000000000000000000000000")
{
$legend = substr($POI[$i], 0, 8);
$longitude = substr($POI[$i], 8, 8);//E and W (-) 180
$latitude = substr($POI[$i], 16, 8);//N and S (-) 90
$title = substr($POI[$i], 24, 256);
$tel = substr($POI[$i], 280, 64);
$address = substr($POI[$i], 344, 256);
$note = substr($POI[$i], 600, 256);
//echo $legend. "<br />";
//echo get_coordinate($longitude). "<br />";
//echo get_coordinate($latitude). "<br />";
//echo get_ascii($title)."<br />";
//echo get_ascii($tel)."<br />";
//echo get_ascii($address)."<br />";
//echo get_ascii($note)."<br />";

#############################################################################
$description = "Telephone:\t".get_ascii($tel)."\nAddress:\t".get_ascii($address)."\nNote:\t".get_ascii($note);

//append to output
$output .= waypoint(get_ascii($title),get_coordinate($longitude),get_coordinate($latitude),$description,get_ascii($address));
}
else continue;
}
//merge waypoint with header and footer
output($output);
}
}
//Delete Temp File
unlink($_FILES["ppgpoine"]["tmp_name"]);
}
else
{
echo "Invalid file";
}
function get_filename()
{
$filename = getcwd()."/counter";

$handle = fopen($filename, "r");
$counter = fread($handle, filesize($filename));
fclose($handle);

$contents=$counter+1;

$handle = fopen($filename, "w");
fwrite($handle, $contents);
fclose($handle);

return $counter;
}

function get_ascii($data)
{
$string="";
$contents = str_split($data, 2);
for($i=0;$i<count($contents);$i+=2)
{
if($contents[$i]=="00")break;
$string .= chr( hexdec($contents[$i]) );
}
return $string;
}

function get_coordinate($data)
{
$contents = str_split($data, 2);
$location = ( hexdec($contents[0]) + ( hexdec($contents[1])*256 ) + ( hexdec($contents[2])*65536 ) + ( hexdec($contents[3])*16777216 ) )/1000000;

if($location>180)
$location = ( ( 255-hexdec($contents[0]) + ( ( 255-hexdec($contents[1]) )*256 ) + ( ( 255-hexdec($contents[2]) )*65536 ) + ( ( 255-hexdec($contents[3]) )*16777216 ) )/1000000 )*-1;

return $location;
}

function waypoint($name,$long,$lat,$long_desc,$short_desc)
{
$temp =
"
<Placemark>
<name>$name</name>
<styleUrl>#waypoint</styleUrl>
<description>
$long_desc
</description>
<Point>
<coordinates>$long,$lat,0.000000</coordinates>
</Point>
</Placemark>";

return $temp;
}

function output($file)
{
header("Content-Type: application/vnd.google-earth.kml+xml");
header("Content-Disposition: attachment; filename=\"".get_filename().".kml\";");
echo
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<kml xmlns=\"http://www.opengis.net/kml/2.2\">
<Document>
<name>GPS device</name>
<Snippet>Created ".date('D M d G:i:s Y')." - Converted at zyrax.net</Snippet>
<!-- Normal waypoint style -->
<Style id=\"waypoint_n\">
<IconStyle>
<Icon>
<href>http://maps.google.com/mapfiles/kml/pal4/icon61.png</href>
</Icon>
</IconStyle>
</Style>
<!-- Highlighted waypoint style -->
<Style id=\"waypoint_h\">
<IconStyle>
<scale>1.2</scale>
<Icon>
<href>http://maps.google.com/mapfiles/kml/pal4/icon61.png</href>
</Icon>
</IconStyle>
</Style>
<StyleMap id=\"waypoint\">
<Pair>
<key>normal</key>
<styleUrl>#waypoint_n</styleUrl>
</Pair>
<Pair>
<key>highlight</key>
<styleUrl>#waypoint_h</styleUrl>
</Pair>
</StyleMap>
<Folder>
<name>Waypoints</name>";
echo $file;
echo
"
</Folder>
</Document>
</kml>";
}
?>
 
Web KT

Bài viết mới nhất

Back
Top Bottom