dpymrcl269187540 2011-07-08 08:04
浏览 39
已采纳

将SimpleXML转换为cURL

My host has allow_url_fopen disabled and they will not enable it for me. I need the following code to work for a WordPress plugin. Can someone please give me pointers as to how to convert this code to cURL?

else:
    $results = $wpdb->get_results($wpdb->prepare("SELECT mcd_id FROM mcd_cl_coupons WHERE coupon_list_id = %d AND created_by = 'mcd'", array($coupon_list_id)));
    $mcd_id = ''; foreach($results as $row): $mcd_id .= '-' . $row->mcd_id; endforeach; $mcd_id = substr($mcd_id, 1);
    if($mcd_id): 
        $options = get_option('mcd_list');
        $token = $options['api_key'];
        $xml_file = 'http://www.mycoupondatabase.com/api/coupons-xml.php?token=' . $token . '&id_string=' . $mcd_id;
        $xml = simplexml_load_file($xml_file);
    endif;
  • 写回答

2条回答 默认 最新

  • duanliang8464 2011-07-08 08:39
    关注

    Wordpress has a function build in to request a file called wp_remote_get:

        $xml_file = 'http://www.mycoupondatabase.com/api/coupons-xml.php?token=' . $token . '&id_string=' . $mcd_id;
        $xml_data = wp_remote_get($xml_file);
        $xml = simplexml_load_string($xml_data['body']);
    

    That function internally makes use of the HTTP abstraction wordpress comes with which normally figures out the best way to do HTTP requests for the system it's running on. So it will use cUrl if everything else is restricted on your host.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部