This is a discussion on "How to deal with zero length strings in an array" within the PHP Forum section. This forum, and the thread "How to deal with zero length strings in an array are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
How to deal with zero length strings in an array
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
#1
|
|||
|
|||
|
How to deal with zero length strings in an array
Hope someone can help.
I need to split a sting (a description of an image) read in from MySQL into separate words and present them as a table of check boxes (they'll be used to select keywords for the image) I've got the code working as I need it but for one problem. I use
When other functions I use later on to clean up the data for what I call junk words ( of, at, the etc) and presenting the output, these functions see the zero length string, assume that's the end of the array and abort. I have tried using the index key to step through my subsequent 'for' loop to hopefully skip over the zero length string and tried testing for a zero length string but nothing I try works. This is obviously something there's a function or technique to deal with so could someone enlighten me please. Thanks. Phillip |
|
|
|
#2
|
||||
|
||||
|
Re: How to deal with zero length strings in an array
Maybe something like this?
__________________
Web Design And Development: Other Road Design | Problems with IE6?: KApp | My Blog: Only Nerds Allowed | Learning PHP? Lessons
Last Blog Entry: Hilarious Rapper (Jul 29th, 2008)
|
|
#3
|
|||
|
|||
|
Re: How to deal with zero length strings in an array
Bu**er.
I obviously got something wrong as your method certainly works. Sure beats all the complicated methods I've spent the last three days trying on and off. Anyway I'm a happy bunny now (until I hit the next problem) so thank you very much for your swift and accurate reply. Keen amateurs with no colleagues to talk to would be really up the creek without people like you helping out. Thanks and Happy Easter. Phillip |
|
#4
|
|||
|
|||
|
Re: How to deal with zero length strings in an array
Otherwise you could have use preg_replace() to replace double spaces with single space.
Last Blog Entry: Cross browser nuisance (Feb 11th, 2008)
|
|
#5
|
|||
|
|||
|
Re: How to deal with zero length strings in an array
Thanks for that. That was one of the functions I looked at when I was trying to do it the complicated way.
I didn't think it suitable for me as I couldn't be certain there's not a series of three, or four spaces lurking somewhere in the database which the pattern of the function would then miss (as it is looking for two spaces) and the code would therefore break again. I dare say there's some regular expression someone could come up with that might work but when I look at doing those my head hurts. CloudedVision's example solves the problem simply, and it will also catch any other reasons that an empty field occurs in the array for some as yet unforeseen circumstance. |
|
#6
|
||||
|
||||
|
Re: How to deal with zero length strings in an array
I'd look at str_replace() first. Isn't it faster?
|
|
#7
|
||||
|
||||
|
Re: How to deal with zero length strings in an array
my method is probably the slowest one, but it'll catch triple, quadruple, etc. spaces, unlike preg_replace and str_replace. (actually, you might be able to catch triple spaces with preg_replace, but i know nothing about regular expressions)
__________________
Web Design And Development: Other Road Design | Problems with IE6?: KApp | My Blog: Only Nerds Allowed | Learning PHP? Lessons
Last Blog Entry: Hilarious Rapper (Jul 29th, 2008)
Last edited by CloudedVision; Mar 12th, 2008 at 19:51. |
![]() |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Length problem solved, now width. | Manic056 | Starting Out | 5 | Jan 31st, 2008 02:33 |
| 3 column div layout, not same length | tox0tes | Web Page Design | 8 | Jun 28th, 2007 15:08 |
| setting page length | wmw | Web Page Design | 6 | May 22nd, 2006 16:17 |
| Sorting a new array from an existing array | Ozeona | Flash & Multimedia Forum | 2 | Sep 20th, 2005 08:43 |
| array unable to check another array so as to be displayed | Ozeona | Flash & Multimedia Forum | 1 | Aug 5th, 2005 10:26 |