array is given instead of a string
I'm getting this error:
Quote:
Warning: mb_strlen() expects parameter 1 to be string, array given in ../getBibleCodeinclude.php on line 30
PHP Code:
function mb_str_split($str, $length = 1){
if ($length < 1) return FALSE;
$result = array();
for ($i = 0; $i < mb_strlen($str); $i += $length) {
$result[] = mb_substr($str, $i, $length);
}
return $result;
}
for($tdid=0; $tdid < count($id); $tdid++){
$strText=stripslashes(mysql_escape_string($textData[$tdid]));
include("../includefiles/vowelmarks.php");
for($i=0; $i<count($vm); $i++){
//echo $vm[$i];
$strText=str_replace($vm[$i], "", $strText);
}
$text=str_split($strText);
/********************************************************************************/
//$text = "süpérbrôsé";
$solo = mb_str_split($text);
$quintet = mb_str_split($text, 5);
print_r($solo);
print_r($quintet);
echo "end";
/********************************************************************************/
Re: array is given instead of a string
http://php.net/manual/en/function.mb-strlen.php
the problem is that you need to add character encoding, or correct me if i'm wrong.
Code:
function mb_str_split($str, $length = 1){
if ($length < 1) return FALSE;
$result = array();
for ($i = 0; $i < mb_strlen($str, 'UTF-8'); $i += $length) {
$result[] = mb_substr($str, $i, $length);
}
return $result;
}
Re: array is given instead of a string
Using the character encoding in mb_strlen() is optional.
Do you understand the warning message? The function expected a string, but you gave it an array - so the first thing to look at is what is going into the function. Looks like $text is going in, and what is in $text?
Code:
$text=str_split($strText);
str_split() returns an array. $text is an array.