Results 1 to 1 of 1

Thread: WordPress Curl Replacement

  1. #1
    Andy101's Avatar
    Andy101 is offline Code Otaku
    Join Date
    Aug 2009
    Location
    Japan/uk
    Posts
    699
    Thanks
    100
    Thanked 217 Times in 161 Posts

    WordPress Curl Replacement

    This is the preferred way to grab external website content such as feeds using WordPress:

    PHP Code:
    function nb_fetch($url) {
    /*
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt ($ch, CURLOPT_HEADER, 0); // Don't return http header
        $feed = curl_exec($ch);
        curl_close($ch);
        */
        
    $response wp_remote_request($url, array('headers' => array('user-agent' => 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)')));
        if ( 
    is_wp_error$response ) )
            return 
    '';
            
        if ( 
    200 != $response['response']['code'] )
            return 
    '';
                   
        return 
    $response['body'];

    Article authors check out: Resource Box Wizard

  2. Thanked by:

    m42 (12 October, 2010), Shenron (12 October, 2010), xrvel (21 October, 2010)

Similar Threads

  1. Wanted: Outlook Express replacement
    By UncleP in forum Tech-Talk
    Replies: 4
    Last Post: 5 January, 2011, 09:51 AM
  2. How to Install cURL in WAMP
    By Charles in forum Programming
    Replies: 3
    Last Post: 20 April, 2010, 09:37 AM
  3. latest finding : wordpress search replacement
    By anantshri in forum Blogging
    Replies: 2
    Last Post: 18 April, 2010, 20:52 PM
  4. Looking for a Dynamic Text/Image Replacement
    By Mr.Bill in forum Programming
    Replies: 2
    Last Post: 9 March, 2009, 10:32 AM
  5. cURL scraper queries
    By DickTracy in forum Programming
    Replies: 3
    Last Post: 1 January, 2009, 06:18 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •