Results 1 to 3 of 3

Thread: array is given instead of a string

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    447

    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($text5);

    print_r($solo);
    print_r($quintet);
    echo 
    "end";
        
    /********************************************************************************/ 
    Compare bible texts (and other tools):
    TheWheelofGod

  2. #2
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    1,023

    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; 
    }

  3. #3
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    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
  •  



Click Here to Expand Forum to Full Width