我在将单个单词的字符串与句子或短语中的另一个字符串进行比较时遇到问题。如果值$ Cebu与$ address的值匹配相同的单词,我想从地址获取整个字符串。我的目标是,如果存在完全匹配的结果,则返回true,否则返回false。任何能帮助我的人都非常感激。
public function address(){
$Cebu = 'Cebu';
$lt = '10.2638281';
$lg = '123.60638549999999';
$str = $lt.','.$lg;
$url = 'http://maps.googleapis.com/maps/api/geocode/json?latlng='.trim($lt).','.trim($lg).'&sensor=false';
$json = @file_get_contents($url);
$data=json_decode($json);
$status = $data->status;
$address = $data->results[0]->formatted_address;
//Pinamungahan, Cebu, Philippines
}
您可以使用此比较...
if (strpos($string, $word) === FALSE) {
// word does NOT exists in string
} else {
// word DOES exist in string
}
请注意,strpos()区分大小写,如果要进行不区分大小写的搜索,请改用stripos()。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句