将 SimpleXMLElement 对象值和图像存储在数据库中

发布于 2024-12-13 17:23:37 字数 3009 浏览 0 评论 0原文

我正在尝试读取 RSS 提要并将其值存储在我的数据库中。为此我正在使用这个

    $homepage = file_get_contents('http://showmycode.co.in/supermob/feeds/rss/Jaipur');
    $movies = new SimpleXMLElement($homepage);
 echo '<pre>';
 print_r($movies);

然后我发现

     SimpleXMLElement Object

( [@属性] =>大批 ( [版本] => 2.00 )

[channel] => SimpleXMLElement Object
    (
        [title] => supermobdeal
        [description] => best discount accross canada        
        [link] => SimpleXMLElement Object
            (
            )

        [lastBuildDate] => Thu, Nov 3rd 2011, 00:32 GMT 
        [generator] => supermobdeal
        [image] => SimpleXMLElement Object
            (
                [url] => http://showmycode.co.in/supermob/app/webroot/img/site_logo.png
                [title] => supermobdeal
                [link] => http://showmycode.co.in/supermob/app/webroot/img/site_logo.png
                [description] => Feed provided by supermobdeal
            )

        [item] => Array
            (
                [0] => SimpleXMLElement Object
                    (
                        [title] => Let your 
                        [link] => http://showmycode.co.in/supermob/homes/index/Jaipur/25
                        [small_image_url] => http://showmycode.co.in/supermob/app/webroot/img/uploads/product_images/small/

                        [description] =>  trainers r any course



                        [start_date] => 2011-10-26
                        [end_date] => 2011-11-30
                        [start_time] => 09:26:00
                        [end_time] => 09:26:50
                        [price] => 50$
                        [value] => 199$
                        [discount] => 74.87%
                        [city] => Jaipur
                    )

                [1] => SimpleXMLElement Object
                    (
                        [title] => Feel a
                        [link] => http://showmycode.co.in/supermob/homes/index/Jaipur/31
                        [small_image_url] => http://showmycode.co.in/supermob/app/webroot/img/uploads/product_images/small/3b8d0_Jaip_OrientSpa_24thOct_M_1.jpg

                        [description] => Orient Spa 
                        [city] => Jaipur
                    )

                [2] => SimpleXMLElement Object
                    (
                        [title] => Feel a
                        [link] => http://showmycode.co.in/supermob/homes/index/Jaipur/26
                        [small_image_url] => http://showmycode.co.in/supermob/app/webroot/img/uploads/product_images/small/0a646_Bombay-Biryani1.jpg

                        [description] => Taxes 



                        [city] => Jaipur
                    )

            )

    )

) 如何在数据库中存储标题、链接或其他属性并将图像存储在文件夹中

I'm trying to read a rss feed and store its value in my database . for this I'm using this

    $homepage = file_get_contents('http://showmycode.co.in/supermob/feeds/rss/Jaipur');
    $movies = new SimpleXMLElement($homepage);
 echo '<pre>';
 print_r($movies);

and then I found

     SimpleXMLElement Object

(
[@attributes] => Array
(
[version] => 2.00
)

[channel] => SimpleXMLElement Object
    (
        [title] => supermobdeal
        [description] => best discount accross canada        
        [link] => SimpleXMLElement Object
            (
            )

        [lastBuildDate] => Thu, Nov 3rd 2011, 00:32 GMT 
        [generator] => supermobdeal
        [image] => SimpleXMLElement Object
            (
                [url] => http://showmycode.co.in/supermob/app/webroot/img/site_logo.png
                [title] => supermobdeal
                [link] => http://showmycode.co.in/supermob/app/webroot/img/site_logo.png
                [description] => Feed provided by supermobdeal
            )

        [item] => Array
            (
                [0] => SimpleXMLElement Object
                    (
                        [title] => Let your 
                        [link] => http://showmycode.co.in/supermob/homes/index/Jaipur/25
                        [small_image_url] => http://showmycode.co.in/supermob/app/webroot/img/uploads/product_images/small/

                        [description] =>  trainers r any course



                        [start_date] => 2011-10-26
                        [end_date] => 2011-11-30
                        [start_time] => 09:26:00
                        [end_time] => 09:26:50
                        [price] => 50$
                        [value] => 199$
                        [discount] => 74.87%
                        [city] => Jaipur
                    )

                [1] => SimpleXMLElement Object
                    (
                        [title] => Feel a
                        [link] => http://showmycode.co.in/supermob/homes/index/Jaipur/31
                        [small_image_url] => http://showmycode.co.in/supermob/app/webroot/img/uploads/product_images/small/3b8d0_Jaip_OrientSpa_24thOct_M_1.jpg

                        [description] => Orient Spa 
                        [city] => Jaipur
                    )

                [2] => SimpleXMLElement Object
                    (
                        [title] => Feel a
                        [link] => http://showmycode.co.in/supermob/homes/index/Jaipur/26
                        [small_image_url] => http://showmycode.co.in/supermob/app/webroot/img/uploads/product_images/small/0a646_Bombay-Biryani1.jpg

                        [description] => Taxes 



                        [city] => Jaipur
                    )

            )

    )

)
how can I store tittle , link or other attributes in my database and store image in folder

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薄暮涼年 2024-12-20 17:23:37
   //get contanints from SimpleXMLElement Object
    foreach($movies->channel->item as $opt){
    $title= $opt->title;
    $tittle=mysql_real_escape_string($title); //for Escapes special characters in a    string you can use for all varriables if require
     $link=$opt->link;
     $des=$opt->description;
     $image=$opt->medium_image_url;

    //for store image from http url to my folder
    $ch = curl_init($image);
    $fp = fopen('images/'. time () .'.'.'jpg', 'wb');//path for store image 
    curl_setopt($ch, CURLOPT_FILE, $fp);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_exec($ch);
    curl_close($ch);
        fclose($fp);

    include('db.php');//config file for db connection
     $sql="INSERT INTO rss (tittle, link, image,description,city)
     VALUES ('$tittle', '$link', '$image','$des','$city')";//insert record in database table
        $result=mysql_query($sql) or die('Error, insert query failed');

此代码将变量值存储在数据库中,将图像存储在来自 http url 的文件夹中。谢谢。

   //get contanints from SimpleXMLElement Object
    foreach($movies->channel->item as $opt){
    $title= $opt->title;
    $tittle=mysql_real_escape_string($title); //for Escapes special characters in a    string you can use for all varriables if require
     $link=$opt->link;
     $des=$opt->description;
     $image=$opt->medium_image_url;

    //for store image from http url to my folder
    $ch = curl_init($image);
    $fp = fopen('images/'. time () .'.'.'jpg', 'wb');//path for store image 
    curl_setopt($ch, CURLOPT_FILE, $fp);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_exec($ch);
    curl_close($ch);
        fclose($fp);

    include('db.php');//config file for db connection
     $sql="INSERT INTO rss (tittle, link, image,description,city)
     VALUES ('$tittle', '$link', '$image','$des','$city')";//insert record in database table
        $result=mysql_query($sql) or die('Error, insert query failed');

this code store varriables value in your database and image in folder from http url.thanks..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文