在我开始我的大学项目之前,我想知道是否有一种方法可以将PHP文件中的PHP变量提取到Android中?
服务器上有一个PHP文件,其中包含我想要的所有变量。显然,您可以将文件上传到设备上,但是有没有办法提取该文件中的所有变量?
我需要的所有值都在该PHP文件中。在所有变量之前有几行代码。
我不能修改PHP文件,因为它已经由其他地方的另一个程序生成。该文件的名称始终相同。有没有人能给我指个方向?
所以我有一个包含变量的PHP文件,下面是实际的前几行:
<?php>
if ( isset($_REQUEST['sce']) && strtolower($_REQUEST['sce']) == 'view' ) {
//--self downloader --
$filenameReal = __FILE__;
$download_size = filesize($filenameReal);
header('Pragma: public');
header('Cache-Control: private');
header('Cache-Control: no-cache, must-revalidate');
header("Content-type: text/plain");
header("Accept-Ranges: bytes");
header("Content-Length: $download_size");
header('Connection: close');
readfile($filenameReal);
exit;
}
// General OR Non Weather Specific/SUN/MOON
// ========================================
$time = '19:20'; // current time
$date = '22/12/14'; // current date
$sunrise = '08:04'; // sun rise time (make sure you have the correct lat/lon
// in view/sun moon)
$time_minute = '20'; // Current minute
$time_hour = '19'; // Current hour
$date_day = '22'; // Current day
$date_month = '12'; // Current month
$date_year = '2014'; // Current year
$monthname = 'December'; // Current month name
$dayname = 'Monday'; // Current day name
$sunset = '15:53'; // sunset time
$moonrise = '07:56'; // moon rise time
$milestokm = 1.609344; // to convert miles to kms
.
.
.and many more...
?>
我希望在屏幕上显示所有这些变量,而不是所有变量。他们中的一些。
发布于 2014-12-28 19:35:47
PHP只能在服务器上运行,如果你想从服务器上获取值,那么它需要以任何方式公开。例如,REST端点。现在假设您的服务器已启动并运行,在android应用程序中,您需要向端点发出HTTP请求以公开这些值。这样你就可以得到值了。
我必须说你应该学习关于web的概念,从PHP复制值不会得到值。还可以通过以下链接了解REST端点的公开方式:http://coreymaynard.com/blog/creating-a-restful-api-with-php/
这就是安卓应用程序使用rest客户端通过http://www.techrepublic.com/blog/software-engineer/calling-restful-services-from-your-android-app/使用这些端点的方式
https://stackoverflow.com/questions/27675960
复制相似问题