PHP - Need Help With Getting Rid Of Whitespaces
Ok, i've encountered the worse bug in my life. I worked over it for about 12 hours until I found the source, and as always, it is somthing quite stupid...
after long research I found that the problem is that there are whitespaces in my DB... the thing is, that I can't get rid of them... I tried to use "trim" - like this: Code: [Select] $name = trim($name);and like this: Code: [Select] $name = trim($name, ' '); I tried: Code: [Select] if ($name[0] = ' ') $name[0] = '' but the little white spaces are still there. I thought it might be non-breaking space html char but when I looked at the source it was still a tiny space. any ideas? thanks When I checked it in phpMyAdmin I couldn't see it in the result list, but when I edited a row it was there and I was able to delete it... I'm not sure what else data is required but please ask anything you need because I'm running out of ideas Similar TutorialsHi, Now I'm working with Joomla! site with virtuemart shop engine, and my problem is I sometimes find an annoying whitespaces. These whitespaces create an empty space that destruct the layout. I've manage to remove it with jquery trim. However, it must also be done with PHP because the script seems to consider this as not empty, so the modules, which suppose to be hidden if it's empty, is just displaying empty space. I've tried trim, but it's not working.. it's still showing empty string. Like the image bellow if I open the browser console (circled): If i copy the whitespace from the console and paste it to notepad, it shows me empty space and some question marks (?). Is there any advice how to get rid of this annoying problem? Thanks, ayok Hy ya'll! I've been trying to programatically read a string, but with no success. Code: [Select] function get_between($input, $start, $end) { $substr = substr($input, strlen($start)+strpos($input, $start), (strlen($input) - strpos($input, $end))*(-1)); return $substr; } $string = 'open -greetings hello -bye seeya'; echo get_between($string, '-greetings ', ' -bye'); // Output: hello echo get_between($string, '-greetings ', ' -'); // Outputs nothing echo get_between($string, '-greetings ', ' '); // Outputs nothing } It turns out that I don't know if "-bye" will always follow the value of "-greetings", so I can't call everything in between like the first way even tough it works fine in this example. Given that those values will always be a single word, I can use a whitespace as a delimiter to the right, but for some reason it won't return anything whatsoever, not even an error code. Any ideas how to get it done? Txs a bunch! Code: [Select] <label for="first_name">* First Name </label> <input type="text" name="first_name" maxlength="64" value=<?php echo formatPhone(clean_input($_POST['first_name']); ?>> I have a form where I want to enter a first name. I want the fields to take only alphabets(no numbers). Also when a user enters something like John Doe separated by multiple white spaces, I want it to separate the two words only by a single space. I am not sure how this is done in php. I'm new in php and I don't have knowledge of php.
I just want to know, whenever we download file from server to Desktop through FTP, there are whitespaces occuring in files.
Like html websites, we always remove whitespaces whenever we upload the file to server after editing it. Is this step necessary for php websites also? If necessary then how to do it?
|