我正试图从此字符串中获取信息:
UPS EXPRESSS_SAVER-1díahab。
EXPRESSS_SAVER
我尝试了以下代码: 它从字符串的4索引开始,到特殊字符“-”之前结束
$shippingMethod = "UPS EXPRESSS_SAVER - 1 día hab.";
$shippingServiceId = substr($shippingMethod, 4, strpos($shippingMethod,'-'));
这返回了我:EXPRESSS_SAVER - 1
我也尝试过:
$shippingServiceId = substr($shippingMethod, 4, strpos($shippingMethod,' '));
但是得到了:EXP
答案 0 :(得分:1)
您可以使用以下代码点获取EXPRESSS_SAVER
$shippingMethod = "UPS EXPRESSS_SAVER - 1 día hab.";
$shippingMethodArr = explode(" ",$shippingMethod);
$shipped = $shippingMethodArr[1];
答案 1 :(得分:0)
$shippingMethod = "UPS EXPRESSS_SAVER - 1 día hab.";
$position = 4;
$shippingServiceId = substr($shippingMethod, $position, strpos($shippingMethod,'-') - $position);
echo $shippingServiceId;