php-general Digest 7 Apr 2010 14:49:50 -0000 Issue 6680
php-general Digest 7 Apr 2010 14:49:50 - Issue 6680 Topics (messages 303864 through 303874): Re: SimpleXMLElement occasionally fails to parse gb2312 or big5 feeds 303864 by: Dan Joseph Re: Logical reason for strtotime('east') and strtotime('west') returning valid results? 303865 by: Kevin Kinsey 303869 by: Peter Lind Re: no-cache control 303866 by: kranthi 303867 by: Karl DeSaulniers Re: $_SERVER['PHP_AUTH_USER'] has gone 303868 by: Satz Klauer Re: image question again 303870 by: Ashley Sheridan Who uses Mantis, please help! 303871 by: Andre Polykanine 303872 by: Paul M Foster stat(), NFS shares and local files timeout 303873 by: Igor Feghali 303874 by: Dan Joseph Administrivia: To subscribe to the digest, e-mail: php-general-digest-subscr...@lists.php.net To unsubscribe from the digest, e-mail: php-general-digest-unsubscr...@lists.php.net To post to the list, e-mail: php-gene...@lists.php.net -- ---BeginMessage--- On Fri, Apr 2, 2010 at 10:28 AM, Peter Pei peterpei...@hotmail.com wrote: I use the following code to get rss and parse it, but the code occasionally have issues with gb2312 or big-5 encoded feeds, and fails to parse them. However other times may appear just okay. Any thoughts? Maybe SimpleXMLElement is simply not meant for other language encodings... $page = file_get_contents($rss); try { $feed = new SimpleXMLElement($page); I've been learning a bit about SimpleXML today myself. It seems that it misses a lot of things when it comes to complex, or abnormal XML. Abnormal being what you're describing and whatnot. I don't really have a solid answer for you (Just noticed no one responded), but I think you're running into what I was... Its just built to be Simple, not expand its mind. Hope that helps! -- -Dan Joseph www.canishosting.com - Unlimited Hosting Plans start @ $3.95/month. Promo Code NEWTHINGS for 10% off initial order http://www.facebook.com/canishosting http://www.facebook.com/originalpoetry ---End Message--- ---BeginMessage--- Colin Guthrie wrote: 'Twas brillig, and Kevin Kinsey at 05/04/10 19:15 did gyre and gimble: Nonetheless, I'm suspecting the programmers had something like this in mind. Yeah I guess that's why it interprets these terms. Good thinking :) Isn't strtotime() based on some GNU utility? Yeah, that's why I said the relevant authorities. I couldn't remember off-hand where it came from so figured I'd not blame PHP just yet :p Apparently these strings are being recognized as TZ stamps, but the underlying logic is not fully implemented: see http://www.gnu.org/s/libc/manual/html_node/Low_002dLevel-Time-String-Parsing.html Try it with some TZ stamps ... I'm pretty sure that in the previous example it was taking East to be EST, as I observed (rather by accident) earlier. Kevin Kinsey ---End Message--- ---BeginMessage--- On a related note: does anyone know why php -r echo date('Y-m-d H:i:s', strtotime('a')); happily outputs a valid timestamp? And why all other letters work as well (but only one character)? I'm sure there's a good reason for it, it just completely escapes me right now :) Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype ---End Message--- ---BeginMessage--- you can do that by using .htacess in the required directory http://www.askapache.com/htaccess/apache-speed-cache-control.html ---End Message--- ---BeginMessage--- Thanks kranthi. I thought there was a way. I was thinking you could, say, set your header content in the php.ini file?, but a .htaccess would work too. Thanks, Best, Karl On Apr 6, 2010, at 11:44 PM, kranthi wrote: you can do that by using .htacess in the required directory http://www.askapache.com/htaccess/apache-speed-cache-control.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Karl DeSaulniers Design Drumm http://designdrumm.com ---End Message--- ---BeginMessage--- Yes, the authantication-box is there. And I'm definitely using Basic auth, the same script has worked for a long time without problems. On 4/7/10, Nilesh Govindarajan li...@itech7.com wrote: On 04/06/10 21:27, Satz Klauer wrote: var_dump($_SERVER) gives me several data, the following arrayindices contain data: HTTPS, SSL_TLS_SNI, HTTP_USER_AGENT, HTTP_HOST, HTTP_ACCEPT, HTTP_ACCEPT_LANGUAGE, HTTP_ACCEPT_CHARSET, HTTP_ACCEPT_ENCODING, HTTP_REFERER, HTTP_COOKIE, HTTP_COOKIE2, HTTP_CONNECTION, HTTP_TE, PATH, SERVER_SIGNATURE, SERVER_SOFTWARE, SERVER_NAME, SERVER_ADDR, SERVER_PORT, REMOTE_HOST, REMOTE_ADDR, DOCUMENT_ROOT, SERVER_ADMIN, SCRIPT_FILENAME, REMOTE_PORT,
Re: [PHP] no-cache control
Thanks kranthi. I thought there was a way. I was thinking you could, say, set your header content in the php.ini file?, but a .htaccess would work too. Thanks, Best, Karl On Apr 6, 2010, at 11:44 PM, kranthi wrote: you can do that by using .htacess in the required directory http://www.askapache.com/htaccess/apache-speed-cache-control.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Karl DeSaulniers Design Drumm http://designdrumm.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: $_SERVER['PHP_AUTH_USER'] has gone
Yes, the authantication-box is there. And I'm definitely using Basic auth, the same script has worked for a long time without problems. On 4/7/10, Nilesh Govindarajan li...@itech7.com wrote: On 04/06/10 21:27, Satz Klauer wrote: var_dump($_SERVER) gives me several data, the following arrayindices contain data: HTTPS, SSL_TLS_SNI, HTTP_USER_AGENT, HTTP_HOST, HTTP_ACCEPT, HTTP_ACCEPT_LANGUAGE, HTTP_ACCEPT_CHARSET, HTTP_ACCEPT_ENCODING, HTTP_REFERER, HTTP_COOKIE, HTTP_COOKIE2, HTTP_CONNECTION, HTTP_TE, PATH, SERVER_SIGNATURE, SERVER_SOFTWARE, SERVER_NAME, SERVER_ADDR, SERVER_PORT, REMOTE_HOST, REMOTE_ADDR, DOCUMENT_ROOT, SERVER_ADMIN, SCRIPT_FILENAME, REMOTE_PORT, GATEWAY_INTERFACE = string(7) CGI/1.1 (??? it is running as apache-module ???, SERVER_PROTOCOL, REQUEST_METHOD, QUERY_STRING, REQUEST_URI, SCRIPT_NAME, PHP_SELF, REQUEST_TIME Unfortunately not Auth-data. var_dump($_ENV) tells me (partially anonymised): [HOSTNAME]= string(24) xxx.yyy.de [TERM]= string(5) xterm [SHELL]= string(9) /bin/bash [HISTSIZE]= string(4) 1000 [QTDIR]= string(15) /usr/lib/qt-3.3 [QTINC]= string(23) /usr/lib/qt-3.3/include [USER]= string(4) root [LS_COLORS]= string(1268) rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=01;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.tbz=01;31:*.tbz2=01;31:*.bz=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01 ;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=01;36:*.au=01;36:*.flac=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.ogg=01;36:*.ra=01;36:*.wav=01;36:*.axa=01;36:*.oga=01;36:*.spx=01;36:*.xspf=01;36: [MC_TMPDIR]= string(12) /tmp/mc-root [PATH]= string(29) /sbin:/usr/sbin:/bin:/usr/bin [MAIL]= string(20) /var/spool/mail/root [PWD]= string(17) /etc/xxx/yyy [LANG]= string(1) C [HISTCONTROL]= string(11) ignorespace [HOME]= string(5) /root [SHLVL]= string(1) 4 [MC_SID]= string(5) 25229 [LOGNAME]= string(4) root [CVS_RSH]= string(3) ssh [QTLIB]= string(19) /usr/lib/qt-3.3/lib [LESSOPEN]= string(24) |/usr/bin/lesspipe.sh %s [G_BROKEN_FILENAMES]= string(1) 1 [_]= string(15) /usr/sbin/httpd On Sun, Apr 4, 2010 at 10:54 PM, Daniel P. Brown daniel.br...@parasane.netwrote: Sorry for the top-post. Easter has me on the DROID instead of my PC. I second Rixham's thought. Is it a DSO, CGI, FCGI? What pops out in var_dump($_SERVER) and var_dump($_ENV)? On Apr 4, 2010 3:49 PM, Nathan Rixhamnrix...@gmail.com wrote: Satz Klauer wrote: Hi, I'm running a system with Fedora 12 and Apache/PHP default installatio... just a quick sanity check; you do have the specific site/directory set up to send and receive basic auth yeah? sounds very much to me like this is an apache config issue and not php :) regards! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub This means that something is wrong with your script or server which is not sending the Auth headers properly. Do you get the auth box in the latest browser, and are you sure that you're using basic and not digest auth ? -- Nilesh Govindarajan Site Server Administrator www.itech7.com मेरा भारत महान ! मम भारत: महत्तम भवतु ! -- 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] Re: Logical reason for strtotime('east') and strtotime('west') returning valid results?
On a related note: does anyone know why php -r echo date('Y-m-d H:i:s', strtotime('a')); happily outputs a valid timestamp? And why all other letters work as well (but only one character)? I'm sure there's a good reason for it, it just completely escapes me right now :) Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind Flickr: http://www.flickr.com/photos/fake51 BeWelcome: Fake51 Couchsurfing: Fake51 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] image question again
On Tue, 2010-04-06 at 21:44 -0500, Karl DeSaulniers wrote: When I have an imagecreatetruecolor and I create another one and use imagecopymerge, how do I keep the backgrounds transparent even if say the width of the top image is smaller than the back image? I keep getting a black background where the top image does not cover the back. It sets the transparency to the rest of the top image as long as it is covering the bottom one. I think it has to do with the imagealphablending. Any ideas? TIA Karl DeSaulniers Design Drumm http://designdrumm.com If it's just that the images are different sizes, then imagecopyresample might be the better option. Thanks, Ash http://www.ashleysheridan.co.uk
[PHP] Who uses Mantis, please help!
Hello everyone, I decided to use Mantis before I'll be able to use something like Trac :-). The problem is: I'm not getting mail about issues reported by my testers, only by myself. The preferences are set correctly (all the checkboxes are checked). Could you help me please? Thanks! -- With best regards from Ukraine, Andre Http://oire.org/ - The Fantasy blogs of Oire Skype: Francophile; WlmMSN: arthaelon @ yandex.ru; Jabber: arthaelon @ jabber.org Yahoo! messenger: andre.polykanine; ICQ: 191749952 Twitter: http://twitter.com/m_elensule -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Who uses Mantis, please help!
On Wed, Apr 07, 2010 at 03:37:07PM +0300, Andre Polykanine wrote: Hello everyone, I decided to use Mantis before I'll be able to use something like Trac :-). The problem is: I'm not getting mail about issues reported by my testers, only by myself. The preferences are set correctly (all the checkboxes are checked). Could you help me please? Thanks! Isn't there a Mantis list or forum? Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] stat(), NFS shares and local files timeout
I am running with an issue with remote filesystems (mounted via NFS) and PHP's stat() / filemtime(). Sometimes when the remote filesystem (NFS share) is busy, my PHP daemon just hangs forever on a filemtime() call to a file inside this FS. I failed to find a proper way of setting a timeout for that kind of operation. Everything I can think of is related to remote files (URLs) and/or content operations (read/write). Streams for example, don't even have any options for local files and default_socket_timeout directive is applicable only for sockets. I could fork my daemon just to do a stat() call and control the running time (timeout) inside the parent process, but I usually stat 60 files / second, so that would be a lot of forking. I prefer to go another way. anyone has a clue ? PS: I appreciate if replies go CC'ed to me Best, ~IF. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stat(), NFS shares and local files timeout
On Wed, Apr 7, 2010 at 10:27 AM, Igor Feghali igor.fegh...@gmail.comwrote: I am running with an issue with remote filesystems (mounted via NFS) and PHP's stat() / filemtime(). Sometimes when the remote filesystem (NFS share) is busy, my PHP daemon just hangs forever on a filemtime() call to a file inside this FS. I failed to find a proper way of setting a timeout for that kind of operation. Everything I can think of is related to remote files (URLs) and/or content operations (read/write). Streams for example, don't even have any options for local files and default_socket_timeout directive is applicable only for sockets. I could fork my daemon just to do a stat() call and control the running time (timeout) inside the parent process, but I usually stat 60 files / second, so that would be a lot of forking. I prefer to go another way. anyone has a clue ? What if you simply set the script to time out? Is it ignoring that too? set_time_limit( seconds ) -- -Dan Joseph www.canishosting.com - Unlimited Hosting Plans start @ $3.95/month. Promo Code NEWTHINGS for 10% off initial order http://www.facebook.com/canishosting http://www.facebook.com/originalpoetry
[PHP] RE: mysql query returning slowly
Nathan, The profiling I included proved that was not the case. Mysql run the query and return the single column single row result in under 1 second but PHP's mysql-query waited much longer than that to return. If it was a big result set I could see some slow down in parsing the results into memory but this wasn't the case. Updates/Deletes have similar random timing issues , and using mysql profiling, I can see its not transit or lock or clean up time from mysql - php , it is purely inside the php mysql functions the slow down seems to be occurs , but I can dive into those as they are compiled modules not userland functions. -Original Message- -Original Message- From: Nathan Rixham [mailto:nrix...@gmail.com] Sent: Tuesday, April 06, 2010 6:35 PM To: David Murphy Cc: php-general@lists.php.net Subject: Re: mysql query returning slowly David Murphy wrote: This is from our application I enabled profile in mysql to determine why an update took 20seconds. As you can see MySQL reported no where near that amount of duration took place. Is there any way I can dig into php and determine why mysql client libs are so slow (this is not using mysqlnd but mysql-client-libs on CentOS using 5.3.2) 04/06/2010 14:54:54 20.6899s maybe it was waiting to acquire a lock -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Howto send command over ssh using sockets
phpseclib does SSH without PECL extension and only with fsockopen: http://phpseclib.sourceforge.net/ On Sun Apr 4 21:09:54 2010, Hans_Åhlin wrote: Instead of ssh, you could use telnet to connect to the Cisco router (which incidentally runs on port 23, but is likely to be disabled on the cisco router, unless you have a pre-SSH capable IOS running on it (like my old cisco crap :( ) ), because i strongly doubt you have written or are willing to write your own encryption libraries for this project, you might also want to read IETF RFC 854 [http://tools.ietf.org/html/rfc854] about the telnet protocol, as you are writing your own client, and not using a pre-made one, judging from your script. Or if you do not like the idea of sending clear-text passwords to the router, you might want to learn about proc_open() (or popen()) and use the native ssh utility that most likely is present on the server, taking great care to READ THE MANUAL for the ssh command, because you most likely do _not_ want it to spit out ANSI-escapes to you script. Kind regards from Johan Lidström Örnsköldsvik, Sweden irc://irc.freenode.net/Dr_Kao frozendude+php...@gmail.com P.S. currently borrowing a friends account. 2010/4/5 Radek Krejča radek.kre...@starnet.cz: Hello, I am trying send command to remote host over ssh with sockets. But I need to set up username/password. I am trying to modify this script (from www.php.net - function fsockopen), but I dont know, where set username/password because I got this message: Bad protocol version identification 'password' from ip Library ssh2 is not currentu userfull for me, because I am not admin of server. Thank you Radek ?php / * Author: Richard Lajaunie * Mail : richard.lajau...@cote-azur.cci.fr * * subject : this script retreive all mac-addresses on all ports * of a Cisco 3548 Switch by a telnet connection * * base on the script by: xbensemhoun at t-systems dot fr on the same page **/ if ( array_key_exists(1, $argv) ){ $cfgServer = $argv[1]; }else{ echo ex: 'php test.php 10.0.0.0' \n; exit; } $cfgPort = 23; //port, 22 if SSH $cfgTimeOut = 10; $usenet = fsockopen($cfgServer, $cfgPort, $errno, $errstr), $cfgTimeOut); if(!$usenet){ echo Connexion failed\n; exit(); }else{ echo Connected\n; fputs ($usenet, password\r\n); fputs ($usenet, en\r\n); fputs ($usenet, password\r\n); fputs ($usenet, sh mac-address-table\r\n); fputs ($usenet, ); // this space bar is this for long output // this skip non essential text $j = 0; while ($j16){ fgets($usenet, 128); $j++; } stream_set_timeout($usenet, 2); // set the timeout for the fgets $j = 0; while (!feof($usenet)){ $ret = fgets($usenet, 128); $ret = str_replace(\r, '', $ret); $ret = str_replace(\n, , $ret); if (ereg(FastEthernet, $ret)){ echo $ret \n; } if (ereg('--More--', $ret) ){ fputs ($usenet, ); // for following page } $info = stream_get_meta_data($usenet); if ($info['timed_out']) { $j++; } if ($j 2){ fputs ($usenet, lo); break; } } } echo End.\r\n; ? -- 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] Greate day for you,
http://sites.google.com/site/vfgbyuhoi6/kewe2w -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Greate day for you,
On Wed, Apr 7, 2010 at 12:11, Chris G thunder...@gmail.com wrote: http://sites.google.com/site/vfgbyuhoi6/kewe2w Heads-up: It's a SPAM link. You probably already knew that. (Funny that Jochem was targeted directly for this particular one. ;-P) -- /Daniel P. Brown daniel.br...@parasane.net || danbr...@php.net http://www.parasane.net/ || http://www.pilotpig.net/ Looking for hosting or dedicated servers? Ask me how we can fit your budget! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Greate day for you,
On 04/07/10 21:41, Chris G wrote: http://sites.google.com/site/vfgbyuhoi6/kewe2w Bloody asshole spammer. Is there no spam filter at lists.php.net ? -- Nilesh Govindarajan Site Server Administrator www.itech7.com मेरा भारत महान ! मम भारत: महत्तम भवतु ! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Greate day for you,
2010/4/7 Nilesh Govindarajan li...@itech7.com: On 04/07/10 21:41, Chris G wrote: http://sites.google.com/site/vfgbyuhoi6/kewe2w Bloody asshole spammer. Is there no spam filter at lists.php.net ? It was probably a virus or a trojahn, not intentionally sent to the list by the OP... -- Nilesh Govindarajan Site Server Administrator www.itech7.com मेरा भारत महान ! मम भारत: महत्तम भवतु ! -- 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] Greate day for you,
Nilesh Govindarajan wrote: On 04/07/10 21:41, Chris G wrote: http://sites.google.com/site/vfgbyuhoi6/kewe2w snip Is there no spam filter at lists.php.net ? Does your filter catch 101% of all of it? That's the only one I've seen in a Long Time(tm). Just asking :-) Kevin Kinsey -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Greate day for you,
-Original Message- From: Chris G [mailto:thunder...@gmail.com] Sent: Wednesday, April 07, 2010 12:11 PM To: denisema...@googlemail.com; derrick.h...@za.delarue.com; gc...@aceonline.com.au; ja...@shongololocomm.co.za; joc...@iamjochem.com; bonge...@mweb.co.za; johan.bong...@za.delarue.com; jonathanbus-...@telkomsa.net; kmfisc...@gmail.com; kell...@trtretail.co.za; kerry.gri...@gmail.com; kirst...@switchdesign.com; s.ku...@huxley.co.uk; lee.mais...@7layer.net; mik.gri...@za.delarue.com; paintball...@hotmail.com; paintball...@yahoo.com; php-general@lists.php.net; php-general-unsubscr...@lists.php.net; scot...@mkbgroup.co.za Subject: [PHP] Greate day for you, http://sites.google.com/site/vfgbyuhoi6/kewe2w -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php It looks like the mighty Gmail has been cracked. This is the second time today I have seen something like this and both have originated through actual gmail accounts and CC to people on their mailing lists. __ Information from ESET Smart Security, version of virus signature database 5007 (20100407) __ The message was checked by ESET Smart Security. http://www.eset.com __ Information from ESET Smart Security, version of virus signature database 5008 (20100407) __ The message was checked by ESET Smart Security. http://www.eset.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Sort two coupled arrays
Hi gang: Here's the problem -- I want to sort and combine two arrays into one sorted array. Here's a real-world example: Array 1 ( [1] = 75 [2] = 31 [3] = 31 [4] = 31 [5] = 40 ) Array 2 ( [1] = Personal Email [2] = Personal Phone [3] = Web site [4] = Text Message [5] = USPS mail ) After the operation, I want this: Array ( [75] = Personal Email [40] = USPS mail [31] = Personal Phone [31] = Web site [31] = Text Message ) Note: This is a descending-sort of Array 1 while being coupled to index of Array 2. In other words, the order of Array 2 depends upon the order of Array 1 -- the two arrays are coupled. I've solved this problem, but my solution is pretty lame. There has to be a better/slicker way. Suggestions? Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Sort two coupled arrays
Am 07.04.2010 22:09, schrieb tedd: Hi gang: Here's the problem -- I want to sort and combine two arrays into one sorted array. Here's a real-world example: Array 1 ( [1] = 75 [2] = 31 [3] = 31 [4] = 31 [5] = 40 ) Array 2 ( [1] = Personal Email [2] = Personal Phone [3] = Web site [4] = Text Message [5] = USPS mail ) After the operation, I want this: Array ( [75] = Personal Email [40] = USPS mail [31] = Personal Phone [31] = Web site [31] = Text Message ) Note: This is a descending-sort of Array 1 while being coupled to index of Array 2. In other words, the order of Array 2 depends upon the order of Array 1 -- the two arrays are coupled. I've solved this problem, but my solution is pretty lame. There has to be a better/slicker way. Suggestions? Cheers, tedd array_combine($key_array, $value_array) :) -- Piero -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Sort two coupled arrays
Piero Steinger wrote: Am 07.04.2010 22:09, schrieb tedd: Hi gang: Here's the problem -- I want to sort and combine two arrays into one sorted array. Here's a real-world example: Array 1 ( [1] = 75 [2] = 31 [3] = 31 [4] = 31 [5] = 40 ) Array 2 ( [1] = Personal Email [2] = Personal Phone [3] = Web site [4] = Text Message [5] = USPS mail ) After the operation, I want this: Array ( [75] = Personal Email [40] = USPS mail [31] = Personal Phone [31] = Web site [31] = Text Message ) Note: This is a descending-sort of Array 1 while being coupled to index of Array 2. In other words, the order of Array 2 depends upon the order of Array 1 -- the two arrays are coupled. I've solved this problem, but my solution is pretty lame. There has to be a better/slicker way. Suggestions? Cheers, tedd array_combine($key_array, $value_array) :) -- Piero And then: krsort($combined_array); Cheers, Mattias -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Sort two coupled arrays
On Wed, Apr 07, 2010 at 04:09:47PM -0400, tedd wrote: Hi gang: Here's the problem -- I want to sort and combine two arrays into one sorted array. Here's a real-world example: Array 1 ( [1] = 75 [2] = 31 [3] = 31 [4] = 31 [5] = 40 ) Array 2 ( [1] = Personal Email [2] = Personal Phone [3] = Web site [4] = Text Message [5] = USPS mail ) After the operation, I want this: Array ( [75] = Personal Email [40] = USPS mail [31] = Personal Phone [31] = Web site [31] = Text Message ) Note: This is a descending-sort of Array 1 while being coupled to index of Array 2. In other words, the order of Array 2 depends upon the order of Array 1 -- the two arrays are coupled. I've solved this problem, but my solution is pretty lame. There has to be a better/slicker way. Just so I understand the way arrays work in PHP (gee, I *thought* I did!), as you add the final three elements in the final array, won't they overwrite each other? I was under the impression that a *numerically* indexed array has a constraint that the numeric indexes be unique, if not contiguous. Am I wrong? If so, please provide a reference. Or are those numbers really strings? Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Sort two coupled arrays
On Wed, Apr 7, 2010 at 5:02 PM, Paul M Foster pa...@quillandmouse.com wrote: On Wed, Apr 07, 2010 at 04:09:47PM -0400, tedd wrote: Hi gang: Here's the problem -- I want to sort and combine two arrays into one sorted array. Here's a real-world example: Array 1 ( [1] = 75 [2] = 31 [3] = 31 [4] = 31 [5] = 40 ) Array 2 ( [1] = Personal Email [2] = Personal Phone [3] = Web site [4] = Text Message [5] = USPS mail ) After the operation, I want this: Array ( [75] = Personal Email [40] = USPS mail [31] = Personal Phone [31] = Web site [31] = Text Message ) [snip] Just so I understand the way arrays work in PHP (gee, I *thought* I did!), as you add the final three elements in the final array, won't they overwrite each other? I was under the impression that a *numerically* indexed array has a constraint that the numeric indexes be unique, if not contiguous. Am I wrong? If so, please provide a reference. Or are those numbers really strings? Paul -- Paul M. Foster Array indexes have to be unique regardless of whether they are numeric or strings. ?php $a = array ( 1 = '75', 2 = '31', 3 = '31', 4 = '31', 5 = '40', ); $b = array ( 1 = 'Personal Email', 2 = 'Personal Phone', 3 = 'Web site', 4 = 'Text Message', 5 = 'USPS mail', ); $x = array_combine($a, $b); var_export($x); /* array ( 75 = 'Personal Email', 31 = 'Text Message', 40 = 'USPS mail', ) */ echo \n; krsort($x); var_export($x); /* array ( 75 = 'Personal Email', 40 = 'USPS mail', 31 = 'Text Message', ) */ ? Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Sort two coupled arrays
Try this insted array( [0]=array( [0]=75, [1] = Personal Email) [1]=array( [0]=31, [1] = Personal Phone) [2]=array( [0]=31, [1] = Web site) [3]=array( [0]=31, [1] = Text Message) [4]=array( [0]=40, [1] = USPS mail) MvH / Hans Åhlin Tel: +46761488019 http://www.kronan-net.com/ irc://irc.freenode.net:6667 - TheCoin 2010/4/7 tedd t...@sperling.com: Hi gang: Here's the problem -- I want to sort and combine two arrays into one sorted array. Here's a real-world example: Array 1 ( [1] = 75 [2] = 31 [3] = 31 [4] = 31 [5] = 40 ) Array 2 ( [1] = Personal Email [2] = Personal Phone [3] = Web site [4] = Text Message [5] = USPS mail ) After the operation, I want this: Array ( [75] = Personal Email [40] = USPS mail [31] = Personal Phone [31] = Web site [31] = Text Message ) Note: This is a descending-sort of Array 1 while being coupled to index of Array 2. In other words, the order of Array 2 depends upon the order of Array 1 -- the two arrays are coupled. I've solved this problem, but my solution is pretty lame. There has to be a better/slicker way. Suggestions? Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- 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] Sort two coupled arrays {my solution]
At 5:35 PM -0400 4/7/10, Andrew Ballard wrote: On Wed, Apr 7, 2010 at 5:02 PM, Paul M Foster pa...@quillandmouse.com wrote: Array indexes have to be unique regardless of whether they are numeric or strings. Ahhh, so you start to see the problem, eh? Let's look at the problem again (a vote collection problem): Array 1 ( [1] = 75 [2] = 31 [3] = 31 [4] = 31 [5] = 40 ) Array 1 is an array that contains the count of votes ($votes[] ) for the index. IOW, index 1 received 75 votes. Array 2 ( [1] = Personal Email [2] = Personal Phone [3] = Web site [4] = Text Message [5] = USPS mail ) Array 2 is an array that contains the names for the items ($items[] ) voted upon. As such, index 1 (Personal Email) received 75 votes. Now, I have this data in two different arrays and I wanted to combine the data into one array and then preform a descend sort. This is the way I solved it: $final = array(); for($i =1; $i =5; $i++) { $final[$i][] = $votes[$i]; $final[$i][] = $items[$i]; } echo(pre); echo('br'); print_r($final); echo('br'); array_multisort($final, SORT_DESC); echo('br'); print_r($final); echo('br'); echo(/pre); I was hoping that someone might present something clever. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Sort two coupled arrays {my solution]
rsort(array_combine(array2, array1)); you should expect array( 'Personal Email' = 75, 'USPS mail' = 40, 'Personal Phone' = 31, 'Web site' = 31, 'Text Message' = 31 ) logically, the items are your key but not the count of votes On Wed, Apr 7, 2010 at 6:29 PM, tedd tedd.sperl...@gmail.com wrote: At 5:35 PM -0400 4/7/10, Andrew Ballard wrote: On Wed, Apr 7, 2010 at 5:02 PM, Paul M Foster pa...@quillandmouse.com wrote: Array indexes have to be unique regardless of whether they are numeric or strings. Ahhh, so you start to see the problem, eh? Let's look at the problem again (a vote collection problem): Array 1 ( [1] = 75 [2] = 31 [3] = 31 [4] = 31 [5] = 40 ) Array 1 is an array that contains the count of votes ($votes[] ) for the index. IOW, index 1 received 75 votes. Array 2 ( [1] = Personal Email [2] = Personal Phone [3] = Web site [4] = Text Message [5] = USPS mail ) Array 2 is an array that contains the names for the items ($items[] ) voted upon. As such, index 1 (Personal Email) received 75 votes. Now, I have this data in two different arrays and I wanted to combine the data into one array and then preform a descend sort. This is the way I solved it: $final = array(); for($i =1; $i =5; $i++) { $final[$i][] = $votes[$i]; $final[$i][] = $items[$i]; } echo(pre); echo('br'); print_r($final); echo('br'); array_multisort($final, SORT_DESC); echo('br'); print_r($final); echo('br'); echo(/pre); I was hoping that someone might present something clever. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- 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