目录
描述
Retrieve only the body from the raw response.
用法
<?php $body = wp_remote_retrieve_body($response); ?>
参数
返回值
(string)
The body of the response. Empty string if no body or incorrect parameter given.
示例
Retrieving data from a JSON API:
1 2 3 4 5 6 7 8 9 |
/* ---------------------------------- * wordpress之魂 © http://wphun.com * ---------------------------------- */ $url = '<a class="external free" href="http://example.org/api'">http://example.org/api'</a>; $response = wp_remote_get( esc_url_raw( $url ) ); /* Will result in $api_response being an array of data, parsed from the JSON response of the API listed above */ $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); |
历史
添加于 版本: 2.7.0
源文件
wp_remote_retrieve_body() 函数的代码位于 wp-includes/http.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
/* ---------------------------------- * wordpress之魂 © http://wphun.com * ---------------------------------- */ /** * Retrieve only the body from the raw response. * * @since 2.7.0 * * @param array $response HTTP response. * @return string The body of the response. Empty string if no body or incorrect parameter given. */ function wp_remote_retrieve_body( $response ) { if ( is_wp_error($response) || ! isset($response['body']) ) return ''; return $response['body']; } |
- 原文:http://codex.wordpress.org/Function_Reference/wp_remote_retrieve_body
- 翻译:黄聪@WordPress之魂