试图将Html插入表中

时间:2015-01-21 11:32:35

标签: php html mysql sql

我正在尝试将RSS源中的html代码插入到表中,这是代码;

<?php

  $dbip   = "localhost";
  $dbuser = "xxxxxxx";
  $dbpass = "xxxxxxxx";

    $rss = new DOMDocument();
    $rss->load('http://store.steampowered.com/feeds/daily_deals.xml');

    $feed = array();
    foreach ($rss->getElementsByTagName('item') as $node) {
        $item = array ( 
            'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
            'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
            'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
            'content' => $node->getElementsByTagName('encoded')->item(0)->nodeValue,
            );
        array_push($feed, $item);
    }

    $limit = 1;

    for($x=0;$x<$limit;$x++) {

        $title = str_replace(' & ', ' &amp; ', $feed[$x]['title']);
        $link = $feed[$x]['link'];
        $date = date('F j, Y', strtotime($feed[$x]['date']));
        $con = str_replace('style=', 'style=" float: left; margin-right: 12px; height: 100px; width: 260px;"', $feed[$x]['content']);
        $con = str_replace('><img', ' target="_blank"><br><img', $con);

        if($title != ""){

            echo '<div class="recent_post">' . "\n" . "\n";

            echo '<h4><a href="'.$link.'" title="'.$title.'" target="_blank">'.$title.'</a></h4>' . "\n" . "\n";
            //echo '<div class="post_date">'.$date.'</div>' . "\n";
            echo $con;
            echo '</div>' . "\n" . "\n";

        }

    }

    $conn = mysqli_connect($dbip, $dbuser, $dbpass, "news");

    if(!$conn) {

        die("Failed: ") . mysqli_error();

    }
        $html = mysql_real_escape_string($con);
        $imput = "INSERT INTO `deal` (`title`, `info`) VALUES ('$title', '$html')";

        if(!mysqli_query($conn, $imput)){

                echo "Nope!!!!!!!!!";
                echo $html;

            }else{

                echo "1 Record added";

        }

        if(!$title){

        print('Error getting Daily Deal' . '<br \><br \>' . 'Please check back soon, or contact us <a href="mailto:huskies@hubskie.com">here</a>');

        }

    mysqli_close($conn)
?>

我可以获得标题,它只是$ con,我不能;

以下是$ con;

的输出
Today's Deal: Save 40% on <a href='http://store.steampowered.com/app/253510/'>WARMACHINE: Tactics</a>!*<br><br>Look for the deals each day on the front page of Steam. Or follow us on <a href='http://twitter.com/steam_games'>twitter</a> or <a href='http://www.facebook.com/Steam'>Facebook</a> for instant notifications wherever you are!<br><br>*Offer ends Thursday at 10AM Pacific Time<br><a href="http://store.steampowered.com/app/253510/" target="_blank"><br><img src="http://cdn.akamai.steamstatic.com/steam/apps/253510/capsule_467x181.jpg" style=" float: left; margin-right: 12px; height: 100px; width: 260px;"" float: left; margin-right: 12px; height: 181px; width: 467px;"></a>

我真的被卡住了,:(请帮忙!


更新

使用Addslashes func修复问题

0 个答案:

没有答案