473,836 Members | 1,457 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multiple spaces become single space when submitting

3 New Member
hie all

i got a form

Expand|Select|Wrap|Line Numbers
  1. <form name="TEST" method=POST action="test.php">
  3. <input type="text" name="MyInput">
  5. <input type="submit" name="ACTION" value="SAVE">
  7. </form>
if i input "Welcome ", with a few spaces, i cannot get all the spaces. the $_POST['MyInput'] only give single space. can anyone help me

Expand|Select|Wrap|Line Numbers
  2. if ( isset($_POST['ACTION']) )
  3. {
  4.   if ( $_POST['ACTION'] == 'SAVE' )
  5.   {
  6.     $SQL = 'SELECT * FROM NAME WHERE NAME = \''.$_POST['MyInput'].'\'';  // this is where multiple spaces become single space
  7.   }
  8. }
help me on this..thanks
Jun 25 '07 #1
5 6374
404 Recognized Expert Contributor
Hi polturgiest and welcome to TSDN !!

I have just tested this using :

[PHP]<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<title>New document</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<form name="TEST" method=POST action="spaces. php">

<input type="text" name="MyInput">

<input type="submit" name="ACTION" value="SAVE">

if (!empty($_POST['MyInput'])) $var = str_replace(" ","*",$_POS T['MyInput']);
else $var = "not set";
echo "==>".$var."<== ";

and the spaces are maintained - I am running IIS, IE7 and PHP 5.1

try the code posted and confirm if the leading spaces are changed to *s

Regards Purple
Jun 25 '07 #2
3 New Member
i've tried this

[PHP]$var = $_POST['MyInput']; // for example "AH 1902" with 2 spaces
$tmp = str_replace(" ", "*", $var);
print "var is : ".$var." ( ".strlen($var). " )";
print "tmp is : ".$tmp." ( ".strlen($tmp). " )";[/PHP]

output :
[HTML]var is : AH 1F02 ( 8 )
tmp is : AH**1F02 ( 8 )[/HTML]

when i print var, its only give me one blank space (tried it by copying to notepad) even its return 8 when strlen it

any idea?
Jun 26 '07 #3
404 Recognized Expert Contributor
Hi polturgiest,

What you are seeing is your browser rendering the two spaces to one - this is not happening within your code - this is confirmed by the string length of the two variables at 8 chars..

This removal of spaces is normal behaviour for HTML.

What is the issue with the database query ?

Jun 26 '07 #4
3 New Member
i cannot find macthing records before using this, bcoz most of my records got many spaces :( .


$var = str_replace(' ', '&nbsp;', 'Micheal Owen'); // with multiple spaces
print $var; // the result

// when query i used this

$SQL = 'select name from player where name = \''.str_replace ('&nbsp;', ' ', $var).'\''; // working its take all the spaces
Jun 26 '07 #5
404 Recognized Expert Contributor

Good job, pleased you got there

Regards Purple
Jun 26 '07 #6

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

Similar topics

by: p s | last post by:
hi all i have a vb6 project, one of the functions is to read in a text file and place it into an array problem is, when people use the TAB key in the original file that is read, i just get the tab code in the string, what i need is for the TAB to literally become that many SPACES ... the problem is this can vary depending on where exactly the TAB key is hit! i have tried
by: DarthMacgyver | last post by:
Hello, I recently wrote a survey application. Each question is very similar. The first questions gives me a problem when there are multiple people taking the survey (The Database connection Timed out) I am using the Data Access Application Blocks as ASP.NET (using VB.NET) and SQL 2000. In there first question there can be up to 27 answers. So I figured instead of making 27 different trips to the database I woulc just concatenate my...
by: Christine | last post by:
I have a text file that appears to be delimited by multiple spaces. The split function will only work with one space if I am correct. Is there some way to split this file into an array without getting the extra spaces?
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if ((someString.IndexOf("something1",0) >= 0) || ((someString.IndexOf("something2",0) >= 0) ||
by: Graham | last post by:
I have been having some fun learning and using the new Controls and methods in .Net 2.0 which will make my life in the future easier and faster. Specifically the new databinding practises and wizards. But, I have found that trying to do something "outside the norm" adds a rather large level of complexity and/or data replication. Background I have been commissioned to create a web-based application for a client. It has a formsaunthentication...
by: Vikram | last post by:
I have a label control whose text is having multile spaces "Name :" but when this is rendered as html in an aspx page it only shows single space. How to render with multiple spaces.
by: tommy | last post by:
Hi all, I' m adding strings to some fields in my table via Access. The strings sometimes have trailing spaces and I really need to have it that way, but Access truncates trailing spaces. How can I force Access not to truncate?! Thanx, /Toommy
by: Xah Lee | last post by:
Tabs versus Spaces in Source Code Xah Lee, 2006-05-13 In coding a computer program, there's often the choices of tabs or spaces for code indentation. There is a large amount of confusion about which is better. It has become what's known as “religious war” — a heated fight over trivia. In this essay, i like to explain what is the situation behind it, and which is proper.
by: Joe Cool | last post by:
I need to map several columns of data from one database to another where the data contains multiple spaces (once occurance of a variable number or spaces) that I need to replace with a single space. What would be the most efficient way to do this? I am using SQL2K. I was thinking a function since I know of no single Transact-SQL command that can accomplish this task.
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.