Be Excellent To Each Other

And, you know, party on. Dude.

All times are UTC [ DST ]




Reply to topic  [ 29 posts ] 
Author Message
 Post subject: Nerds! Assist me!
PostPosted: Fri Nov 23, 2012 11:38 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69712
Location: Your Mum
Someone explain why I keep getting the result:

Code:
Don't recognise column 1: 'Panel id'
Don't recognise column 2: 'Member id'
Don't recognise column 3: 'Project id'
Don't recognise column 4: 'Estimated LOI'


For this bit of code?!

Code:
foreach ($data[0] as $k=>$d) {
    switch (trim($d)) {
        case 'Member id' :
            $memid = $k;       
        break;
        case 'Project id' :
            $projid = $k;       
        break;
        case 'Estimated LOI' :
            $loi = $k;     
        break;
        default :
            print "Don't recognise column ".($k + 1).": '".trim($d)."'<br />";
        break;
    }
}


I have no idea.

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Nerds! Assist me!
PostPosted: Fri Nov 23, 2012 11:42 
User avatar

Joined: 30th Mar, 2008
Posts: 14366
Location: Shropshire, UK
What's your array look like? I just replicated that with this code:
Code:
<?php

$data[0][0] = "Panel id";
$data[0][1] = "Member id";
$data[0][2] = "Project id";
$data[0][3] = "Estimated LOI";

foreach ($data[0] as $k=>$d) {
    switch (trim($d)) {
        case 'Member id' :
            $memid = $k;
        break;
        case 'Project id' :
            $projid = $k;
        break;
        case 'Estimated LOI' :
            $loi = $k;
        break;
        default :
            print "Don't recognise column ".($k + 1).": '".trim($d)."'<br />";
        break;
    }
}

?>

And it complained about not recognising the panel ID (as I expected) but everything else was fine.


Top
 Profile  
 
 Post subject: Re: Nerds! Assist me!
PostPosted: Fri Nov 23, 2012 11:45 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69712
Location: Your Mum
Right? My array looks like what you'd expect (it's being output in the default switch, after all):
Code:
Array
(
    [0] => Array
        (
            [0] => Panel id
            [1] => Member id
            [2] => Project id
            [3] => Estimated LOI
        )
)

It can't be encoding, can it?

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Nerds! Assist me!
PostPosted: Fri Nov 23, 2012 11:48 
User avatar
ugvm'er at heart...

Joined: 4th Mar, 2010
Posts: 22391
Grim... wrote:
Right? My array looks like what you'd expect (it's being output in the default switch, after all):
Code:
Array
(
    [0] => Array
        (
            [0] => Panel id
            [1] => Member id
            [2] => Project id
            [3] => Estimated LOI
        )
)

It can't be encoding, can it?


Don't your array elements need to be strings?

Code:
Array
(
    [0] => Array
        (
            [0] => "Panel id"
            [1] => "Member id"
            [2] => "Project id"
            [3] => "Estimated LOI"
        )
)


Top
 Profile  
 
 Post subject: Re: Nerds! Assist me!
PostPosted: Fri Nov 23, 2012 11:50 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69712
Location: Your Mum
They are, it's just the way they're output.

Anyway, this is php, where
Code:
0 == "" == null == false
:)

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Nerds! Assist me!
PostPosted: Fri Nov 23, 2012 11:52 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69712
Location: Your Mum
Re-writing them just before the switch (ie:
Code:
$data[0][0] = "Panel id";
$data[0][1] = "Member id";
$data[0][2] = "Project id";
$data[0][3] = "Estimated LOI";

Makes it work.

They're actually coming from a CSV, so it has to be encoding, somehow. I'll force them all to UTF8.

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Nerds! Assist me!
PostPosted: Fri Nov 23, 2012 11:58 
User avatar
ugvm'er at heart...

Joined: 4th Mar, 2010
Posts: 22391
Grim... wrote:
They are, it's just the way they're output.

Anyway, this is php, where
Code:
0 == "" == null == false
:)


Everyday is a school day. I know fuck all about php :D


Top
 Profile  
 
 Post subject: Re: Nerds! Assist me!
PostPosted: Fri Nov 23, 2012 12:09 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69712
Location: Your Mum
But it certainly should still work.

Re-encoding everything doesn't help. I'm proper confused.

I'm going to try re-encoding the original file.

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Nerds! Assist me!
PostPosted: Fri Nov 23, 2012 12:11 
SupaMod
User avatar
Commander-in-Cheese

Joined: 30th Mar, 2008
Posts: 49244
Let me know if you need me to sort this shit out bud. I'll be right there.

_________________
GoddessJasmine wrote:
Drunk, pulled Craster's pork, waiting for brdyime story,reading nuts. Xz


