0

I have a code of 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.

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

1
  • Well without changing the code you cannot get the code to do something different. So the actual answer is No you cannot Commented May 6, 2015 at 8:48

1 Answer 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.

<?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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.