php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40607 mssql_fetch_array concatinates spaces in middle of data
Submitted: 2007-02-23 15:59 UTC Modified: 2007-02-23 21:06 UTC
From: Joe at sofusion dot com Assigned:
Status: Not a bug Package: MSSQL related
PHP Version: 5.2.1 OS: FREE BSD 6.0
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: Joe at sofusion dot com
New email:
PHP Version: OS:

 

 [2007-02-23 15:59 UTC] Joe at sofusion dot com
Description:
------------
When using mssql_fetch_arry and mssql_fetch_row, data returned that contains 2 spaces has been concatinated to one space.  Example:
Data returned should be "Two"' '' '"Spaces" (without quotes  Two  Spaces)
But is returned as "Two"' '"Spaces" (without quotes -Two Spaces with one space between)

FreeBSD WEBSERVER1.SOFUSION.local 6.0-RELEASE FreeBSD 6.0-RELEASE #0: Thu Nov 3 09:36:13 UTC 2005 root@x64.samsco.home:/usr/obj/usr/src/sys/GENERIC i386  

Build Date  Feb 22 2007 19:36:38  

Configure Command  './configure' '--with-apxs=/usr/local/apache/bin/apxs' '--enable-versioning' '--with-mssql=/usr/local' '--enable-libxml'  

Library version  FreeTDS  



Reproduce code:
---------------
--MSSQL TABLE

CREATE TABLE #T1( Name varchar(255),
Number int )
INSERT INTO #T1 VALUES('Two  Spaces',1)
INSERT INTO #T1 VALUES('One Spaces',2)


--PHP CODE

$sql = "select Name FROM Name_TBL  WHERE Number = '1'";
$rs = mssql_query($sql);
$RT = mssql_fetch_array($rs);
$Name= $RT[Name'];
--This should have 2 spaces in it like the DB
--But it only has one
echo $Name




Expected result:
----------------
Two  Spaces
--This has 2 spaces between the words.

Actual result:
--------------
Two Spaces
--This only hase 1 space between the words

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-02-23 16:18 UTC] Joe at sofusion dot com
Sorry, dont use # in TBL Name.  USE THIS DB CODE AND PHP CODE TO TEST:

CREATE TABLE T1( Name varchar(255),
Number int )
INSERT INTO T1 VALUES('Two  Spaces',1)
INSERT INTO T1 VALUES('One Spaces',2)



$sql = "SELECT Name FROM T1 WHERE Number = '1'";
$rs = mssql_query($sql);
while ($RT = mssql_fetch_array($rs)) 
{$Name= $RT['Name'];
//This should have 2 spaces in it like the DB
//But it only has one
echo ' <p>Name = '.$Name . '</p>';
}
 [2007-02-23 19:29 UTC] fmk@php.net
I'm unable to reproduce this (on Linux and WIndows with FreeTDS). Try viewing the result outside the browser, use <pre></pre> or get the length of the column to verify that you are getting the right results.
 [2007-02-23 20:16 UTC] Joe at sofusion dot com
When I use the <pre></pre> tags, It does display the correct data.  Is this telling me that it is HTML that is concatinating the 2 spaces into one?
Also you can use:
$Name = str_replace (' ', ':', $RT['Name']);
echo ' <p>Name2 = '.$Name . '</p>';
to see the 2 spaces.

When you duplicate the bug, do you have 2 spaces between the words in your browser?
Thanks!!
 [2007-02-23 20:40 UTC] fmk@php.net
This is a normal browser feature. The browser will reduce the whitespace (spaces, tabs new lines etc) to a single space. You could replace each space with &nbsp; if you want to force two spaces.
 [2007-02-23 21:01 UTC] Joe at sofusion dot com
Thanks!!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Oct 08 22:01:27 2024 UTC