Top
 Profile  
 
 Post subject: Re: Nerds! Assist me!
PostPosted: Fri Nov 23, 2012 12:11 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69712
Location: Your Mum
The csv file is currently encoded with UTF-16. That's got to be the issue.

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Nerds! Assist me!
PostPosted: Fri Nov 23, 2012 12:12 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69712
Location: Your Mum
Yup, that was it.

I hate encoding. Why can't we all just agree to get along?

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Nerds! Assist me!
PostPosted: Fri Nov 23, 2012 12:19 
User avatar
Hibernating Druid

Joined: 27th Mar, 2008
Posts: 49352
Location: Standing on your mother's Porsche
Grim... wrote:
Yup, that was it.

I hate encoding. Why can't we all just agree to get along?

Cunt

_________________
SD&DG Illustrated! Behance Bleep Bloop

'Not without talent but dragged down by bass turgidity'


Top
 Profile  
 
 Post subject: Re: Nerds! Assist me!
PostPosted: Fri Nov 23, 2012 13:09 
User avatar

Joined: 30th Mar, 2008
Posts: 14366
Location: Shropshire, UK
Who the hell uses UTF-16 in this day and age?


Top
 Profile  
 
 Post subject: Re: Nerds! Assist me!
PostPosted: Fri Nov 23, 2012 13:21 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69712
Location: Your Mum
GazChap wrote:
Who the hell uses UTF-16 in this day and age?

Right? Right?

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Nerds! Assist me!
PostPosted: Fri Nov 23, 2012 13:43 
User avatar

Joined: 30th Mar, 2008
Posts: 14366
Location: Shropshire, UK
Grim... wrote:
GazChap wrote:
Who the hell uses UTF-16 in this day and age?

Right? Right?

Huh, well blow me - apparently Windows uses it for all of it's OS text encoding. I don't think I've ever come across UTF-16 "in the wild."


Top
 Profile  
 
 Post subject: Re: Nerds! Assist me!
PostPosted: Fri Nov 23, 2012 17:13 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69712
Location: Your Mum
Excellently, I just found this in a page I wrote a couple of months ago (during my "insane busy" phase):
Code:
            if ($type == 2 || $type == 5 || $type == 8 || $type == 24 || $type == 25) {
                // [] we have to switch the option ID for the option key
                // [] this is, to put it lightly, a pain in the arse
                if ($type == 2) {
                    // [] Multi-choice singles can contain   
                }
            }


I added
Code:
                    // [] can contain what? Why have I just left this here?
                    // [] ruh-roh

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Nerds! Assist me!
PostPosted: Fri Nov 23, 2012 20:32 
User avatar
Sitting balls-back folder

Joined: 30th Mar, 2008
Posts: 10172
PHP really is shit isn't it?


Top
 Profile  
 
 Post subject: Re: Nerds! Assist me!
PostPosted: Sat Nov 24, 2012 0:07 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69712
Location: Your Mum
BikNorton wrote:
PHP really is shit isn't it?

No, it's pretty much as good as any other language (although the naming conventions bother me).

Unfortunately, the majority of PHP programmers are shit.

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Nerds! Assist me!
PostPosted: Sat Nov 24, 2012 0:11 
User avatar
Comfortably Dumb

Joined: 30th Mar, 2008
Posts: 12034
Location: Sunny Stoke
Grim... wrote:
Unfortunately, the majority of PHP programmers are shit.


Hello!

Actually, I think I've come to realise that I don't want to get heavily into any kind of programming - this year it's been a case of Frameworks, SVNs and database diagrams. I just want to arse about with a bit of code that somehow works. :)

_________________
Consolemad | Under Logic
Curse, the day is long
Realise you don't belong


Top
 Profile  
 
 Post subject: Re: Nerds! Assist me!
PostPosted: Sat Nov 24, 2012 0:23 
User avatar
Sitting balls-back folder

Joined: 30th Mar, 2008
Posts: 10172
Grim... wrote:
BikNorton wrote:
PHP really is shit isn't it?

No, it's pretty much as good as any other language (although the naming conventions bother me).

Unfortunately, the majority of PHP programmers are shit.
the ridiculous type conversions and operators are shocking, and then it can't even convert one string to another for comparison. It's shit compared to c, c++, java, perl, JavaScript and c# in those regards, to name the ones I know. Christ, even BASIC. I'm a bit shocked your blaming the workman when it's very clearly the tool, from this example that's affected you.

I hate the random sprawl of inconsistent functions/naming, too.

But I can happily ignore it, so it's fine really. Carry on.

Edit: actually, scratch c(++), because the traditional c runtime is easy to confuse, even if the more recent object and typed stuff isn't.


Top
 Profile  
 
 Post subject: Re: Nerds! Assist me!
