I'm very newbie in PHP and I have a problem in filtering a value. Here my case :
- when I call data
$originfrom a database the result is a country code, example:US, GB, AU, BR, PT, or MX - then, I want to filter them example: if the code is between
US, GB, AU=EN, if the code is betweenBR, PT, MX=PT, and if the code is besideUS, GB, AU, BR, PT, MX=INT, and if there is an error when calling data$origin=ERROR
I already search the solution but not of them is solving the problem as I'd expected. Here some of the code :
$origin = 'AU';
$geo = array('US', 'AU', 'UK');
foreach ($geo as $result) {
//if (strstr($string, $url)) { // mine version
if (strpos($origin, $result) !== FALSE) { // Yoshi version
echo "EN";
return true;
}
}
echo "INT";
return false;
and
$origin = 'BR';
if (strpos($origin,'US') !== false) { //first we check if the url contains the string 'en-us'
$result = str_replace('US', 'EN', $origin); }
else {
$result = str_replace('BR', 'PT', $origin);
}
echo $result
I want to filter based on my cased and I want the result can call by using echo $result
Thanks
Aucun commentaire:
Enregistrer un commentaire