我对来自apparel21 api的创建人的反应低于此。
HTTP/1.1 201 Created
Cache-Control: private
Location: https://domainName.com.au:8181/retailapi_test/Persons//15668?countryCode=AU
Server: Microsoft-IIS/7.5
X-AspNetMvc-Version: 3.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Mon, 10 Aug 2015 07:11:38 GMT
Content-Length: 0
有没有办法使用哪些我只能检索文本上方的人员ID(15668)? 请任何人帮忙。
答案 0 :(得分:1)
PHP代码:
$hdr_array = http_parse_headers($header);
$str = $hdr_array['Location'];
//$str = 'https://domainName.com.au:8181/retailapi_test/Persons//15668?countryCode=AU';
echo getStringBetween($str , 'Persons//', '?countryCode');
function getStringBetween($str,$from,$to)
{
$sub = substr($str, strpos($str,$from)+strlen($from),strlen($str));
return substr($sub,0,strpos($sub,$to));
}
使用这两个答案 -
答案 1 :(得分:0)
您可以使用$hdr_array = http_parse_headers($header);
$string = $hdr_array['Location'];
//$string = "https://domainName.com.au:8181/retailapi_test/Persons//15668?countryCode=AU";
$personID = parse_url($string, PHP_URL_PATH);
$personID = str_ireplace('/retailapi_test/Persons//', '', $personID);
echo $personID;
功能来展开网址。
尝试
add_action('woocommerce_before_checkout_form', 'mme_send_mail'); function mme_send_mail(){
global $woocommerce;
$items = $woocommerce->cart->get_cart();
$msg = "Description\n------------------------------------"; foreach($items as $item) {
$_product = $item[ 'data' ]->post;
$msg .= "\nItem\t:".$_product->post_title."\nQuantity\t:".$item['quantity'];
$price = get_post_meta($item['product_id'] , '_price', true);
$msg .= "\nPrice\t:".$price;
}
$msg .= "\n----------------------------------------\nTotal amount\t:".$woocommerce->cart->get_cart_total();
$to = get_option('custom_email');
$subject = "Acknowledgment";
wp_mail($to, $subject, $msg);}
答案 2 :(得分:0)
另一个问题,使用preg_split和preg_match等
$headerlist="
HTTP/1.1 201 Created
Cache-Control: private
Location: https://domainName.com.au:8181/retailapi_test/Persons//15668?countryCode=AU
Server: Microsoft-IIS/7.5
X-AspNetMvc-Version: 3.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Mon, 10 Aug 2015 07:11:38 GMT
Content-Length: 0";
$location=false;
$pieces=array_filter( preg_split( '@\n@', $headerlist ) );
foreach( $pieces as $pair ) {
list( $param, $value )=preg_split( '@:\s@',$pair );
if( strtolower( trim($param) )=='location' ){
$location=$value;
break;
}
}
$path=parse_url( $location, PHP_URL_PATH );
preg_match('@\d+@',$path,$matches);
$userid=$matches[0];
echo 'userid:'.$userid;