我的主机已禁用 allow_url_fopen,他们不会为我启用它。我需要以下代码才能为 WordPress 插件工作。有人可以指点一下如何将此代码转换为 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;
最佳答案
Wordpress 内置了一个函数来请求名为 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']);
该函数在内部使用 wordpress 附带的 HTTP 抽象,它通常会找出对其运行的系统执行 HTTP 请求的最佳方式。因此,如果您的主机上的其他一切都受到限制,它将使用 cUrl。
关于php - 将 SimpleXML 转换为 cURL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6627191/