我有一個API調用,返回具有以下格式的字段meetingAddress。 街道「 」城市「,」州ZipCode。本例中的「」是顯示匹配字符落入字符串的位置。從字符串返回城市和州
我已經擺弄了substr和strpos,但由於我的極限經驗似乎無法讓它工作。我正在寫一個函數來接收地址並返回城市和州。
$str needs to be populated with the MeetingAddress data
$from = "#xD;"; - this is always before the city
$to = ","; - this is after the city
echo getStringBetween($str,$from,$to);
function getStringBetween($str,$from,$to)
{
$sub = substr($str, strpos($str,$from)+strlen($from),strlen($str));
return substr($sub,0,strpos($sub,$to));
}
下面是返回內容的確切示例。
<d:MeetingAddress>44045 Five Mile Rd
Plymouth, MI 48170-2555</d:MeetingAddress>
這是第二個例子:
<d:MeetingAddress>PO Box 15526
Houston, TX 77220-5526</d:MeetingAddress>
後從API返回的字符串的確切實例。 – AbraCadaver
字符串在哪裏?提供一個你得到的迴應的例子。 –
我附加了對問題的回答。謝謝! – Johanna