I use these code to splite a Phone number String into area code and call number.
When i use "strlen($areacode)" i get a php warning strlen() expects parameter 1 to be string, array given.
When is use count () instead of strlen(), the script is wrong execute. I get the result "No AreaCode found".
What make i wrong?
<?php
$phonenumber = '0349152023';
$link = mysqli_connect('host', 'DB', 'Pass','User') or die(mysqli_error());
$db_selected = mysqli_select_db( $link, 'DB');
$ErsteDrei = substr($phonenumber,0,3);
$array = array();
$query = mysqli_query($link, "SELECT Areacode FROM `Areacodes` WHERE Vorwahl like '".$ErsteDrei."%' ORDER BY CHAR_LENGTH(Vorwahl) DESC");
while($row = mysqli_fetch_assoc($query)){
$array[] = $row;
}
foreach ($array as $areacode) {
$subString = substr($phonenumber, 0, strlen($areacode));
if ($subString == $areacode) {
$phone = $subString." ".substr($phonenumber, strlen($areacode));
}
}
if (!empty($phone)) {
echo $phone;
}
else {
echo "No AreaCode found.";
}
?>