PostPosted: Sat Nov 24, 2012 0:29 
User avatar

Joined: 30th Mar, 2008
Posts: 14366
Location: Shropshire, UK
Grim... wrote:
Unfortunately, the majority of PHP programmers are shit.

:this:, although I'm probably one of them.


Top
 Profile  
 
 Post subject: Re: Nerds! Assist me!
PostPosted: Sat Nov 24, 2012 2:08 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69712
Location: Your Mum
BikNorton wrote:
from this example that's affected you.

I know the encoding would have affected Java and Javascript in the same way, and I can't see the others managing too well. Simply, the strings were different - but the browser rendered them "correctly", so it was hard to tell.

If any language nobbed about converting strings without me wanting it to I think I'd be a bit upset - you'd end up with all different types of encoding stored, and when you tried to display them all at the same time you'd end up with a big old page of junk.

BikNorton wrote:
I hate the random sprawl of inconsistent functions/naming, too.

Right? >:(

I actually asked Rasmus Lerdorf why the Hell that had happened once, and the answer was basically "If I changed it all now, millions of people would cry." Which is probably true, but - you know - fuck'em.

Also, array sorting all happens in place, which is inconsistent with every other function PHP has. And it has a function called `mysql_escape_string()` which is no good, and has been superseded by the excellently-named `mysql_real_escape_string()`. Oh yes.

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Nerds! Assist me!
PostPosted: Sat Nov 24, 2012 10:37 
User avatar

Joined: 30th Mar, 2008
Posts: 14366
Location: Shropshire, UK
The things that wind me up the most about it are the inconsistent order for parameters - like, for example, in array_search, it's needle then haystack, but in strstr/stristr, it's haystack then needle. Pain in the ass to remember.

That and the functions that operate on the original, like the array sorting functions and shuffle. And why ksort() instead of array_keysort() or something?


Top
 Profile  
 
 Post subject: Re: Nerds! Assist me!
PostPosted: Sat Nov 24, 2012 11:20 
User avatar
Sitting balls-back folder

Joined: 30th Mar, 2008
Posts: 10172
Java would complain at compile time, like the other compiled.languages (expect the ols-fangled pointer arithmetic ops in c) id expect Perl not to fuck it up silently. JavaScript interpreters tend to error at the drop of a hat!


Top
 Profile  
 
 Post subject: Re: Nerds! Assist me!
PostPosted: Sat Nov 24, 2012 20:34 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69712
Location: Your Mum
But there was no error, remember. I was asking it to compare two different strings, which it did. They were different, but they looked the same as the ones in my code when output by the browser.

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Nerds! Assist me!
PostPosted: Sat Nov 24, 2012 21:21 
User avatar
Paws for thought

Joined: 27th Mar, 2008
Posts: 17161
Location: Just Outside That London, England, Europe
I've spent much of the last few weeks of work having to find various encoding issues - and that's where all strings are internally UTF16 and only converted on boundarys. Not having an enforced encoding throughout the code makes my head hurt with the potential for issues.


Top
 Profile  
 
 Post subject: Re: Nerds! Assist me!
PostPosted: Sun Nov 25, 2012 3:02 
User avatar
Sitting balls-back folder

Joined: 30th Mar, 2008
Posts: 10172
Yes, there was no error. But there should have been. Or it should have done a thread-locale conversion then compare.

Instead it did something insane, which appears to be the PHP modus operandi.


Top
 Profile  
 
 Post subject: Re: Nerds! Assist me!
PostPosted: Sun Nov 25, 2012 4:56 
SupaMod
User avatar
Commander-in-Cheese

Joined: 30th Mar, 2008
Posts: 49244
Eh? He compared a UTF-8 string to a UTF-16 string and PHP told him they were different. How is that not correct behaviour? It's not up to the language to sanitise your inputs.

_________________
GoddessJasmine wrote:
Drunk, pulled Craster's pork, waiting for brdyime story,reading nuts. Xz


Top
 Profile  
 
 Post subject: Nerds! Assist me!
PostPosted: Sun Nov 25, 2012 11:49 
User avatar

Joined: 30th Mar, 2008
Posts: 14366
Location: Shropshire, UK
:this:

Thank God they eventually turned off magic quotes by default.


Top
 Profile  
 
Display posts from previous:  Sort by  
Reply to topic  [ 29 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Columbo, KNIGHTS TEMPLAR and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search within this thread:
You are using the 'Ted' forum. Bill doesn't really exist any more. Bogus!
Want to help out with the hosting / advertising costs? That's very nice of you.
Are you on a mobile phone? Try http://beex.co.uk/m/
RIP, Owen. RIP, MrC. RIP, Dimmers.

Powered by a very Grim... version of phpBB © 2000, 2002, 2005, 2007 phpBB Group.