Jump to content

april2008

Members
  • Posts

    24
  • Joined

  • Last visited

    Never

Posts posted by april2008

  1. this is the code i have

    <?
        Function feedMe($feed) {  
            // Use cURL to fetch text  
            $ch = curl_init();  
            curl_setopt($ch, CURLOPT_URL, $feed);  
            curl_setopt($ch, CURLOPT_HEADER, 0);  
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt ($ch, CURLOPT_USERAGENT, $useragent);  
            $rss = curl_exec($ch);  
            curl_close($ch);  
         
           // Manipulate string into object  
    
           $rss = simplexml_load_string($rss);
      
       
         
           $siteTitle = $rss->channel->title;  
           echo "<h1>".$siteTitle."</h1>";  
           echo "<hr />";  
         
           $cnt = count($rss->channel->item);  
         
           for($i=0; $i<$cnt; $i++)  
           {  
               $url = $rss->channel->item[$i]->link;  
               $title = $rss->channel->item[$i]->title;  
               $desc = $rss->channel->item[$i]->description;  
               echo '<h3><a href="'.$url.'">'.$title.'</a></h3>'.$desc.'';  
           }  
       }  
         
       feedMe("http://twitter.com/statuses/user_timeline/44045750.rss");  
    ?>
    

  2. Problem solve

     

    just add in the code below after curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); to detect the proxy setting

     

    curl_setopt($ch, CURLOPT_PROXY, "http://xxx.xxx.xxx.xxx:8080");
    curl_setopt($ch, CURLOPT_PROXYPORT, 8080);
    curl_setopt ($ch, CURLOPT_PROXYUSERPWD, "username:password"); 
    

     

    thanks everyone :)

     

  3. ok. i off the firewall and tested the code u given.

     

    this is the output

    
    ------------------------------
    
    array(19) {
      ["url"]=>
      string(38) "http://www.dpreview.com/feeds/news.xml"
      ["http_code"]=>
      int(0)
      ["header_size"]=>
      int(0)
      ["request_size"]=>
      int(0)
      ["filetime"]=>
      int(-1)
      ["ssl_verify_result"]=>
      int(0)
      ["redirect_count"]=>
      int(0)
      ["total_time"]=>
      float(0)
      ["namelookup_time"]=>
      float(0)
      ["connect_time"]=>
      float(0)
      ["pretransfer_time"]=>
      float(0)
      ["size_upload"]=>
      float(0)
      ["size_download"]=>
      float(0)
      ["speed_download"]=>
      float(0)
      ["speed_upload"]=>
      float(0)
      ["download_content_length"]=>
      float(0)
      ["upload_content_length"]=>
      float(0)
      ["starttransfer_time"]=>
      float(0)
      ["redirect_time"]=>
      float(0)
    }
    
    
    ------------------------------
    
    

  4. i tried to safe_mode = On, it still display a blank page.

     

    if open_basedir = On, i got the error below

     

    Warning: Unknown: open_basedir restriction in effect. File(C:/Apache2.2/htdocs/testing.php) is not within the allowed path(s): (1) in Unknown on line 0

     

    Warning: Unknown: failed to open stream: Operation not permitted in Unknown on line 0

     

    Fatal error: Unknown: Failed opening required 'C:/Apache2.2/htdocs/testing.php' (include_path='.;C:\php5\pear') in Unknown on line 0.

     

    by the way, is it safe to on safe mode and open_basedir?

     

  5. ok.this is the code i had modify

     

    <?
    error_reporting(E_ALL);
    //$xml = file_get_contents('http://www.dpreview.com/feeds/news.xml');
    
    
    // Use cURL to get the RSS feed into a PHP string variable.
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,'http://www.dpreview.com/feeds/news.xml');
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 15);
    $xml = curl_exec($ch);
    curl_close($ch);
    die($xml);//added  for debugging
    //$xml = curl_exec($ch);
    //curl_close($ch);
    
    
    // Include the handy XML data extraction functions.
    include 'xml_regex.php';
    // An RSS 2.0 feed must have a channel title, and it will
    // come before the news items. So it's safe to grab the
    // first title element and assume that it's the channel
    // title.
    $channel_title = value_in('title', $xml);
    // An RSS 2.0 feed must also have a link element that
    // points to the site that the feed came from.
    $channel_link = value_in('link', $xml);
    
    
    // Create an array of item elements from the XML feed.
    $news_items = element_set('item', $xml);
    
    
    foreach($news_items as $item) {
        $title = value_in('title', $item);
        $url = value_in('link', $item);
        $description = value_in('description', $item);
        $timestamp = strtotime(value_in('pubDate', $item));
        $item_array[] = array(
                'title' => $title,
                'url' => $url,
                'description' => $description,
                'timestamp' => $timestamp
        );
    }
    
    if (sizeof($item_array) > 0) {
        // First create a div element as a container for the whole
        // thing. This makes CSS styling easier.
        $html = '<div class="rss_feed_headlines">';
        // Markup the title of the channel as a hyperlink.
        $html .= '<h2 class="channel_title">'.
                '<a href="'.make_safe($channel_link).'">'.
                make_safe($channel_title).'</a></h2><dl>';
        // Now iterate through the data array, building HTML for
        // each news item.
        $count = 0;
        foreach ($item_array as $item) {
            $html .= '<dt><a href="'.make_safe($item['url']).'">'.
                    make_safe($item['title']).'</a></dt>';
            //$html .= '<dd>'.make_safe($item['description']);
            if ($item['timestamp'] != false) {
              $html .= '<br />';
                        //'<span class="news_date">['.
                        //gmdate('H:i, jS F T', $item['timestamp']).
                        //']</span>';
            }
            //echo '</dd>';
            // Limit the output to five news items.
            if (++$count == 10) {
                break;
            }
        }
        $html .= '</dl></div>';
        echo $html;
    }
    
    
    function make_safe($string) {
        $string = preg_replace('#<!\[CDATA\[.*?\]\]>#s', '', $string);
        $string = strip_tags($string);
        // The next line requires PHP 5, unfortunately.
        //$string = htmlentities($string, ENT_NOQUOTES, 'UTF-8', false);
        // Instead, use this set of replacements in PHP 4.
        $string = str_replace('<', '<', $string);
        $string = str_replace('>', '>', $string);
        $string = str_replace('(', '&#40;', $string);
        $string = str_replace(')', '&#41;', $string);
        return $string;
    }
    
    
    $string =  preg_replace('#<!\[CDATA\[.*?\]\]>#s', '', $string);
    ?>
    
    

     

    but it still display an empty page ???

  6. MadTechie,

     

    yes, i got it from that site.

     

    i already set

    allow_url_fopen = On

    uncomment extension=php_curl.dll

     

    and add in

    $xml = curl_exec($ch);
    curl_close($ch);
    die($xml);//added  for debugging

     

    but still have the same error

    Warning: file_get_contents(http://www.dpreview.com/feeds/news.xml) [function.file-get-contents]: failed to open stream: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

  7. this is my code

     

    <?

    $xml = file_get_contents('http://www.dpreview.com/feeds/news.xml');

     

     

    // Use cURL to get the RSS feed into a PHP string variable.

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL,'http://www.dpreview.com/feeds/news.xml');

    curl_setopt($ch, CURLOPT_HEADER, false);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $xml = curl_exec($ch);

    curl_close($ch);

     

     

    // Include the handy XML data extraction functions.

    include 'xml_regex.php';

    // An RSS 2.0 feed must have a channel title, and it will

    // come before the news items. So it's safe to grab the

    // first title element and assume that it's the channel

    // title.

    $channel_title = value_in('title', $xml);

    // An RSS 2.0 feed must also have a link element that

    // points to the site that the feed came from.

    $channel_link = value_in('link', $xml);

     

     

    // Create an array of item elements from the XML feed.

    $news_items = element_set('item', $xml);

     

     

    foreach($news_items as $item) {

        $title = value_in('title', $item);

        $url = value_in('link', $item);

        $description = value_in('description', $item);

        $timestamp = strtotime(value_in('pubDate', $item));

        $item_array[] = array(

                'title' => $title,

                'url' => $url,

                'description' => $description,

                'timestamp' => $timestamp

        );

    }

     

    if (sizeof($item_array) > 0) {

        // First create a div element as a container for the whole

        // thing. This makes CSS styling easier.

        $html = '<div class="rss_feed_headlines">';

        // Markup the title of the channel as a hyperlink.

        $html .= '<h2 class="channel_title">'.

                '<a href="'.make_safe($channel_link).'">'.

                make_safe($channel_title).'</a></h2><dl>';

        // Now iterate through the data array, building HTML for

        // each news item.

        $count = 0;

        foreach ($item_array as $item) {

            $html .= '<dt><a href="'.make_safe($item['url']).'">'.

                    make_safe($item['title']).'</a></dt>';

            //$html .= '<dd>'.make_safe($item['description']);

            if ($item['timestamp'] != false) {

        $html .= '<br />';

                        //'<span class="news_date">['.

                        //gmdate('H:i, jS F T', $item['timestamp']).

                        //']</span>';

            }

            //echo '</dd>';

            // Limit the output to five news items.

            if (++$count == 10) {

                break;

            }

        }

        $html .= '</dl></div>';

        echo $html;

    }

     

     

    function make_safe($string) {

        $string = preg_replace('#<!\[CDATA\[.*?\]\]>#s', '', $string);

        $string = strip_tags($string);

        // The next line requires PHP 5, unfortunately.

        //$string = htmlentities($string, ENT_NOQUOTES, 'UTF-8', false);

        // Instead, use this set of replacements in PHP 4.

        $string = str_replace('<', '<', $string);

        $string = str_replace('>', '>', $string);

        $string = str_replace('(', '&#40;', $string);

        $string = str_replace(')', '&#41;', $string);

        return $string;

    }

     

     

    $string =  preg_replace('#<!\[CDATA\[.*?\]\]>#s', '', $string);

    ?>

  8. I got this warning message from a script I was working on to read XML feeds.

     

    Warning: file_get_contents(http://feeds2.feedburner.com/tmi/news/malaysia?format=xml) [function.file-get-contents]: failed to open stream: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

     

    but when i run this "http://feeds2.feedburner.com/tmi/news/malaysia?format=xml".

     

    can anyone tell me what is the problem? i already set allow_url_fopen = On

     

    currently using PHP5 and Apache2.2

     

    thanks

  9. OK. i already turn on the ini_set('display_errors','On'); 

     

    but it still blank

     

    phpbuilder.rss

    <? xml version="1.0" ?>

    <rss version="0.91">

    <channel> 

    <pubDate>Thu, 29 Sep 2005 15:16:13 GMT</pubDate> 

    <description>Newest Articles and How-To's on PHPBuilder.com</description>

    <link>http://phpbuilder.com</link> 

    <title>PHPBuilder.com New Articles</title> 

    <webMaster>staff@phpbuilder.com</webMaster> 

    <language>en-us</language>  <item> 

    <title>In Case You Missed It...The Week of September 26, 2005</title> 

    <link>http://www.phpbuilder.com/columns/weeklyroundup20050926.php3</link> 

    <description>This week Elizabeth brings us news of an upcoming free

    webcast called Design Patterns in PHP, the schedule for the Fall Zend conference,

    security alerts for Moveable Type and phpBB, the release of Zend Platform 2,

    XAMPP for Linux, the latest PEAR/PECL releases and much more!

    </description>  </item>  <item> 

    <title>In Case You Missed It...The Week of September 19, 2005</title> 

    <link>http://www.phpbuilder.com/columns/weeklyroundup20050919.php3</link> 

    <description>This week Elizabeth brings us news of the release of PEAR 1.4,   

    Zend Studio 5 Beta, a security vulnerability with PHP-Nuke, the release of a

    SimpleTest plugin for PHPEclipse, a patch for phpMyAdmin, the latest PEAR/PECL

    releases and much, much more!</description> 

    </item>

    </channel>

    </rss>

     

    rssread.php

    <?php 

    ini_set('display_errors','On'); 

    ?> 

    <?php

     

    $rssFeeds = array ('phpbuilder.rss');

     

    //Loop through the array, reading the feeds one by one

    foreach ($rssFeeds as $feed) {

      readFeeds($feed);

    }

    function startElement($xp,$name,$attributes) {

      echo "Start $name";

    }

     

    function endElement($xp,$name) {

      echo "End: $name";

    }

     

     

    function characterDataHandler($xp,$data) {

      echo "Data: $data ";

    }

     

    function readFeeds($feed) {

      $fh = fopen($feed,'r');

    // open file for reading

     

      $xp = xml_parser_create();

    // Create an XML parser resource

     

      xml_set_element_handler($xp, "startElement", "endElement");

    // defines which functions to call when element started/ended

     

      xml_set_character_data_handler($xp, "characterDataHandler");

     

      while ($data = fread($fh, 4096)) {

        if (!xml_parse($xp,$data)) {

          return 'Error in the feed';

        }

      }

    }

    ?>

     

    ???

  10. ok. i changed to the code below

     

    <?php $rssFeeds = array ('phpbuilder.rss');

    // for now we'll just have the one file, but this can later be expanded

    //Loop through the array (just one element for now) and read the feedforeach

    foreach ($rssFeeds as $feed) {

      readFeeds($feed);

    }

     

    // The function to be called when a start element is read. For now we'll

    // just echo some outputfunction

    function startElement($xp,$name,$attributes) { 

    echo "Start $name <br>";}

    function endElement($xp,$name) { 

    echo "End: $name<br>";}

     

    function characterDataHandler($xp,$data) {

      echo "Data: $data

    ";

    }

     

     

    function readFeeds($feed) { 

    $fh = fopen($feed,'r');

    // open file for reading 

    $xp = xml_parser_create();

    // Create an XML parser resource 

    xml_set_element_handler($xp, "startElement", "endElement");

    // defines which functions to call when element started/ended 

    while ($data = fread($fh, 4096)) {   

    if (!xml_parse($xp,$data)) {     

    return 'Error in the feed';    }  }}?>

     

     

    but how come it display a blank page?

  11. Having error for my code

     

    Parse error: parse error, unexpected T_AS in C:\Apache2.2\htdocs\rssread.php on line 4

     

    this is the code i have

     

    <?php $rssFeeds = array ('phpbuilder.rss');

    // for now we'll just have the one file, but this can later be expanded

    //Loop through the array (just one element for now) and read the feedforeach

    ($rssFeeds as $feed) {  readFeeds($feed);}

    // The function to be called when a start element is read. For now we'll

    // just echo some outputfunction

    startElement($xp,$name,$attributes) { 

    echo "Start $name <br>";}

    function endElement($xp,$name) { 

    echo "End: $name<br>";}

     

    function readFeeds($feed) { 

    $fh = fopen($feed,'r');

    // open file for reading 

    $xp = xml_parser_create();

    // Create an XML parser resource 

    xml_set_element_handler($xp, "startElement", "endElement");

    // defines which functions to call when element started/ended 

    while ($data = fread($fh, 4096)) {   

    if (!xml_parse($xp,$data)) {     

    return 'Error in the feed';    }  }}?>

     

     

     

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.