El error es que recogo noticias de rss remoto como el pais, etc.. y las meto en mi base de datos como si fueran mias para poder mostrarlas a mi gusto y no conosigo sacar el error, Este es el error:
/************************************************** *************/
Warning: DOMDocument::load() [domdocument.load]: Input is not proper UTF-8, indicate encoding ! Bytes: 0xF1 0x6F 0x20 0x66 in http://red.es/articles/index.action?sec=326, line: 39 in C:\xampp\htdocs\aulasmart2.5\page\prs.php on line 11
Warning: DOMDocument::load() [domdocument.load]: EntityRef: expecting ';' in http://red.es/articles/index.action?sec=326, line: 54 in C:\xampp\htdocs\aulasmart2.5\page\prs.php on line 11
Warning: DOMDocument::load() [domdocument.load]: Opening and ending tag mismatch: img line 54 and div in http://red.es/articles/index.action?sec=326, line: 54 in C:\xampp\htdocs\aulasmart2.5\page\prs.php on line 11
Warning: DOMDocument::load() [domdocument.load]: Opening and ending tag mismatch: div line 54 and noscript in http://red.es/articles/index.action?sec=326, line: 55 in C:\xampp\htdocs\aulasmart2.5\page\prs.php on line 11
Warning: DOMDocument::load() [domdocument.load]: Opening and ending tag mismatch: noscript line 53 and li in http://red.es/articles/index.action?sec=326, line: 56 in C:\xampp\htdocs\aulasmart2.5\page\prs.php on line 11
Warning: DOMDocument::load() [domdocument.load]: Opening and ending tag mismatch: li line 41 and ul in http://red.es/articles/index.action?sec=326, line: 57 in C:\xampp\htdocs\aulasmart2.5\page\prs.php on line 11
Warning: DOMDocument::load() [domdocument.load]: Opening and ending tag mismatch: ul line 38 and div in http://red.es/articles/index.action?sec=326, line: 58 in C:\xampp\htdocs\aulasmart2.5\page\prs.php on line 11
Warning: DOMDocument::load() [domdocument.load]: Opening and ending tag mismatch: div line 31 and body in http://red.es/articles/index.action?sec=326, line: 884 in C:\xampp\htdocs\aulasmart2.5\page\prs.php on line 11
Warning: DOMDocument::load() [domdocument.load]: Opening and ending tag mismatch: body line 29 and html in http://red.es/articles/index.action?sec=326, line: 885 in C:\xampp\htdocs\aulasmart2.5\page\prs.php on line 11
Warning: DOMDocument::load() [domdocument.load]: Premature end of data in tag html line 7 in http://red.es/articles/index.action?sec=326, line: 886 in C:\xampp\htdocs\aulasmart2.5\page\prs.php on line 11
/************************************************** *************/
y este es mi código llevo dandole vueltas y no tengo manera de solucionarlo:
/************************************************** *************/
<?php
ob_start();
include ("../dll/database.php");
include ("../dll/verweb.php");
$con=conectar();
//funcion rss ************************************************** ***********************
function rss_to_array($tag, $array, $url, $con) {
$doc = new DOMdocument();
$doc->load($url);
$rss_array = array();
$items = array();
foreach($doc->getElementsByTagName($tag) AS $node) {
foreach($array AS $key => $value) {
$items[$value] = $node->getElementsByTagName($value)->item(0)->nodeValue;
}
array_push($rss_array, $items);
}
//print_r($rss_array);
return $rss_array;
}
//************************************************** ***********************************
// Creamo un array con lo elementos que componen un canal rss
$rss_tags = array(
'title',
'link',
'guid',
'comments',
'description',
'pubDate',
'category',
);
$rss_item_tag = 'item';
// Creamos un array con las url a buscar las noticias
$rss_url= array ("http://www.mcu.es/fundaciones/rss.xml",
"http://www.elpais.com/rss/feed.html?feedId=17064",
"http://red.es/articles/index.action?sec=326");
// bucle para buscar una auna en todas las url
for($j=0;$j<=count($rss_url)-1;$j++){
$rssfeed = rss_to_array($rss_item_tag,$rss_tags,$rss_url[$j], $con);
//echo '<pre>';
//print_r($rssfeed);
for($i=5;$i>=0;$i--){
switch ($j){
case 0:
$fuente = 'Ministerio de educación';
break;
case 1;
$fuente = 'El Pais';
break;
case 2;
$fuente = 'Redcrea';
break;
}
$desc = utf8_decode ($rssfeed[$i][description]);
$tit = utf8_decode ($rssfeed[$i][title]);
if ($rssfeed[$i][pubDate] == '') $fecha = date("Y-m-d");
else{
if ($fuente == 'El Pais'){
$f = explode(" ",$rssfeed[$i][pubDate]);
$mes = pasar_a_numero($f[2]);
$fecha = $f[3]."-".$mes."-".$f[1];
}
}
$sql = "SELECT * from noticias where titulo like '".$tit."'";
//echo $sql;
$re = mysqli_query($con,$sql);
if((mysqli_num_rows($re)==0) AND (!empty ($tit))){
$sql="INSERT into noticias (titulo,descripcion,fecha,fuente,enlace_noticia) VALUES ('".$tit."','".$desc."','$fecha','$fuente','".$rss feed[$i][link]."')";
//echo $sql;
mysqli_query($con,$sql);
}
else echo "noticia ya almacenada<br/>";
}
//echo '</pre>';
}
//header("Location: feedrss2.php");
ob_end_flush();
?>
/************************************************** ************/