Re: Tip For The Day

From: Date: Tue, 27 Jan 2004 18:40:37 +0000
Subject: Re: Tip For The Day
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-175959@lists.php.net to get a copy of this message
On Tue, 2004-01-27 at 09:19, Jay Blanchard wrote: > When constructing arrays where you are meddling with fixed width > substrings in a larger file make sure that the array item does not > contain a tab or you will certainly get unexpected results; > > $arrBadInfo ( > 'AMARILLOHOUSE ', > 'KJONES HOUSE ', <--- 16 characters wide, or is it? > 'DCOLLINSCUSTSVC ', > 'LAWTON JCOLEMAN', > }; > > Both above appear to be 16 characters wide in the editor of your choice > (I am using Zend at the moment). However, if there is a tab between > KJONES and HOUSE, the HOUSE is moved to the right the appropriate number > of characters (or inappropriate as it were) and produce undesired > results. I have been working on this issue since 5 am this morning when > I finally decided to print_r() the array (consisting of 192 elements). > Lo and behold (and slapping my forehead thusly) we saw that there were > tabs in the result. Replacing the tabs with the proper number of spaces > fixed the result. > > Actually this tip applies to all strings in which you expect there to be > a fixed width. Beware the tab, especially if you are bring in the data > from a source (cuttin' n' pastin') outside of your editor. Event better... turn your editor's tab character to 4 spaces, then your code never contains those despicable tab characters and you won't accidentally insert tabs into strings :) Cheers, Rob -- .------------------------------------------------------------. | InterJinn Application Framework - http://www.interjinn.com | :------------------------------------------------------------: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `------------------------------------------------------------'

« previous php.general (#175959) next »