473,327 Members | 1,920 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,327 software developers and data experts.

Multiple spaces become single space when submitting

hie all

i got a form

Expand|Select|Wrap|Line Numbers
  1. <form name="TEST" method=POST action="test.php">
  2.  
  3. <input type="text" name="MyInput">
  4.  
  5. <input type="submit" name="ACTION" value="SAVE">
  6.  
  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
  1.  
  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. }
  9.  
  10.  
help me on this..thanks
Jun 25 '07 #1
5 6340
Purple
404 Expert 256MB
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">
<head>
<title>New document</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<form name="TEST" method=POST action="spaces.php">

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

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

</form>
<?php
if (!empty($_POST['MyInput'])) $var = str_replace(" ","*",$_POST['MyInput']);
else $var = "not set";
echo "==>".$var."<==";
?>
</body>
</html>[/PHP]

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
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
Purple
404 Expert 256MB
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 ?

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

solved

[PHP]
$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
[/PHP]
Jun 26 '07 #5
Purple
404 Expert 256MB
Hi

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

13
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...
3
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...
5
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...
32
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...
9
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...
1
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.
17
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...
135
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...
8
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
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: 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...
1
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: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.