I would appreciate some help. I have this script (written by someone else before I joined) which would get content from XML link and save into a file for apple news. Most part of code is working but the only thing is not working is that when file is saved, it's blank, content is not being saved from XML.
$cu = 'XML FILE LINK'
$tu = 'APPLE JSON TEMPLATE';
$c = file_get_contents($cu);
$t = file_get_contents($tu);
//$t = file_get_contents($tu);
$a1 = explode('__ENDI__', $c);
$ia = array();
foreach ($a1 as $i){
if (strlen($i) > 50){
$ta = explode('__ENDF__', $i);
$o = new stdClass;
$o->storyid = $ta[0];
$o->img1 = $ta[1];
$o->caption = json_encode($ta[2]);
$o->headline = json_encode($ta[3]);
$tmpa = explode('<BR>', $ta[6]);
$o->abst = json_encode($tmpa[0]);
// $o->abst = json_encode($ta[4]);
$o->auth = json_encode($ta[5]);
$o->body = str_replace("<BR>\r", "\n", $ta[6]);
$o->body = json_encode($o->body);
// NEW FOR TAGS
$tmpa2 = explode(',', $ta[7]);
$tmpk = '';
foreach ($tmpa2 as $k){
$tk = trim($k);
if (strlen($tk) > 3){
$tmpk .= "\n" . json_encode($tk) . ",";
}
}
$tmpk .= "\n" . json_encode("celebrity news");
$o->keywords = $tmpk;
// END NEW FOR TAGS
$ia[$o->storyid] = $o;
} // end if strlen
}
echo "<pre>\n";
foreach ($ia as $id => $o){
echo "\nchecking log for $id\n";
$ftg = $ld . $id . '.txt';
$dt = file_get_contents($ftg);
if (strlen($dt) < 5){
echo "no $dt entry, creating content for $id\n";
$cd = $wd . $id;
mkdir($cd, 0777);
$tt = $t;
$tt = str_replace('**story_id**', $o->storyid, $tt);
$tt = str_replace('**headline**', $o->headline, $tt);
$tt = str_replace('**abstract**', $o->abst, $tt);
$tt = str_replace('**auth**', $o->auth, $tt);
$tt = str_replace('**caption**', $o->caption, $tt);
$tt = str_replace('**body**', $o->body, $tt);
// NEW FOR TAGS
$tt = str_replace('**keywords**', $o->keywords, $tt);
// END NEW FOR TAGS
echo "</pre><hr>made template : \n\n<textarea>$tt</textarea><pre>\n\n";
$nfn = $cd . '/' . 'article.json';
Aucun commentaire:
Enregistrer un commentaire