|
-
Jan 19th, 2011, 01:06 AM
#1
Thread Starter
Hyperactive Member
array is given instead of a string
I'm getting this error:
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";
/********************************************************************************/
-
Jan 19th, 2011, 11:50 AM
#2
Fanatic Member
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;
}
-
Jan 19th, 2011, 12:09 PM
#3
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|