Elseif file_put_contents elágazót nem tudom létrehozni.

Elseif file_put_contents elágazót nem tudom létrehozni.
2022-08-23T15:09:11+02:00
2022-08-23T21:12:50+02:00
2022-10-15T21:20:21+02:00
Géplakatos
Sziasztok lenne egy nagy gondom. 
Van egy progamom. Ami egy txt-be logol.
A lényege,ha végez egy feladattal így logolja :


oldal.hu ~ adott tartalom Nincs letoltve...

De szeretnék bele egy ilyet ha pl sikeresen letölti:

oldal.hu ~ adott tartalom Letöltve

Ez lenne a komplett kódom.:

<?php for ($z = 0;$z < $DAYS;$z++) { $date = date("Y-m-d", strtotime("+" . $z . " days")); $_tempFile = SETTINGS1 . 'cache/oldalam.hu/' . $ID . '~' . $date . '.json'; if (!file_exists($_tempFile) || filesize($_tempFile) < 10) { $json = json_decode(getUrlContents('https://oldalam.hu/tvapi?channel_id=tvchannel-' . $ID . '&date=' . $date), true); if (isset($json["channels"][0]["programs"][0]) == true) { $_date = date("Y-m-d", strtotime("+" . ($z + 1) . " days")); $_json = json_decode(getUrlContents('https://oldalam.hu/tvapi?channel_id=tvchannel-' . $ID . '&date=' . $_date), true); $temp = array_column($_json["channels"][0]["programs"], 'start_datetime'); foreach ($json["channels"][0]["programs"] as $program) { if ($program["end_datetime"] !== null) { $jsonArrays["end_datetime"][] = strReplace(explode('+', $program["end_datetime"]) [0], array('T' => '', '-' => '', ':' => '')); } else { $key = array_search($program["start_datetime"], $temp); $jsonArrays["end_datetime"][] = strReplace(explode('+', $_json["channels"][0]["programs"][$key]["end_datetime"]) [0], array('T' => '', '-' => '', ':' => '')); } $jsonArrays["start_datetime"][] = strReplace(explode('+', $program["start_datetime"]) [0], array('T' => '', '-' => '', ':' => '')); $jsonArrays["title"][] = $program["title"]; $jsonArrays["italics"][] = $program["italics"]; $jsonArrays["episode_title"][] = $program["episode_title"]; $jsonArrays["description"][] = $program["description"]; $jsonArrays["short_description"][] = $program["short_description"]; $jsonArrays["highlight"][] = $program["highlight"]; $jsonArrays["film_url"][] = $program["film_url"]; $jsonArrays["age_limit"][] = $program["restriction"]["age_limit"]; } file_put_contents($_tempFile, json_encode($jsonArrays)); $jsonArrays = null; $temp = null; $json = null; $_json = null; $stop = false; } else { $stop = true; } } } if ($stop !== true) { $files = glob(SETTINGS1 . 'cache/oldalam.hu/' . $ID . '~*.json'); $step = 0; foreach ($files as $file) { if (filesize($file) > 10) { $jsonArray[] = json_decode(file_get_contents($file, false), true); } } for ($x = 0;$x < count($jsonArray);$x++) { for ($y = 0;$y < count($jsonArray[$x]["start_datetime"]);$y++) { $portHUmd5 = null; $casts = null; $result["casts"] = null; $result["linkDesc"] = null; $result["release"] = 'N/A'; $result["snapshot"] = null; $result["category"] = 'N/A'; $break = " "; if ($jsonArray[$x]["film_url"][$y] !== null && findStringBYneedles($jsonArray[$x]["film_url"][$y], array('nincs-informacio')) === false) { $portHUmd5 = SETTINGS1 . 'cache/oldalam.hu/' . md5($jsonArray[$x]["film_url"][$y]) . '.json'; } if (file_exists($portHUmd5)) { $result = json_decode(file_get_contents($portHUmd5, false), true); } else { if (isset($jsonArray[$x]["italics"][$y]) == true && findStringBYneedles($jsonArray[$x]["italics"][$y], array('feliratozva', 'felirattal'), 'start') === false && mb_strlen($jsonArray[$x]["italics"][$y]) > 5) { $italics = preg_replace('~\d{4}|\d+ perc|,~', '', UTF8string($jsonArray[$x]["italics"][$y])); } if (isset($jsonArray[$x]["short_description"][$y]) == true && findStringBYneedles($jsonArray[$x]["short_description"][$y], array('feliratozva', 'felirattal'), 'start') === false && mb_strlen($jsonArray[$x]["short_description"][$y]) > 5) { $shortDesc = preg_replace('~\d{4}|,~', '', UTF8string($jsonArray[$x]["short_description"][$y])); } if ($portHUmd5 !== null) { $results = getUrlContents('https://oldalam.hu' . $jsonArray[$x]["film_url"][$y]); if (mb_strlen($results) > 0) { $newResults = preg_replace('~<strong>.+</strong>|<b>.+</b>~', '', $results); $doc = new DOMDocument(); $doc->loadHTML($results); $xpath = new DOMXpath($doc); if (isset($xpath->query("//meta[contains(@property, 'video:actor')]") [0])) { $i = 0; foreach ($xpath->query("//meta[contains(@property, 'video:actor')]") as $actor) { $casts[] = $actor->getAttribute("content"); if ($i == 3) break; $i++; } $result["casts"] = $break . $casts[0]; if (isset($casts[1]) == true) { $result["casts"] = $break . $casts[0] . ', ' . $casts[1]; if (isset($casts[2]) == true) { $result["casts"] = $break . $casts[0] . ', ' . $casts[1] . ', ' . $casts[2]; } } } if (isset($xpath->query("//div[@class='description']//article") [0])) { $result["linkDesc"] = $break . preg_replace('~Forgalmaz:.+|Bemutat dtuma:.+~i', '', $xpath->query("//div[@class='description']//article") [0]->nodeValue); } if (isset($xpath->query("//meta[contains(@property, 'video:release_date')]") [0])) { $result["release"] = $xpath->query("//meta[contains(@property, 'video:release_date')]") [0]->getAttribute("content"); } if (isset($xpath->query("//section[contains(@class, 'row no-hr details-box')]//div") [0])) { $item = preg_replace('~\d{4}|\d+ perc|,~', '', UTF8string($xpath->query("//section[contains(@class, 'row no-hr details-box')]//div") [0]->nodeValue)); if (mb_strlen($item) < 50 && mb_strlen($item) > 3) { $result["category"] = $item; } } if ($result["category"] === 'N/A' && mb_strlen($italics) < 50 && mb_strlen($italics) > 3) { $result["category"] = $italics; } if ($result["category"] === 'N/A' && mb_strlen($shortDesc) < 50 && mb_strlen($shortDesc) > 3) { $result["category"] = $shortDesc; } if (isset($xpath->query("//meta[contains(@property, 'og:image')]") [0])) { $result["snapshot"] = $xpath->query("//meta[contains(@property, 'og:image')]") [0]->getAttribute("content"); } } else { file_put_contents(SETTINGS1 . 'logs/generator_' . $CH_GROUP . '.log', $WEBSITE . " ~ " . $CHANNEL . " Nincs eredmeny.\r\n ", FILE_APPEND | LOCK_EX); } } else { if (preg_match('~\d{4}~', $jsonArray[$x]["italics"][$y])) { $result["release"] = preg_replace('~[^\d{4}]~', '', $jsonArray[$x]["italics"][$y]); } if (mb_strlen($italics) < 50 && mb_strlen($italics) > 3) { $result["category"] = $italics; } if ($result["category"] === 'N/A' && mb_strlen($shortDesc) < 50 && mb_strlen($shortDesc) > 3) { $result["category"] = $shortDesc; } } if (isset($jsonArray[$x]["description"][$y]) == true && mb_strlen($jsonArray[$x]["description"][$y]) > 5) { $portDesc = $break . $jsonArray[$x]["description"][$y]; } if (isset($jsonArray[$x]["highlight"][$y]) == true && mb_strlen($jsonArray[$x]["highlight"][$y]) > 5) { $highlight = $break . $jsonArray[$x]["highlight"][$y]; } if (findStringBYneedles($result["category"], array('. rsz'), 'start') !== false) { $result["episodeNum"] = preg_replace('~[^\d+]~', '', findStringBYneedles($result["category"], array('. rsz'), 'start', false)); } elseif (findStringBYneedles($jsonArray[$x]["short_description"][$y], array('. rsz'), 'start') !== false) { $result["episodeNum"] = preg_replace('~[^\d+]~', '', findStringBYneedles($jsonArray[$x]["short_description"][$y], array('. rsz'), 'start', false)); } elseif (findStringBYneedles($jsonArray[$x]["italics"][$y], array('. rsz'), 'start') !== false) { $result["episodeNum"] = preg_replace('~[^\d+]~', '', findStringBYneedles($jsonArray[$x]["italics"][$y], array('. rsz'), 'start', false)); } else { $result["episodeNum"] = ''; } file_put_contents($portHUmd5, json_encode($result)); } $XMLarrays["start_datetime"][$ITERATOR][$step] = $jsonArray[$x]["start_datetime"][$y] . ' ' . SETTINGS7; $XMLarrays["end_datetime"][$ITERATOR][$step] = $jsonArray[$x]["end_datetime"][$y] . ' ' . SETTINGS7; if (isset($jsonArray[$x]["episode_title"][$y]) == true) { $XMLarrays["title"][$ITERATOR][$step] = $jsonArray[$x]["title"][$y] . ', ' . $jsonArray[$x]["episode_title"][$y]; } else { $XMLarrays["title"][$ITERATOR][$step] = $jsonArray[$x]["title"][$y]; } $XMLarrays["episode_num"][$ITERATOR][$step] = $result["episodeNum"]; $XMLarrays["category"][$ITERATOR][$step] = '[' . $result["category"] . '] (' . $result["release"] . ') [' . strReplace($jsonArray[$x]["age_limit"][$y]) . ']'; $XMLarrays["snapshot"][$ITERATOR][$step] = $result["snapshot"]; $XMLarrays["full_description"][$ITERATOR][$step] = $italics . $highlight . $portDesc . $result["linkDesc"] . $result["casts"]; $step++; if ($x == count($jsonArray) - 1 && $y == count($jsonArray[$x]) - 1) { $jsonArray = null; $result = null; $results = null; $portHUmd5 = null; $casts = null; } } } } elseif ($stop !== true) { file_put_contents(SETTINGS1 . 'logs/generator_' . $CH_GROUP . '.log', $WEBSITE . " ~ " . $CHANNEL . " Letöltve ", FILE_APPEND | LOCK_EX); $stop = true; } else { file_put_contents(SETTINGS1 . 'logs/generator_' . $CH_GROUP . '.log', $WEBSITE . " ~ " . $CHANNEL . " Nincs letoltve... ", FILE_APPEND | LOCK_EX); } ?>
Mutasd a teljes hozzászólást!
Hali!

Ha az if feltétele (39. sor) $stop !== true, akkor miért gondolod, hogy abba az elseif ágba (170. sor) bele fog ugrani, aminek a feltétele szintén $stop !== true? Minek akkor az elseif ág, miért nem egyből az if ágban írod a log-fájlt?

Más: ha a $stop változó logikai érték (bár, akkor is, ha nem), fölösleges az egyenlőség/nem-egyenlőség vizsgálat true-val/false-szal, simán csak a változó maga lehet a kifejezés, pl.:
if ($stop) { // Ha $stop igaz… } else { // Ha $stop hamis… }
Mutasd a teljes hozzászólást!

Tetszett amit olvastál? Szeretnél a jövőben is értesülni a hasonló érdekességekről?
abcd