Re: [PHP] Problem retrieving CN with ldap_search()
Hi all, Sorry to reply to myself, but I finally solved the issue. In the end it turned out it *did* have something to do with the LDAP configuration. For some reason, retrieval of 'cn' attributes was disallowed, as can be seen in this snippet from /etc/openldap/slapd.conf: access to attrs=userPassword,userPKCS12,cn by self write by * auth Removing 'cn' from 'attrs' solved the problem. Best regards, Marcel Loose. On 2/17/10, Marcel Loose wrote: > Hi all, > > I've posted this question to comp.lang.php a couple of days ago, but up > till now didn't get a really useful answer. So, here it is: > > > I' m facing the following problem. I try to retrieve the Common Name > (cn) from an LDAP database, using the commands: > > $result = ldap_search($ldap,$basedn, 'mail='.$email, array('dn','cn')); > $entries = ldap_get_entries($ldap, $result); > > The weird thing is that $entries[0]['cn'] is empty. I know the search > command succeeded, because $entries[0]['dn'] contains the correct > information. Furthermore, if I issue the following commands: > > $result = ldap_search($ldap,$basedn, 'mail='.$email); > $entries = ldap_get_entries($ldap, $result); > var_dump($entries); > > I get: > > array(2) { ["count"]=> int(1) [0]=> array(24) { ["objectclass"]=> > array(4) { ["count"]=> int(3) [0]=> string(13) > "shadowAccount" [1]=> string(12) "posixAccount" [2]=> string(13) > "inetOrgPerson" } [0]=> string(11) "objectclass" ["gecos"]=> > array(2) { ["count"]=> int(1) [0]=> string(12) "Marcel Loose" } > [1]=> string(5) "gecos" ["uid"]=> array(2) { ["count"]=> int(1) > [0]=> string(5) "loose" } [2]=> string(3) "uid" ["sn"]=> array(2) > { ["count"]=> int(1) [0]=> string(5) "Loose" } [3]=> string(2) > "sn" ["givenname"]=> array(2) { ["count"]=> int(1) [0]=> string(6) > "Marcel" } [4]=> string(9) "givenname" ["uidnumber"]=> array(2) > { ["count"]=> int(1) [0]=> string(3) "511" } [5]=> string(9) > "uidnumber" ["mail"]=> array(2) { ["count"]=> int(1) [0]=> > string(15) "lo...@astron.nl" } [6]=> string(4) > "mail" ["gidnumber"]=> array(2) { ["count"]=> int(1) [0]=> > string(4) "1000" } [7]=> string(9) > "gidnumber" ["shadowlastchange"]=> array(2) { ["count"]=> int(1) > [0]=> string(5) "14127" } [8]=> string(16) > "shadowlastchange" ["homedirectory"]=> array(2) { ["count"]=> int(1) > [0]=> string(11) "/home/loose" } [9]=> string(13) > "homedirectory" ["loginshell"]=> array(2) { ["count"]=> int(1) > [0]=> string(9) "/bin/bash" } [10]=> string(10) > "loginshell" ["count"]=> int(11) ["dn"]=> string(35) > "uid=loose,ou=people,dc=astron,dc=nl" } } > > As can be seen, the Common Name (cn), is mysteriously missing. The > information IS present in the LDAP database, though. Here's a snippet > of the output of 'slapcat', for the given user: > > dn: uid=loose,ou=people,dc=astron,dc=nl > objectClass: shadowAccount > objectClass: posixAccount > objectClass: inetOrgPerson > gecos: Marcel Loose > uid: loose > sn: Loose > givenName: Marcel > structuralObjectClass: inetOrgPerson > entryUUID: 2375bf08-e435-102b-8b97-3952138d3cf7 > creatorsName: cn=Manager,dc=astron,dc=nl > createTimestamp: 20070821132115Z > uidNumber: 511 > mail: lo...@astron.nl > gidNumber: 1000 > shadowLastChange: 14127 > cn: Marcel Loose > userPassword:: <> > homeDirectory: /home/loose > loginShell: /bin/bash > entryCSN: 20100104140045Z#00#00#00 > modifiersName: cn=Manager,dc=astron,dc=nl > modifyTimestamp: 20100104140045Z > > Am I using ldap_search() incorrectly? Or is this a problem with the > PHP-LDAP module? Or is it a caused by a misconfiguration of LDAP? > > Best regards, > Marcel Loose. > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHPDoc (not PhD) question.
Hello. Does anyone have any other templates for PHPDoc? I've found zym's ExtJS PHPDoc template, but this doesn't seem to be maintained and there are a few bugs (source code not styled, source code rendered as external windows with broken links, ordered and unordered lists not rendered with appropriate styling, etc.). Any suggestsions, fixes, alternatives. Regards, Richard. -- - Richard Quadling "Standing on the shoulders of some very clever giants!" EE : http://www.experts-exchange.com/M_248814.html EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 ZOPA : http://uk.zopa.com/member/RQuadling -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Linux ERD software
I don't normally need an ERD, but this latest project I'm on has some pretty complex database tables, and as I'm working with someone else on it, I need to plan out exactly how all the tables relate to each other properly. Do any of you have any suggestions for ERD software that will run on Linux. It can't be web-based (unless it's something I can run easily on my own local server) as I won't have access to the Internet all the time I'm working on this. Thanks, Ash http://www.ashleysheridan.co.uk
[PHP] Re: Linux ERD software
Ashley Sheridan wrote: > I don't normally need an ERD, but this latest project I'm on has some > pretty complex database tables, and as I'm working with someone else on > it, I need to plan out exactly how all the tables relate to each other > properly. Do any of you have any suggestions for ERD software that will > run on Linux. It can't be web-based (unless it's something I can run > easily on my own local server) as I won't have access to the Internet > all the time I'm working on this. MySQL Workbench, Azzurri Clay. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Linux ERD software
On Thu, Feb 18, 2010 at 7:26 AM, Ashley Sheridan wrote: > I don't normally need an ERD, but this latest project I'm on has some > pretty complex database tables, and as I'm working with someone else on > it, I need to plan out exactly how all the tables relate to each other > properly. Do any of you have any suggestions for ERD software that will > run on Linux. It can't be web-based (unless it's something I can run > easily on my own local server) as I won't have access to the Internet > all the time I'm working on this. > > Thanks, > Ash > http://www.ashleysheridan.co.uk > > > Yep, Mysql Workbench is pretty darn good -- Bastien Cat, the other other white meat -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Dumb Question - Casting
Sorry, been doing heavy perl and haven't written any PHP in 3 years so a tad rusty. Can someone explain why the second expression in this code snippet evaluates to 7 and not 8? $a = (int) (0.1 +0.7); echo "$a\n"; $x = (int) ((0.1 + 0.7) * 10); echo "$x\n"; $y = (int) (8); echo "$y\n";
Re: [PHP] Dumb Question - Casting
On Thu, 2010-02-18 at 09:47 -0600, Chuck wrote: > Sorry, been doing heavy perl and haven't written any PHP in 3 years so a tad > rusty. > > Can someone explain why the second expression in this code snippet evaluates > to 7 and not 8? > > $a = (int) (0.1 +0.7); > > echo "$a\n"; > > $x = (int) ((0.1 + 0.7) * 10); > > echo "$x\n"; > > $y = (int) (8); > > echo "$y\n"; It works as expected if you take out the int() parts in each line. I'm not sure why, but the use of int() seems to be screwing around with the results. That's why the first line outputs a 0. Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] Dumb Question - Casting
On Thu, Feb 18, 2010 at 10:50 AM, Ashley Sheridan wrote: > On Thu, 2010-02-18 at 09:47 -0600, Chuck wrote: > >> Sorry, been doing heavy perl and haven't written any PHP in 3 years so a tad >> rusty. >> >> Can someone explain why the second expression in this code snippet evaluates >> to 7 and not 8? >> >> $a = (int) (0.1 +0.7); >> >> echo "$a\n"; >> >> $x = (int) ((0.1 + 0.7) * 10); >> >> echo "$x\n"; >> >> $y = (int) (8); >> >> echo "$y\n"; > > > It works as expected if you take out the int() parts in each line. I'm > not sure why, but the use of int() seems to be screwing around with the > results. That's why the first line outputs a 0. > > Thanks, > Ash > http://www.ashleysheridan.co.uk > Another fine example of floating point math. Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Dumb Question - Casting
On Thu, Feb 18, 2010 at 16:47, Chuck wrote: > Sorry, been doing heavy perl and haven't written any PHP in 3 years so a tad > rusty. > > Can someone explain why the second expression in this code snippet evaluates > to 7 and not 8? > > $a = (int) (0.1 +0.7); > > echo "$a\n"; > > $x = (int) ((0.1 + 0.7) * 10); > > echo "$x\n"; > > $y = (int) (8); > > echo "$y\n"; > The reason why you get 7 instead of 8 is because you are using floating point arithmetic. 0.1 (i.e. the fraction 1/10) does not have a finite representation in base 2 (like you cannot finitely represent 1/3 in base 10). So the number 0.1 is represented in the computer as a number that is strictly less than 0.1 so when you do 0.1+0.7=x then you have x<0.8 in the computer (think 7.999...). When you cast to int you just truncate the number, i.e. you chop off the fractional part leaving you with 7. -- Daniel Egeberg -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Dumb Question - Casting
According to the PHP manual using the same expression, "Never cast an unknown fraction to integer, as this can sometimes lead to unexpected results". My guess is that since it is an expression of floating points, that the result is not quite 8 (for whatever reason). Therefore, it is rounded towards 0. Of course, that is only a guess, and I have no true documentation on it. Ashley Sheridan wrote: On Thu, 2010-02-18 at 09:47 -0600, Chuck wrote: Sorry, been doing heavy perl and haven't written any PHP in 3 years so a tad rusty. Can someone explain why the second expression in this code snippet evaluates to 7 and not 8? $a = (int) (0.1 +0.7); echo "$a\n"; $x = (int) ((0.1 + 0.7) * 10); echo "$x\n"; $y = (int) (8); echo "$y\n"; It works as expected if you take out the int() parts in each line. I'm not sure why, but the use of int() seems to be screwing around with the results. That's why the first line outputs a 0. Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] Dumb Question - Casting
Daniel Egeberg wrote: > On Thu, Feb 18, 2010 at 16:47, Chuck wrote: >> Sorry, been doing heavy perl and haven't written any PHP in 3 years so a tad >> rusty. >> >> Can someone explain why the second expression in this code snippet evaluates >> to 7 and not 8? >> >> $a = (int) (0.1 +0.7); >> >> echo "$a\n"; >> >> $x = (int) ((0.1 + 0.7) * 10); >> >> echo "$x\n"; >> >> $y = (int) (8); >> >> echo "$y\n"; >> > > The reason why you get 7 instead of 8 is because you are using > floating point arithmetic. 0.1 (i.e. the fraction 1/10) does not have > a finite representation in base 2 (like you cannot finitely represent > 1/3 in base 10). So the number 0.1 is represented in the computer as a > number that is strictly less than 0.1 so when you do 0.1+0.7=x then > you have x<0.8 in the computer (think 7.999...). When you cast to > int you just truncate the number, i.e. you chop off the fractional > part leaving you with 7. > yup as Daniel pointed out; this is correct - love floats & casting! see: $y = ((0.1 + 0.7) * 10); $x = (int)$y; $z = intval($y); var_dump($y); var_dump(serialize($y)); var_dump($x); var_dump($z); outputs: float(8) string(55) "d:7.99911182158029987476766109466552734375;" int(7) int(7) lovely! - note: serializing gives us the exact value of the float regards, Nathan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: PHPDoc (not PhD) question.
Richard Quadling wrote: > Hello. > > Does anyone have any other templates for PHPDoc? > > I've found zym's ExtJS PHPDoc template, but this doesn't seem to be > maintained and there are a few bugs (source code not styled, source > code rendered as external windows with broken links, ordered and > unordered lists not rendered with appropriate styling, etc.). > > Any suggestsions, fixes, alternatives. > > Regards, > > Richard. > There's a half decent one included with phpUnderControl - never seen one I *really* like yet though, and never had the time nor inclination to go making / editing one of the templates. Regards! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] linux admin needed in israel
I know it' not the right place to post this, but this is the only mailing list i'm on, and guessed this might be interesting to one of you possibly? I've a friend looking to place a Linux administrator in Israel (I've no idea what part, she didn't say) If you want, you can replay back off-list and I can pass her work email address along or something. I'm just asking here as a favor for her really. Sorry if this message doesn't seem appropriate. I won't be making a habit of this sort of thing, honest! Like I said, just doing a friend a favor, and not getting anything out of this myself Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] Export/Write rows from DBF to CSV
I'm trying to adopt this piece of code for my use. I fixed the csv_data .= trim error. Does anyone know how I can fix empty fields? Everything is dumping to a csv file but information is not matching up. I don't know if I can insert a space or something if field is blank? Rahul S. Johari-2 wrote: > > Ave, > > I'm trying to retrieve data from a DBF database and write it to a CSV > file in a comma delimited format. I'm able to get the data and write > it to CSV, but it only writes the last row/record ... not all the > records. I know I don't have the correct code and I'm hoping someone > can help me... > > _ > #CREATE CSV > $date = date('mdy'); > $_file = 'CSV/TransferData_'.$date.'.csv'; > $_fp = @fopen( $_file, 'w' ); > > #SELECT DBF TO OPEN - READ ONLY > $db = dbase_open("mydata.dbf", 0); > #PULL UP RECORD > if ($db) { > $record_numbers = dbase_numrecords($db); > for ($i = 1; $i <= $record_numbers; $i++) { > $row = dbase_get_record_with_names($db, $i); > > #WRITE ROWS TO VARIABLE > $_csv_data = > trim($row['PHONE']).",".trim($row['DATE']).","."\n"; > <-- THIS is where my problem is! This only writes the last row!! > } > } > > #WRITE TO CSV > @fwrite( $_fp, $_csv_data ); > @fclose( $_fp ); > > -- View this message in context: http://old.nabble.com/Export-Write-rows-from-DBF-to-CSV-tp22496924p27646825.html Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Magnetic Stripe Reader or Barcode to PHP
I'll confess that I've done almost zero research on this topic as of right now aside from pricing readers and blank cards. So we're opening a new super-club here in Seattle. One of the ideas we'd like to pursue is that people are assigned a card. This can be a magstripe card or something with a barcode. Not really sure at the moment which way to go. The idea being that when they enter, we "swipe/scan" their card and we can log stats (# of visits, # guests, favorite drink so the bar has it ready, enter into contest, etc.) I was thinking we setup a simple netbook with a USB reader at the front door when they pay. Then we have another back at the bar. Connect via WiFi. Have a notebook somewhere behind the scenes that runs LAMP (or a VM thereof). No internet needed. The backend database and even web/GUI stuff is of course trivial with any LAMP stack. What I don't know is how do I interface _to_ PHP from say a magstripe reader. They're dirt cheap ($50), but I assume come with zero software. http://www.kanecal.net/mag-stripe-reader-scanner.html . And there are hundreds of these gadgets out there all the same basically. I guess what I'm hoping for is some pointers, from someone who's done this sort of thing. My gut thought is something so simple, where there is some XP software (or Linux I suppose) that reads the card (and generally they only have a number encoded on them) and this is sent via a URL we define, such as http://192.168.10.100/door.php?id=123456 or http://192.168.10.100/bar.php?id=123456 etc. (ignore the security issues and all that. It's trivial to encode the parameters, plus it's a closed system with WEP/WPA/WTF). But does anyone know of such a key piece of code? Like I said, I'm not locked into magcards. It could be a barcode reader just as easily. Or fingerprint scanner, or facial recognition. In the end it's just a unique "thing" that maps to a unique number. I just need the "FM" (F*ckin' Magic -- it's a programmer term -- look it up!) that goes in between PHP and the hardware. http://daevid.com "Some people, when confronted with a problem, think 'I know, I'll use XML.'" Now they have two problems. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Magnetic Stripe Reader or Barcode to PHP
If the scanning device hooks into the keyboard somehow it should be easy. I believe that's called a "keyboard wedge". Basically, you scan and it types. My only exposure to this is using one of the old CueCat scanners to index my personal library into a php app I cobbled together. The CueCat hooked in line with the keyboard. You'd bring up the scanning page and an onload Javascript would place the cursor into the "Scan ISBN Here" text box. Scan the book and the input went where it was needed. I believe it also sent an "enter" keystroke which submitted the form. It's been a couple years since I played with it so there might have been some additional software that kicked the "enter". Then you process the data as you would for any other text field submission. It worked well enough to catalog a couple thousand books in a single evening. Hope this helps Matt On Thu, Feb 18, 2010 at 5:42 PM, Daevid Vincent wrote: > So we're opening a new super-club here in Seattle. One of the ideas we'd > like to pursue is that people are assigned a card. This can be a magstripe > card or something with a barcode. Not really sure at the moment which way > to go. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Magnetic Stripe Reader or Barcode to PHP
The inputs are simple client side devices, lime th keyboard. I used as wasp brand barcode reader and it was configured to input the value and the tab to send it to te next field. They work well and easy to set up. Bastien Sent from my iPod On Feb 18, 2010, at 5:42 PM, "Daevid Vincent" wrote: I'll confess that I've done almost zero research on this topic as of right now aside from pricing readers and blank cards. So we're opening a new super-club here in Seattle. One of the ideas we'd like to pursue is that people are assigned a card. This can be a magstripe card or something with a barcode. Not really sure at the moment which way to go. The idea being that when they enter, we "swipe/scan" their card and we can log stats (# of visits, # guests, favorite drink so the bar has it ready, enter into contest, etc.) I was thinking we setup a simple netbook with a USB reader at the front door when they pay. Then we have another back at the bar. Connect via WiFi. Have a notebook somewhere behind the scenes that runs LAMP (or a VM thereof). No internet needed. The backend database and even web/GUI stuff is of course trivial with any LAMP stack. What I don't know is how do I interface _to_ PHP from say a magstripe reader. They're dirt cheap ($50), but I assume come with zero software. http://www.kanecal.net/mag-stripe-reader-scanner.html . And there are hundreds of these gadgets out there all the same basically. I guess what I'm hoping for is some pointers, from someone who's done this sort of thing. My gut thought is something so simple, where there is some XP software (or Linux I suppose) that reads the card (and generally they only have a number encoded on them) and this is sent via a URL we define, such as http://192.168.10.100/door.php?id=123456 or http://192.168.10.100/bar.php?id=123456 etc. (ignore the security issues and all that. It's trivial to encode the parameters, plus it's a closed system with WEP/WPA/WTF). But does anyone know of such a key piece of code? Like I said, I'm not locked into magcards. It could be a barcode reader just as easily. Or fingerprint scanner, or facial recognition. In the end it's just a unique "thing" that maps to a unique number. I just need the "FM" (F*ckin' Magic -- it's a programmer term -- look it up!) that goes in between PHP and the hardware. http://daevid.com "Some people, when confronted with a problem, think 'I know, I'll use XML.'" Now they have two problems. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Magnetic Stripe Reader or Barcode to PHP
Bar code scanners can be setup to decode the scan code on the card and output it as text. On your incoming site, place cursor in text box, scan card, code on card is entered as text, hit enter, text field sent to database where all the F* Magic takes place. You will also need a method to create the cards and get the data into the database associated with the number. You can use Word or other text program and a bar code font to print the cards with bar-code, or use pre-printed peel and stick barcode labels to place on a card. To Initialize the card, have an new member interface where the data for the member is entered, along with their bar-coded number. There are a LARGE number of bar-code codes. Pick one of the more common that uses alphanumeric and symbols. Tips: Have a backup reader or hard wire the bar-code scanner into a power outlet. The cheaper hand held ones don't have a very good battery life. Print the number on the card under the bar code. This will help when a drink smears the bar code or it becomes unreadable. The door person can enter the number by hand. Dewey Williams > -Original Message- > From: Daevid Vincent [mailto:dae...@daevid.com] > Sent: Thursday, February 18, 2010 5:43 PM > To: php-general@lists.php.net > Subject: [PHP] Magnetic Stripe Reader or Barcode to PHP > > I'll confess that I've done almost zero research on this topic as of > right > now aside from pricing readers and blank cards. > > So we're opening a new super-club here in Seattle. One of the ideas > we'd > like to pursue is that people are assigned a card. This can be a > magstripe > card or something with a barcode. Not really sure at the moment which > way > to go. > > The idea being that when they enter, we "swipe/scan" their card and we > can > log stats (# of visits, # guests, favorite drink so the bar has it > ready, > enter into contest, etc.) I was thinking we setup a simple netbook with > a > USB reader at the front door when they pay. Then we have another back > at > the bar. Connect via WiFi. Have a notebook somewhere behind the scenes > that > runs LAMP (or a VM thereof). No internet needed. The backend database > and > even web/GUI stuff is of course trivial with any LAMP stack. > > What I don't know is how do I interface _to_ PHP from say a magstripe > reader. They're dirt cheap ($50), but I assume come with zero software. > http://www.kanecal.net/mag-stripe-reader-scanner.html . And there are > hundreds of these gadgets out there all the same basically. > > I guess what I'm hoping for is some pointers, from someone who's done > this > sort of thing. > > My gut thought is something so simple, where there is some XP software > (or > Linux I suppose) that reads the card (and generally they only have a > number > encoded on them) and this is sent via a URL we define, such as > http://192.168.10.100/door.php?id=123456 or > http://192.168.10.100/bar.php?id=123456 etc. (ignore the security > issues > and all that. It's trivial to encode the parameters, plus it's a closed > system with WEP/WPA/WTF). But does anyone know of such a key piece of > code? > > Like I said, I'm not locked into magcards. It could be a barcode reader > just as easily. Or fingerprint scanner, or facial recognition. In the > end > it's just a unique "thing" that maps to a unique number. I just need > the > "FM" (F*ckin' Magic -- it's a programmer term -- look it up!) that goes > in > between PHP and the hardware. > > http://daevid.com > > "Some people, when confronted with a problem, think 'I know, I'll use > XML.'" > Now they have two problems. > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Export/Write rows from DBF to CSV
On Thu, Feb 18, 2010 at 02:31:00PM -0800, OBXer wrote: > > Rahul S. Johari-2 wrote: > > > > Ave, > > > > I'm trying to retrieve data from a DBF database and write it to a CSV > > file in a comma delimited format. I'm able to get the data and write > > it to CSV, but it only writes the last row/record ... not all the > > records. I know I don't have the correct code and I'm hoping someone > > can help me... > > > > _ > > #CREATE CSV > > $date = date('mdy'); > > $_file = 'CSV/TransferData_'.$date.'.csv'; > > $_fp = @fopen( $_file, 'w' ); > > > > #SELECT DBF TO OPEN - READ ONLY > > $db = dbase_open("mydata.dbf", 0); > > #PULL UP RECORD > > if ($db) { > > $record_numbers = dbase_numrecords($db); > > for ($i = 1; $i <= $record_numbers; $i++) { > > $row = dbase_get_record_with_names($db, $i); > > > > #WRITE ROWS TO VARIABLE > > $_csv_data = > trim($row['PHONE']).",".trim($row['DATE']).","."\n"; > > <-- THIS is where my problem is! This only writes the last row!! > > } > > } > > > > #WRITE TO CSV > > @fwrite( $_fp, $_csv_data ); > > @fclose( $_fp ); > > > > > > I'm trying to adopt this piece of code for my use. I fixed the csv_data .= > trim error. Does anyone know how I can fix empty fields? Everything is > dumping to a csv file but information is not matching up. I don't know if I > can insert a space or something if field is blank? > What do you mean "fix" empty fields? And what do you mean by "information is not matching up"? You shouldn't insert spaces where there are blank fields. Just leave them blank. The commas are supposed to delimit all the fields, including the empty ones. Like: John,Smith,,123 Main St,Tucson,AZ Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Magnetic Stripe Reader or Barcode to PHP
On Thu, Feb 18, 2010 at 3:42 PM, Daevid Vincent wrote: > I'll confess that I've done almost zero research on this topic as of right > now aside from pricing readers and blank cards. > > So we're opening a new super-club here in Seattle. One of the ideas we'd > like to pursue is that people are assigned a card. This can be a magstripe > card or something with a barcode. Not really sure at the moment which way > to go. > > The idea being that when they enter, we "swipe/scan" their card and we can > log stats (# of visits, # guests, favorite drink so the bar has it ready, > enter into contest, etc.) I was thinking we setup a simple netbook with a > USB reader at the front door when they pay. Then we have another back at > the bar. Connect via WiFi. Have a notebook somewhere behind the scenes that > runs LAMP (or a VM thereof). No internet needed. The backend database and > even web/GUI stuff is of course trivial with any LAMP stack. > > What I don't know is how do I interface _to_ PHP from say a magstripe > reader. They're dirt cheap ($50), but I assume come with zero software. > http://www.kanecal.net/mag-stripe-reader-scanner.html . And there are > hundreds of these gadgets out there all the same basically. > > I guess what I'm hoping for is some pointers, from someone who's done this > sort of thing. > > My gut thought is something so simple, where there is some XP software (or > Linux I suppose) that reads the card (and generally they only have a number > encoded on them) and this is sent via a URL we define, such as > http://192.168.10.100/door.php?id=123456 or > http://192.168.10.100/bar.php?id=123456 etc. (ignore the security issues > and all that. It's trivial to encode the parameters, plus it's a closed > system with WEP/WPA/WTF). But does anyone know of such a key piece of code? > > Like I said, I'm not locked into magcards. It could be a barcode reader > just as easily. Or fingerprint scanner, or facial recognition. In the end > it's just a unique "thing" that maps to a unique number. I just need the > "FM" (F*ckin' Magic -- it's a programmer term -- look it up!) that goes in > between PHP and the hardware. > DISCLAIMER - THOU ART ABOUT TO BEHOLD A RANT ... ok, so it all started out a few years back when i started a company set out to build a wireless capture portal. we wanted to integrate with a 2-Touch POS which had 'gift cards' which were magcards. the idea was someone buys a drink, the clerk swipes the card and the customer gets a window of time on the internet. so heres the deal (on linux [likely similar on other OS' though not sure on the implementation there]). when you attach a usb card reader, barcode scanner or similar, if you have linux USB HID (HumanInputDevice) support the kernel magically uses the module to treat input from the device as keyboard input; simple right... well this only works iff you have a terminal for the output to arrive at. if you dont it goes nowhere (likely /dev/null or similar). so if you want something quick and dirty, a laptop or any box w/ a full window manager or just a terminal will capture the output. but thats for newbs (haha)... the way we rolled w/ my product was w/ a linux server, running as the local gateway w/ a full lamp stack to provide a UI for the business owner and the customers. new problem - how to capture the output of the device w/o a terminal or UI on the server. to cut to the chase we ended up developing a *user space* driver for the card reader via libusb (which is cross-platform btw). i started out trying the java wrappers, but they all sucked ass.. so ended up going w/ C. basically, we wrote a simple single threaded daemon which sits and listens for card swipes, once the card is swiped, the daemon uses the C system() function to invoke a configurable executable program (which in our case was a php script :)) and passes the captured info from the card via the shell. the code is semi-generic but frankly we stopped off where our needs did at the time. the only real limitations are: . it only provides a fraction of the info from the card (all info could be passed ideally) . it has hardcoded values for a minimag card reader (easily changed - these are just values to identify the proper hardware in the USB tree and bind to it) . single threaded - it would be nice to have a main listener thread and fork child threads to process the swipes (thats where binary from the device is converted to ascii based on the usb2.0 spec) believe it or not you can actually send 2 swipes before the first one is processed w/ a single thread if you swipe it quickly enough! . dependent on glib for some string functionality - i think it would be nice to see it have as few dependencies beyond libusb (and pthreads if ever it was threaded), though glib is quite common afaik we originally ran the software on gentoo, but it could be packaged up for pretty much any OS afaik since libusb is cross-platform. anyways, if this is interesting at all im happy
[PHP] array conversion
Hi guys. How to convert an array like: Array ( [0] => key1 [1] => value1 [2] => key2 [3] => value2 ) to Array ( [key1] => value1 [key2] => value2 ) Is there a built-in function to do this? Please Cc me. :) Thank you in advance. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] array conversion
On Fri, Feb 19, 2010 at 01:20:12PM +0800, Dasn wrote: > Hi guys. How to convert an array like: > > Array > ( > [0] => key1 > [1] => value1 > [2] => key2 > [3] => value2 > ) > > to > > > Array > ( > [key1] => value1 > [key2] => value2 > ) > > Is there a built-in function to do this? > Please Cc me. :) > Thank you in advance. I don't believe so, but rolling your own should not be too hard: $a = array($key1, $value1, $key2, $value2); $b = array(); $numitems = count($a); for ($i = 0; $i < $numitems; $i++) { if ($i % 2 == 0) { $saved_key = $a[$i]; } elseif ($i % 2 == 1) { $b[$saved_key] = $a[$i]; } } Code is crude and untested, but you get the idea. Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] array conversion
On Thursday 18 February 2010 11:58:28 pm Paul M Foster wrote: > On Fri, Feb 19, 2010 at 01:20:12PM +0800, Dasn wrote: > > Hi guys. How to convert an array like: > > > > Array > > ( > > [0] => key1 > > [1] => value1 > > [2] => key2 > > [3] => value2 > > ) > > > > to > > > > > > Array > > ( > > [key1] => value1 > > [key2] => value2 > > ) > > > > Is there a built-in function to do this? > > Please Cc me. :) > > Thank you in advance. > > I don't believe so, but rolling your own should not be too hard: > > $a = array($key1, $value1, $key2, $value2); > $b = array(); > $numitems = count($a); > > for ($i = 0; $i < $numitems; $i++) { > if ($i % 2 == 0) { > $saved_key = $a[$i]; > } > elseif ($i % 2 == 1) { > $b[$saved_key] = $a[$i]; > } > } > > Code is crude and untested, but you get the idea. > > Paul This would be even shorter, I think: foreach ($items as $i => $value) { $temp[$i % 2][] = $value; } $done = array_combine($temp[0], $temp[1]); (Also untested, just off the cuff...) --Larry Garfield -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] array conversion
Or, function new_arr(array $arr) { $count = count($arr); if ($count % 2 != 0) throw new Exception('The new_arr() function requires an even number of elements.'); for ($i = 0; $i < $count; $i += 2) { $new_arr[$arr[$i]] = $arr[$i + 1]; } return $new_arr; } $test = new_arr(array('k1', 'v1', 'k2', 'v2', 'k3', 'v3')); exit(var_dump($test)); On Fri, Feb 19, 2010 at 1:19 AM, Larry Garfield wrote: > On Thursday 18 February 2010 11:58:28 pm Paul M Foster wrote: > > On Fri, Feb 19, 2010 at 01:20:12PM +0800, Dasn wrote: > > > Hi guys. How to convert an array like: > > > > > > Array > > > ( > > > [0] => key1 > > > [1] => value1 > > > [2] => key2 > > > [3] => value2 > > > ) > > > > > > to > > > > > > > > > Array > > > ( > > > [key1] => value1 > > > [key2] => value2 > > > ) > > > > > > Is there a built-in function to do this? > > > Please Cc me. :) > > > Thank you in advance. > > > > I don't believe so, but rolling your own should not be too hard: > > > > $a = array($key1, $value1, $key2, $value2); > > $b = array(); > > $numitems = count($a); > > > > for ($i = 0; $i < $numitems; $i++) { > > if ($i % 2 == 0) { > > $saved_key = $a[$i]; > > } > > elseif ($i % 2 == 1) { > > $b[$saved_key] = $a[$i]; > > } > > } > > > > Code is crude and untested, but you get the idea. > > > > Paul > > This would be even shorter, I think: > > foreach ($items as $i => $value) { > $temp[$i % 2][] = $value; > } > $done = array_combine($temp[0], $temp[1]); > > (Also untested, just off the cuff...) > > --Larry Garfield > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Nephtali: PHP web framework that functions beautifully http://nephtaliproject.com