Removeing blank spaces

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • KeredDrahcir
    Contributor
    • Nov 2009
    • 426

    Removeing blank spaces

    I have some values in an array and I need to remove the blank spaces before them.
    I've used
    Code:
    array_walk($context_array, 'trim_value');
    To trim the spaces using the function:
    Code:
      function trim_value(&$value)
      {
        $value = trim($value, "\xC2\xA0");
      }
    This seems to have no effect. I need to convert my values into an array of single characters. I don't have PHP 5 so I've used a function to do the same job as str_split.

    Code:
      //This fuction is almost the same as the fuction str_split included in php5.
      function strsplt($thetext,$num)
      {
        if (!$num)
        {
          $num=1;
        }
        $arr=array();
        $xfive=floor(strlen($thetext)/$num);
        while ($ifive<=$xfive)
        {
          $yfive=substr($thetext,$jfive,$num);
          if ($yfive)
          {
            array_push($arr,$yfive);
          }
          $ifive++;
          $jfive=$jfive+$num;
        }
        return $arr;
      }
    However when I get the result for the blank space are not removed and for sections where I've used &#160; it has changed it to  which means I get wired looking symbols. Can anyone suggest what it happening?
  • KeredDrahcir
    Contributor
    • Nov 2009
    • 426

    #2
    I'd like to know why this happened. I've fixed it chanigng the trim function to this:
    function trim_value(&$va lue)
    {
    $value = trim($value, "&#160;, ");
    }

    I'd like to fix it proerly though.

    Comment

    Working...