•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 392,083 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,962 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1622 | Replies: 5 | Solved
![]() |
•
•
Join Date: Feb 2007
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
Hello everyone,
I have a MSSQL db with PHP front end.
The data in the table is similiar to:
"Two spaces" with 2 white spaces in the middle.
When I use this code:
In the DB, and when I use another query analyzer, I get the correct return of "Two spaces" with 2 white spaces in the middle.
BUT...in PHP when I echo $Name, one of the two spaces has been deleted.
So I echo "Two spaces" with 1 white spaces in the middle.
I need the varchar to be exactly like it is in the DB, and I CANNOT change the data to one space.
Does anyone know what is causing this? Is there someting in the php.ini file that would do this?
PLEASE HELP I AM STUCK!!
-Joe
I have a MSSQL db with PHP front end.
The data in the table is similiar to:
"Two spaces" with 2 white spaces in the middle.
When I use this code:
$sql = "select Name FROM Name_TBL WHERE Number = '$Num";
$rs = mssql_query($sql);
$RT = mssql_fetch_array($rs);
$Name= $RT[Name'];In the DB, and when I use another query analyzer, I get the correct return of "Two spaces" with 2 white spaces in the middle.
BUT...in PHP when I echo $Name, one of the two spaces has been deleted.
So I echo "Two spaces" with 1 white spaces in the middle.
I need the varchar to be exactly like it is in the DB, and I CANNOT change the data to one space.
Does anyone know what is causing this? Is there someting in the php.ini file that would do this?
PLEASE HELP I AM STUCK!!
-Joe
Last edited by joezyz : Feb 22nd, 2007 at 4:15 pm. Reason: spellin and clarificaiton
•
•
Join Date: Jan 2007
Posts: 37
Reputation:
Rep Power: 2
Solved Threads: 3
Hi joe,
There isn't any problem at all because PHP really outputs series of spaces as just one. I suggest that you either configure the script that inserts the records in the database to automatically converts series of spaces to just one or explode your string to an array such that 1 character string = 1 array element and out each element separately. Hope this helps.
There isn't any problem at all because PHP really outputs series of spaces as just one. I suggest that you either configure the script that inserts the records in the database to automatically converts series of spaces to just one or explode your string to an array such that 1 character string = 1 array element and out each element separately. Hope this helps.
•
•
Join Date: Oct 2006
Location: Sofia, Bulgaria
Posts: 135
Reputation:
Rep Power: 2
Solved Threads: 7
•
•
Join Date: Feb 2007
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
Thanks everyone, but the Data in the Database CANNOT be changed.
The job of any database extension is the display the data EXACTLY as it is written in the DB. It should not re-write the data based on arbitrary rules.
This page is dynamic. Some of the data returned has one space, this one record has two. I cannot make a rule that changes all of the dat to 2 spaces.
The actual data has 4 parts, each separated by a space, and one, separated by 2 spaces. (on this record only). The other records have 1 space.
The explode does not work, because I need to reconstruct the name, and I cannot do this dynamically, because programatically, the computer does not know where the 2 spaces will go.
Does anyone know if there is another way to get the data other than mssql_fetch_* (row, array, etc) from a MSSQL DB that will NOT change the data from what is written in the DB?
Thanks!!!
Please keep the suggestions comming.
The job of any database extension is the display the data EXACTLY as it is written in the DB. It should not re-write the data based on arbitrary rules.
This page is dynamic. Some of the data returned has one space, this one record has two. I cannot make a rule that changes all of the dat to 2 spaces.
The actual data has 4 parts, each separated by a space, and one, separated by 2 spaces. (on this record only). The other records have 1 space.
The explode does not work, because I need to reconstruct the name, and I cannot do this dynamically, because programatically, the computer does not know where the 2 spaces will go.
Does anyone know if there is another way to get the data other than mssql_fetch_* (row, array, etc) from a MSSQL DB that will NOT change the data from what is written in the DB?
Thanks!!!
Please keep the suggestions comming.
•
•
Join Date: Oct 2006
Location: Sofia, Bulgaria
Posts: 135
Reputation:
Rep Power: 2
Solved Threads: 7
Normally both PHP and HTML are ignoring multiple spaces and display them as one single space.
If you're sure you get the correct data from the database, trya simple test over the result.
[php]
$name = str_replace (' ', ':', RT['yourresult here']);
echo $name;
[/php]
If you receive the data correctly from the DB, your spaces should be replaced by columns. So if you have returned 2 spaces from the DB, you should see a result like this
value1::value2
Then, if you get the correct result, run the same function but like this:
str_replace(' ', ' ', rt['your result here']);
NOTE THAT THERE IS A SPACE BETWEEN THE FIRST QUOTES
If you're sure you get the correct data from the database, trya simple test over the result.
[php]
$name = str_replace (' ', ':', RT['yourresult here']);
echo $name;
[/php]
If you receive the data correctly from the DB, your spaces should be replaced by columns. So if you have returned 2 spaces from the DB, you should see a result like this
value1::value2
Then, if you get the correct result, run the same function but like this:
str_replace(' ', ' ', rt['your result here']);
NOTE THAT THERE IS A SPACE BETWEEN THE FIRST QUOTES
Last edited by Rhyan : Feb 23rd, 2007 at 10:32 am. Reason: addding more detail
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
- help with php redirection (PHP)
- PHP in a html page? (PHP)
- Need help in create file php (PHP)
- IE6 has been constantly hijacked by .... (Viruses, Spyware and other Nasties)
Other Threads in the PHP Forum
- Previous Thread: Migration problem with website
- Next Thread: Problem with $_POST


Linear Mode