Re: Compacting multiple spaces...

From: Date: Fri, 14 Apr 2006 19:51:13 +0000
Subject: Re: Compacting multiple spaces...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-234017@lists.php.net to get a copy of this message
On Friday 14 April 2006 12:15, Geoffrey E. Quelch wrote: > Hi, > I am running a self-compiled PHP version 4.4.2 on Apache 1.3.34 on White > Box Enterprise Linux 3. > > I found a problem in my database access code (Oracle 9.2.0.4 if it matters) > and have determined that spaces in string variables are being compacted on > output in PHP. > > This PHP extract, when run, illustrates the problem: > > <?php > $name = "Space 9"; > print "<p>Length: ".strlen($name); > > printf("<p>Variable: %s",$name); > print "<p>Variable: '".$name."'"; > echo "<p>Variable: ".$name; > > for($i=0; $i< strlen($name); $i++) > print "<p>Character: ".$i."\"$name[$i]\""; > ?> > > even though the string does contain 9 consecutive spaces, only one is ever > printed to the screen with echo, print or printf. There is nothing in the > documentation for these functions that I've found that says this is the > expected behavior, or how to override if one really wants those spaces > honored. > > Why is this important? Well, the application this is in allows users to > define text strings that are inserted into the database with multiple > consecutive spaces, however, when constructing select lists in PHP using > these same entries the spaces are compacted, so the SELECT now doesn't > match what is in the database. > > Is there a way to override this behavior? > > Thanks, > Geoff Quelch > > -- > Geoff Quelch > Email: gequelch@frii.net I would suggest replacing spaces with their HTML equivalent (&nbsp;). You could either store it that way, or change it when you output. Then when you go to run the query change all &nbsp; instances back to space. HTH -- Ray Hauge Programmer/Systems Administrator American Student Loan Services www.americanstudentloan.com 1.800.575.1099

« previous php.general (#234017) next »