473,320 Members | 2,110 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Function to trim space also removes zeros

KeredDrahcir
426 256MB
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:
Expand|Select|Wrap|Line Numbers
  1.   function trim_value(&$value)
  2.   {
  3.     $value = trim($value, " , ");
  4.     $value = str_replace(" ", ' ', $value);
  5.   }
To remove the tags I'm using this function:
Expand|Select|Wrap|Line Numbers
  1.   function tag_remove(&$value)
  2.   {
  3.     $value = strip_tags($value);
  4.   }
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?
Sep 30 '10 #1

✓ answered by KeredDrahcir

I don't know what was happening but I changed my trim_value function to do this:
Expand|Select|Wrap|Line Numbers
  1.   function trim_value(&$value)
  2.   {
  3.     $value = trim($value, " , ");
  4.     $value = str_replace(" ", ' ', $value);
  5.     $value = str_replace("0", "0", $value);
  6.   }
The last line seemed to sorted it out although it removed the last few characters from the array but this is acceprtable.

4 1616
johny10151981
1,059 1GB
what do you mean by zero?
Sep 30 '10 #2
KeredDrahcir
426 256MB
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.
Oct 1 '10 #3
KeredDrahcir
426 256MB
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.
Expand|Select|Wrap|Line Numbers
  1.   //This fuction is almost the same as the fuction str_split included in php5.
  2.   function strsplt($thetext,$num)
  3.   {
  4.     if (!$num)
  5.     {
  6.       $num=1;
  7.     }
  8.     $arr=array();
  9.     $xfive=floor(strlen($thetext)/$num);
  10.     while ($ifive<=$xfive)
  11.     {
  12.       $yfive=substr($thetext,$jfive,$num);
  13.       if ($yfive)
  14.       {
  15.         array_push($arr,$yfive);
  16.       }
  17.       $ifive++;
  18.       $jfive=$jfive+$num;
  19.     }
  20.     return $arr;
  21.   }
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?
Oct 1 '10 #4
KeredDrahcir
426 256MB
I don't know what was happening but I changed my trim_value function to do this:
Expand|Select|Wrap|Line Numbers
  1.   function trim_value(&$value)
  2.   {
  3.     $value = trim($value, " , ");
  4.     $value = str_replace("&nbsp;", ' ', $value);
  5.     $value = str_replace("0", "0", $value);
  6.   }
The last line seemed to sorted it out although it removed the last few characters from the array but this is acceprtable.
Oct 1 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Ashlie | last post by:
I am trying to develop a script that takes out the white space at the FRONT and the BACK of a string but not the middle. I have a string that looks like this: XXXX XXXX XXXX XXXX The...
4
by: sam | last post by:
Hi, I can't figure out what is the problem of the following coding. #ifndef __PARSER__ #define __PARSER__ #include <iostream> #include <string> #include <fstream> //#include <exception>
11
by: Reply Via Newsgroup | last post by:
Folks, In PHP and some other scripting languages, one has trim() - It removes newline, tabs and blank spaces that might prefix, or suffix a string. Can someone tell me how I can do this in...
12
by: Robert Mark Bram | last post by:
Hi All, I am using the following trim function: function trim (str) { return str.replace(/^\s*/g, '').replace(/\s*$/g, ''); } The problem is that this doesn't trim instances of the...
11
by: Darren Anderson | last post by:
I have a function that I've tried using in an if then statement and I've found that no matter how much reworking I do with the code, the expected result is incorrect. the code: If Not...
8
by: rayw | last post by:
Following on from my post yesterday about nums -> binary strings ... I've written two routines that can trim the leading zeros from the results, so I call either of these like this: char *...
4
by: ImOk | last post by:
I come from the Visual Foxpro world, which is one reason I love PHP. VFP is a scripting type language with macro substitution abilities similar to PHP. Besides the regular expansion I can do...
3
by: Pascal | last post by:
bonjour hello I would like to trim a string of all its white spaces so i used myString.trim() but it doesn't work as supposed : unsecable space are remaining in the middle of my string... i...
4
by: Oleg Subachev | last post by:
If I apply Trim() method to string consisting of two x0D and x0A characters the resulting string is not empty but contain the same two charaters: x0D, x0A. But according to the help Trim()...
12
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I trim whitespace - LTRIM/RTRIM/TRIM?...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.