Qrabda kömək lazımdı

Shukur_23

Məhşur istifadəçi
Silver istifadeci
salam,
bu kodda heç cürə xəbər başlığı və şəkili üst-üstə sala bilmirəm xaiş kömək edin.

<?php

function fileC($url) {
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,TRUE);
$exec=curl_exec($ch);
curl_close($ch);
return $exec;
}

$xeber=fileC("https://milli.az/");

preg_match_all('#<strong class="title(.*)"><a href="https://news.milli.az/(.*)">(.*)</a></strong>#sU', $xeber, $link);

preg_match_all('#<img src="https://img.milli.az/(.*)"#sU',$xeber,$img);

print_r ($link);
print_r ($img);




$count = count($img[1]);

for ($i = 0; $i < $count; $i++) {
echo $img[1][$i];
//echo $link[3][$i];
}
 
PHP:
<?php

function fileC($url) {
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,TRUE);
$exec=curl_exec($ch);
curl_close($ch);
return $exec;
}

$xeber=fileC("https://milli.az/");
//xeber lentini mueyyen edirik
preg_match('#<ul class="post-list2">(.*)</ul>#sU', $xeber, $link);
// xeber lentinde olan xeberleri secirik.
preg_match_all('#<li>(.*)</li>#sU', $link[1], $news);
// xeberleri tek - siralayiriq.
foreach($news[1] as $n){
    // xeberin fotosunu ayririq
    preg_match('#<img class="alignleft" src="(.*)"#sU', $n, $img);
    // xeberin -> url adresini ayririq
    preg_match('#href="(.*)"#sU', $n, $url);
    // xeberin basligini ayririq
    preg_match('#alt="(.*)"#sU', $n, $title); $title[1]=strip_tags($title[1]);
    // xeberin elave edildiyi vaxti ayririq
    preg_match('#<span class="time">(.*)</span>#sU', $n, $time);
    # Ayirdigimiz butun melumatlari bir yerde toplayiriq :)
    print "<div><span $style>{$time[1]}</span><img src=\"{$img[1]}\" width=\"100\"><a href=\"{$url[1]}\">{$title[1]}</a></div>";
}

/*

preg_match_all('#<strong class="title(.*)"><a href="https://news.milli.az/(.*)">(.*)</a></strong>#sU', $xeber, $link);

preg_match_all('#<img src="https://img.milli.az/(.*)"#sU',$xeber,$img);

print_r ($link);
print_r ($img);




$count = count($img[1]);

for ($i = 0; $i < $count; $i++) {
echo $img[1][$i];
//echo $link[3][$i];
}*/
?>
 
PHP:
<?php

function milliAz($url){
    $cookie_file_path = "cookies.txt";
    $agent            = "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:43.0) Gecko/20100101 Firefox/46.0";
    $ch               = curl_init();
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_USERAGENT, $agent);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
    curl_setopt($ch, CURLOPT_URL, $url);
    $res = curl_exec($ch);
    curl_close($ch);
    return $res;
}

$response = milliAz("https://www.milli.az/latest.php?isAjax=1&ts=".$_GET['page']);
preg_match('/rData\s*=\s*{.*ts:\s*[\'"]?(\d+)[\'"]?.*}/', $response, $pages);//page

preg_match_all('/<li>\s*<a href="(.*?)">\s*<img class="alignleft" src="(.*?)" alt="(.*?)">\s*<\/a>\s*<div class="text-holder">\s*<strong class="title.*?"><a href=".*?">(.*?)<\/a><\/strong>\s*<p>\s*<\/p>\s*<div class="info-block">\s*<span class="time">(.*?)<\/span>/s', $response, $matches, PREG_SET_ORDER);


foreach ($matches as $match) {
  $link = $match[1];
  $img_src = $match[2];
  $img_alt = $match[3];
  $title = $match[4];
  $time = $match[5];

  echo "<li>";
  echo "<a href='$link'>";
  echo "<img class='alignleft' src='$img_src' alt='$img_alt'>";
  echo "</a>";
  echo "<div class='text-holder'>";
  echo "<strong class='title'><a href='$link'>$title</a></strong>";
  echo "<p></p>";
  echo "<div class='info-block'>";
  echo "<span class='time'>$time</span>";
  echo "</div>";
  echo "</div>";
  echo "</li>";
}
echo "<div class='pagination'><a href=\"?page=".$pages[1]."\">Sonraki</a></div>";
?>
<style>
ul {
list-style: none;
padding: 0;
margin: 0;
}

li {
display: flex;
margin-bottom: 20px;
padding-bottom: 20px;
border-bottom: 1px solid #ccc;
}

a {
text-decoration: none;
color: #333;
}

img {
margin-right: 20px;
max-width: 100px;
max-height: 100px;
}

.title {
font-weight: bold;
}

.time {
color: #888;
}
.pagination {
display: inline-block;
margin: 20px 0;
}

.pagination a {
color: #fff;
padding: 8px 16px;
background-color: #4CAF50;
border-radius: 5px;
text-decoration: none;
margin-right: 5px;
}

.pagination a.active {
background-color: #003366;
}

.pagination a:hover:not(.active) {
background-color: #ddd;
}

</style>
 
amma sən bunlari, bu kodları, istəyərk əldə edirsən, bir gun özün tək qalanda heckim kömək etmiyəndə nə edeceksəın,
ona görə bunları özündə oyrən, qrab elə bir şeydiki onu özündə oyrəməlisən ..
 
Geri
Üst