Function to trim space also removes zeros

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

    Function to trim space also removes zeros

    I have two functions to format the result that I get from a table. I want to remove any leading and trailing spaces and also remove any HTML tags.

    To remove the spaces I'm using this function:
    Code:
      function trim_value(&$value)
      {
        $value = trim($value, " , ");
        $value = str_replace(" ", ' ', $value);
      }
    To remove the tags I'm using this function:
    Code:
      function tag_remove(&$value)
      {
        $value = strip_tags($value);
      }
    For some reason the zeros in the text as also removed or not shown. Is there something in these functions that does that or is it likly it's being done somewhere else?
  • johny10151981
    Top Contributor
    • Jan 2010
    • 1059

    #2
    what do you mean by zero?

    Comment

    • KeredDrahcir
      Contributor
      • Nov 2009
      • 426

      #3
      The result I am getting is this:

      8, years of scholarship, plus integrated and friendly help wizards, expert systems, and compatible interfaces make the Encyclopedia Galactica the definitive reference work for the Civilized Ga

      It should say 8,000 years, and I've tried it on something else that had 1999-2,000 and it came out at:
      1999-2,
      Any where else things come out fine but zeros seem to be cut off.

      Comment

      • KeredDrahcir
        Contributor
        • Nov 2009
        • 426

        #4
        I think something was translated in my first post that wasn't supposed to be. It's not either of the two functions I posted it's a different one that had the problem.

        I'm using php4 and needed str_split which isn't available until php5. I wrote a function to do the same thing.
        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;
          }
        I think this function is what is removeing the zeros. Could any suggest why?
        The only other option is I'm using a loop to echo the returned value of this function one character at the time (to put into bold a specific phrase). Could it be that the loop is missing out any array values that are zero even thought they should be?

        Comment

        • KeredDrahcir
          Contributor
          • Nov 2009
          • 426

          #5
          I don't know what was happening but I changed my trim_value function to do this:
          Code:
            function trim_value(&$value)
            {
              $value = trim($value, "&#160;, ");
              $value = str_replace("&nbsp;", ' ', $value);
              $value = str_replace("0", "&#48;", $value);
            }
          The last line seemed to sorted it out although it removed the last few characters from the array but this is acceprtable.

          Comment

          Working...