I have a code of php:

我有一个PHP的代码:

<?php
include('simple_html_dom.php');

$sContent = file_get_contents('http://iztv.com.tr/yayinakisiGunler.aspx?id=1');

$DOM = str_get_html($sContent);   

foreach($DOM -> find('table tr') as $tr)
{
    $saat = $tr -> find('td', 0)->innertext;
    $program = $tr -> find('td', 1)->innertext;
    $rating = $tr -> find('td', 2) -> find('img', 0);
    if($rating)
    {
        $rating = $tr -> find('td', 2) -> find('img', 0) -> src;
    }
    $yayintipi = $tr -> find('td', 2) -> find('img', 1);
    if($yayintipi)
    {
       $yayintipi = $tr -> find('td', 2) -> find('img', 1)->src;
    }
    $detay = $tr -> find('td', 3) -> find('a', 0);
    if($detay)
    {
        $detay = $tr -> find('td', 3) -> find('a', 0) -> href;
    }

    $arr['saat'] = $saat;
    $arr['program adi'] = $program;
    $arr['rating'] = $rating;
    $arr['yayin tipi'] = $yayintipi;
    $arr['detay'] = $detay;
    $arr2[]=$arr;
}
echo json_encode($arr2, true);
?>

When I write the path of php file in browser, it returns proper JSON like I wanted. There is no problem in here. But I want to use whatever link I want like these: "http://iztv.com.tr/yayinakisiGunler.aspx?id=2" or "http://iztv.com.tr/yayinakisiGunler.aspx?id=3" or other links etc.

当我在浏览器中编写php文件的路径时,它会返回我想要的正确JSON。这里没有问题。但我想使用我想要的任何链接:“http://iztv.com.tr/yayinakisiGunler.aspx?id=2”或“http://iztv.com.tr/yayinakisiGunler.aspx?id=3 “或其他链接等

How can I do that without changing the code and just writing an URL/path to browser?

如何在不更改代码的情况下执行此操作,只需将URL /路径写入浏览器即可?

1 个解决方案

#1


If you call your script using a parameter i.e.

如果使用参数调用脚本,即

example.com/myscript.php?id=2

You can use the parameter called id in the script to control the parameter used on the site you get contents from.

您可以在脚本中使用名为id的参数来控制从中获取内容的站点上使用的参数。

<?php
include('simple_html_dom.php');

if ( ! empty($_GET['id']) {
    $id = $_GET['id'];

} else {
    // got no parameter ERROR

    // or got no parameter assume 1
    $id = 1;
}

 $sContent = file_get_contents('http://iztv.com.tr/yayinakisiGunler.aspx?id=' . $id);

Of course you should sanitize the $_GET['id'] parameter before you actually use it, but I have left that for you to do.

当然你应该在实际使用它之前清理$ _GET ['id']参数,但是我已经把它留给了你。

更多相关文章

  1. 如何添加动态参数
  2. 显示长期运行的PHP脚本的进展。
  3. 在php中获取引荐来源网址(包括参数)
  4. PHP基础之脚本传参
  5. php通过$_SERVER[&#39;HTTP_USER_AGENT&#39;]获取浏览器相关参数
  6. phpBB3导入帖子的Python脚本
  7. PHP脚本在我的Wordpress文件中。请解码或帮助我删除它。
  8. AJAX调用在JavaScript中运行PHP脚本
  9. 通过Bash脚本语言逃避MYSQL命令行。

随机推荐

  1. 跟随屏幕大小自动调整bitmap大小(横竖屏拍
  2. android启动过程再研
  3. . io .IOException:setDataSource失败了
  4. Android图形图像处理之Bitmap和BitmapFac
  5. android里Toast的用法
  6. 无法向CalendarView事件添加侦听器
  7. 实现基于注解(Annotation)的数据库框架(一)反
  8. Android内容提供者——Content Providers
  9. OpenCV4Android中图像预览旋转90度的问题
  10. 如何将本机应用程序(android)与phonegap应