Home > Article > Backend Development > The php code hidden by the characters behind the province and city
This article mainly shares with you the method of hiding the characters behind provinces and cities in PHP. We will share it in the form of code, hoping to help everyone.
//隐藏省市区后面的字符串,只显示到省市区 public static function changeToArea($address) { if(strpos($address,'区') !== false) { $b = substr($address,0,strrpos($address,'区')).'区'; } if(strpos($address,'县') !== false) { $b = substr($address,0,strrpos($address,'县')).'县'; } if(strpos($address,'市') !== false && strpos($address,'县') !== false) { $b = substr($address,0,strrpos($address,'市')).'市'; } return $b; }
Related recommendations:
php Issues related to string replacement where some characters are hidden and changed to *
The above is the detailed content of The php code hidden by the characters behind the province and city. For more information, please follow other related articles on the PHP Chinese website!