php - when i insert of description and img_url data behave differently?

571

PHP

$rss = new SimpleXMLElement($xml, LIBXML_NOCDATA);

foreach ($rss->channel->item as $item) { 
  foreach ($rss->channel->item as $item) { 

   $guid = $item->guid  ;
   $title = $item->title ;
   $url = $item->link;
   $description = (string)$item->description ;
   $date = $item->pubDate;
   $img_url = $item->enclosure['url'] ; 
   $category =  $item->category[1] ;  

   Insert($guid,$title,$description,$url,$date,$img_url) ;
}   


function Insert($g,$t,$des,$u,$d,$imgu) {
global $connection ;
echo $g,"<br>",$t,"<br>",$des,"<br>",$u,"<br>",$d,"<br>",$imgu,"<br>" ;
$insert_sql = "INSERT INTO rssfeed (guid,title,description,url,date,img_url) VALUES (?,?,?,?,?,?)" ;
$stmt = $connection->stmt_init() ;
$stmt->prepare($insert_sql) ;
$stmt->bind_param('isssss',$g,$t,$des,$u,$d,$imgu);
$stmt->execute() ;
 } 

when i echo in function it shows clear output but in database in description and img_url and url coulmns have different data entry .both urls haven't full url information which as show in output file .

second question how can i sanitize the all this before input my db like dates ,url and tittle etc.

both images of output and database

output of function

database input

People are also looking for solutions to the problem: php - Update a field in mongodb document stored in a array of array in yii2 model

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.