php - How to wrap html when running foreach loop -
i have loop below
foreach( $b $entry) { $title2 = "<!doctype html> <meta content='text/html; charset=utf-8' http-equiv='content-type'> <head> <link rel='stylesheet' href='../../css/bootstrap.min.css'> </head> <body>"; $title2 .= "<div class='data'><div id=".$id."><span style='font-family: web'>".$entry->pubdate." </span><a href='../../fetch.php?url=".$id."' title='$entry->title' >" .$title. "</a><br/><div class='content'>".$description."</div></div></div>"; $title3 = "<!doctype html> <meta content='text/html; charset=utf-8' http-equiv='content-type'> <meta name='viewport' content='width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;'> <head> <link rel='stylesheet' href='../../../css/bootstrap.min.css'> </head> <body><div class='container'> <div class='row'> <div class='col-lg-12' style='margin-top:20px;'>"; $title3 .= "<div class='list-group'><a href='../../../fetch.php?url=".$id."' title='$entry->title' class='list-group-item' > <i class='fa fa-chevron-right rt'></i><div class='title'><div id=".$id."><span style='font-family: malithi web'>".$entry->pubdate." </span>'<div><h4 class='list-group-item-heading'>'" .$title. "</h4></div><br/></div></div></div></div></div></div></a></div>"; if (!file_exists('file')) { mkdir('file', 0777, true); } if (!file_exists('./file/'.date("y-m-d"))) { mkdir('./file/'.date("y-m-d"), 0777, true); } if (!file_exists('./file/titles/'.date("y-m-d"))) { mkdir('./file/titles/'.date("y-m-d"), 0777, true); } $file = './file/'.date("y-m-d").'/'."file.html"; file_put_contents($file, $title2, file_append | lock_ex); $filet = './file2/titles/'.date("y-m-d").'/'."file2.html"; file_put_contents($filet, $title3, file_append | lock_ex); }//foreach end
when save file want save html head , styles..but saving each time when loop runs..i want run once.
thank you!
do want have 2 dayly log files same data differently formatted? move header , footer , filenaming logic outside of loop.
<?php foreach ($b $entry) { $body2 .= "<div class='data'><div id=" . $id . "><span style='font-family: web'>" . $entry->pubdate . " </span><a href='../../fetch.php?url=" . $id . "' title='$entry->title' >" . $title . "</a><br/><div class='content'>" . $description . "</div></div></div>"; $body3 .= "<div class='list-group'><a href='../../../fetch.php?url=" . $id . "' title='$entry->title' class='list-group-item' > <i class='fa fa-chevron-right rt'></i><div class='title'><div id=" . $id . "><span style='font-family: malithi web'>" . $entry->pubdate . " </span>'<div><h4 class='list-group-item-heading'>'" . $title . "</h4></div><br/></div></div></div></div></div></div></a></div>"; } if (!file_exists('file')) { mkdir('file', 0777, true); } if (!file_exists('./file/' . date("y-m-d"))) { mkdir('./file/' . date("y-m-d"), 0777, true); } if (!file_exists('./file/titles/' . date("y-m-d"))) { mkdir('./file/titles/' . date("y-m-d"), 0777, true); } $file = './file/' . date("y-m-d") . '/' . "file.html"; $title2 = "<!doctype html> <meta content='text/html; charset=utf-8' http-equiv='content-type'> <head> <link rel='stylesheet' href='../../css/bootstrap.min.css'> </head> <body>"; $footer2 = "</body></html>"; file_put_contents($file, $title2 . $body2 . $footer2, file_append | lock_ex); $title3 = "<!doctype html> <meta content='text/html; charset=utf-8' http-equiv='content-type'> <meta name='viewport' content='width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;'> <head> <link rel='stylesheet' href='../../../css/bootstrap.min.css'> </head> <body><div class='container'> <div class='row'> <div class='col-lg-12' style='margin-top:20px;'>"; $footer3 = "</div></div></div></body></html>"; $filet = './file2/titles/' . date("y-m-d") . '/' . "file2.html"; file_put_contents($filet, $title3 . $body3 . $footer3, file_append | lock_ex);
Comments
Post a Comment