Page 1 of 1

Problems trimming whitespace

Posted: Mon Oct 31, 2005 7:29 pm
by mudvein
Guys, I've tried doing this so many different ways that my mind is now about to explode. I have a qury that, when I print it out, looks on my screen as follows :

Code: Select all

SELECT id, count(name) as total_names from NMname where name = '  

Steve' and id = '0' group by id
If you notice, There is a huge space and then some carriage returns in there. Now, I've tried trim, ltrim, preg_replace, ereg_replace, str_replace, and NONE of these things can get rid of this whitespace! I'm beginning to go mad trying to figure this out!

I've even went so far as to print out the actual variable that is holding the name value (strName).

It prints out, you guessed it, with the spaces and new line chars as well. I am completely lost with wonder here... any kind person that would like to help me would be much appreciated if they have come across this same issue...

Posted: Mon Oct 31, 2005 7:37 pm
by feyd
trim() should work just fine... maybe posting the code you tried?

Re: Problems trimming whitespace

Posted: Mon Oct 31, 2005 7:40 pm
by neophyte
mudvein wrote:If you notice, There is a huge space and then some carriage returns in there. Now, I've tried trim, ltrim, preg_replace, ereg_replace, str_replace, and NONE of these things can get rid of this whitespace!
White space in the query text? Post code please...

Posted: Mon Oct 31, 2005 9:18 pm
by mudvein

Code: Select all

function checkit($strName) {
   $strName = trim($strName);
   $check = "SELECT id, count(name) as total from NMname 
    where name = '".$strName."' and id = '0' group by id";
   echo '<br />'.$check.'<br />';
   echo 'The value of string is '.$strName.'<br />';
   //mysql_query($check);
   //$row = mysql_fetch_assoc($mysql_query);
}
as I say, I've tried using str_replace, eregi, trim, ltrim, etc... but nothing gets the whitespace out of that string... the string itself is coming from a file that I have parsed, so I don't know if there is some sort of special space character key one must use or what...but it's definately not liking me or what i'm attempting with it.

Posted: Mon Oct 31, 2005 9:27 pm
by m3mn0n
Error message?

Posted: Mon Oct 31, 2005 9:27 pm
by mudvein
so i guess my main question is, is there any way to tell php to display ALL characters as some thing other than invisible space? That way i could at least try to figure out what the hell is going on... Wether it's a crazy mixed thing like &#NA that represents a space, or whatever ? Dunno the proper term for this..

Posted: Mon Oct 31, 2005 9:28 pm
by mudvein
no error message at all..


Edit : I guess I mean, is there a way to display hidden characters as a human readable format (ie : a ' ' would be represented as %s, a ' ' tab would be represented as '%t', etc...

Posted: Mon Oct 31, 2005 9:37 pm
by feyd
since you are echoing the stuff out into HTML, htmlentities() would be useful..

Posted: Mon Oct 31, 2005 9:39 pm
by mudvein
k...maybe i shoulda tried this before.. firefox is not displaying any whitespace. maybe it's just ie's problem with css.. who knows. im going to bed. wasted 3 hours of my time on this bs problem.


ty feyd.

Posted: Mon Oct 31, 2005 9:43 pm
by mudvein
last question. what would <p> mean??? that is what IE is showing me now...

Posted: Mon Oct 31, 2005 9:46 pm
by feyd
<p> is a HTML tag for "paragraph"

Posted: Mon Oct 31, 2005 9:52 pm
by mudvein
well, when i used htmlentities, it said a <p> was before the char. And I don't know how to tell ereg or str_replace to search for a paragraph character.. any ideas?

Posted: Mon Oct 31, 2005 10:04 pm
by feyd
It's not a paragraph character. It's an HTML tag which, technically, is completely valid data. If you want to remove HTML from the input, use strip_tags() or the code I posted a while ago making a smarter strip_tags() (linked to from Useful Posts, link in my signature)

Posted: Mon Oct 31, 2005 10:12 pm
by mudvein
what can i say feyd, ur the man. strip tags worked like a charM! it worries me though, because when I echod the string out and viewed the source, there was no tags at all (not even in the file itself). Oh well, thanks muchos =D

Posted: Tue Nov 01, 2005 12:44 am
by Jenk
use mysql_real_escape_string() on $strName before using it in the query too.