2 回答
TA贡献1843条经验 获得超7个赞
检查您下面的代码,该代码正在发送多次请求。
while ($response == null) {
array_splice($array, -1);
$FinalAddress = implode(" ", $array);
$response = $this->CallApi($FinalAddress);
}
while ($response->num < 1) {
array_splice($array, -1);
$FinalAddress = implode(" ", $array);
$response = $this->CallApi($FinalAddress);
}
TA贡献1818条经验 获得超3个赞
我找到了我的遮阳篷
public function check($id)
{
//find addres from dataabase
$address = Address::find($id);
$Address = $address->Address;
//check for its address or no
if (strpos($Address, 'STR') || strpos($Address, 'S ') || strpos($Address, "Alley") || strpos($Address, "A ") || strpos($Address, 'number ') !== false) {
//validate address and remove unnecessary details
$FinalAddress = $this->ValidateArray($Address);
//call api
$response = $this->CallApi($FinalAddress);
//update database
$address->FoundedAddress = $response->result[0]->title;
$address->Status = 2;
$address->save();
echo "Searched Address : ". $FinalAddress;
echo "<br/><br/><br/><br/><br/>";
echo "Founded Address : " . $response->result[0]->title;
}else{
echo "Address Not Valid";
}
}
和验证函数
//remove ، from address
if (strpos($address, "،")) {
$address = explode("،", $address);
$address = implode(" ", $address);
}
//remove - from address
elseif (strpos($address, "-")) {
$address = explode("-", $address);
$address = implode(" ", $address);
}
remove title and : from address
if (strpos($address, ":")) {
$address = strstr($address, ':');
$address = str_replace(":", "", $address);
}
//we found the (anyting) and remove that
if (strpos($address , ")") ){
$start = "(";
$end = ")";
$replace = " ";
$pos1 = strpos($address , $start);
$pos2 = strpos($address , $end , $pos1);
$lenght = $pos2 + strlen($pos1) - $pos1;
$address = substr_replace($address , $replace , $pos1 , $lenght);
}
//remove number from address
if (strpos($address, "number")) {
$address = substr($address, 0, strpos($address, "nmber"));
}
//remove floor from address
if (strpos($address, "floor")) {
$address = substr($address, 0, strpos($address, "floor"));
}
- 2 回答
- 0 关注
- 112 浏览
添加回答
举报