Skip to content

Instantly share code, notes, and snippets.

@yusufcakal
Created August 21, 2017 11:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yusufcakal/32e43bfe55cc2691bd12a5ee222d01b6 to your computer and use it in GitHub Desktop.
Save yusufcakal/32e43bfe55cc2691bd12a5ee222d01b6 to your computer and use it in GitHub Desktop.
Cumhuriyet University Cafeteria List Meals Api
<?php
function curlFunc($url)
{
$cd = curl_init();
curl_setopt($cd, CURLOPT_URL, $url);
curl_setopt($cd, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($cd, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($cd, CURLOPT_REFERER, 'http://www.google.com.tr/');
$data = curl_exec($cd);
curl_close($cd);
return $data;
}
function search($first, $last, $content){
$query='#'.$first.'(.*?)'.$last.'#s';
@preg_match_all($query,$content,$cont);
return @$cont;
}
$contentNames = array();
$tabldot = array();
$url = "http://www.cumhuriyet.edu.tr/yemeklistesi.php";
$content=curlFunc($url);
$date = search('<td align="left" width="60" >', '</td>', $content);
$date = substr($date[0][0], 29, strlen($date[0][0])-34);
$eat = search('<td align="left" >', '</td>', $content);
$eat = substr($eat[0][0], 18, strlen($eat[0][0])-23);
$tabldot = explode('-',$eat);
$tabldot = [
'tbl1' => iconv('iso-8859-9','utf-8',$tabldot[0]),
'tbl2' => iconv('iso-8859-9','utf-8',$tabldot[1]),
'tbl3' => iconv('iso-8859-9','utf-8',$tabldot[2]),
'tbl4' => iconv('iso-8859-9','utf-8',explode("(", $tabldot[3])[0]) // Kapalı yazısı için
];
$eat = search('<td align="left">', '</td>', $content);
$eat = substr($eat[0][0], 17, strlen($eat[0][0])-23);
$lokanta = explode('-',$eat);
$lokanta = [
'lknt1' => iconv('iso-8859-9','utf-8',$lokanta[0]),
'lknt2' => iconv('iso-8859-9','utf-8',$lokanta[1]),
'lknt3' => iconv('iso-8859-9','utf-8',$lokanta[2]),
'lknt4' => iconv('iso-8859-9','utf-8',$lokanta[3])
];
$contentNames[] = [
'tarih' => $date,
'tabldot' => $tabldot,
'lokanta' => $lokanta
];
header('Content-Type: application/json; charset=utf-8');
echo json_encode(array('içerik' => $contentNames));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment