php-general Digest 4 Sep 2012 06:17:03 -0000 Issue 7950
php-general Digest 4 Sep 2012 06:17:03 - Issue 7950 Topics (messages 318958 through 318978): Re: load rtf file 318958 by: David OBrien 318971 by: Tedd Sperling 318972 by: Micky Hulse 318976 by: tamouse mailing lists ksort by value 318959 by: John Taylor-Johnston 318960 by: Matijn Woudt 318962 by: John Taylor-Johnston 318963 by: John Taylor-Johnston 318964 by: Serge Fonville 318965 by: John Taylor-Johnston 318966 by: John Taylor-Johnston 318967 by: Serge Fonville 318968 by: Serge Fonville 318969 by: Stuart Dallas 318970 by: John Taylor-Johnston mysql and php questions 318961 by: Littlefield, Tyler templeting 318973 by: David McGlone 318974 by: David OBrien 318975 by: David McGlone 318977 by: tamouse mailing lists 318978 by: Louis Huppenbauer 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 Mon, Sep 3, 2012 at 12:56 PM, Matijn Woudt tijn...@gmail.com wrote: On Mon, Sep 3, 2012 at 5:24 PM, Tedd Sperling t...@sperling.com wrote: On Sep 3, 2012, at 1:23 AM, John Taylor-Johnston jt.johns...@usherbrooke.ca wrote: I have a big giant RTF file. I could convert it to plain text. BUT can PHP do it for me? Hell, even M$ can't do it! I have tons of old Word RFT files that were orphaned by the installation of a newer of M$ Word. The upgrade actually deleted older versions of Word and then would not open the older files because of security concerns (they were create by an older version, duh). It was a nightmare -- as a result, I lost years of business correspondence. Now I make z text version of every document I write. If I wanted to get those old files back, I will have to set up an older computer, reinstall the older version of Word and then transfer those files, convert them to text, and bring them back. That's a lot of work because I trusted M$ to respect older files, but they don't. In short, don't trust M$. Cheers, tedd Either they don't have respect to the older files, or they just don't understand how the format works.. The same goes for opening '97-'03 files in Word 2010 version, sometimes it's also all messed up. Just a side note tedd, couldn't you just open those RTF files with wordpad? IIRC it supports RTF and plain text (even in Win7) - Matijn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php I found this http://webcheatsheet.com/php/reading_the_clean_text_from_rtf.php ---End Message--- ---BeginMessage--- On Sep 3, 2012, at 12:56 PM, Matijn Woudt tijn...@gmail.com wrote Just a side note tedd, couldn't you just open those RTF files with wordpad? IIRC it supports RTF and plain text (even in Win7) - Matijn Maybe if I was on a Windoze machine, but I'm on a Mac. Cheers, tedd _ t...@sperling.com http://sperling.com ---End Message--- ---BeginMessage--- On Mon, Sep 3, 2012 at 3:52 PM, Tedd Sperling t...@sperling.com wrote: Maybe if I was on a Windoze machine, but I'm on a Mac. What about TextEdit.app? ---End Message--- ---BeginMessage--- On Mon, Sep 3, 2012 at 6:04 PM, Micky Hulse mickyhulse.li...@gmail.com wrote: On Mon, Sep 3, 2012 at 3:52 PM, Tedd Sperling t...@sperling.com wrote: Maybe if I was on a Windoze machine, but I'm on a Mac. What about TextEdit.app? Or Open/Libre Office? As for the OP, I know you can script Open/Libre Office with python to do things like batch convert RTF to Text. ---End Message--- ---BeginMessage--- Hi, ?php ... $words = preg_split('/[[:space:]]+/',$mynewstring); foreach ($words as $word) { $freq[$word]++; } ksort($freq); print_r ($freq); ? If I have my terminology right, ksort($freq) sorts the array by the key. And that works fine. But I would also like to sort by value to see which words are more frequent. There is no |ascending/descending option to ksort?| Thanks, John Array ( [] = 1 [a] = 165 [about] = 4 [academy] = 4 [accident] = 3 [accidental] = 1 [accused] = 1 [achieve] = 1 [across] = 1 [act] = 3 [addition] = 1 [address] = 1 [adult] = 3 [advise] = 2 [advised] = 1 [advising] = 2 [advisory] = 4 [after] = 2 [aged] = 1 [aggravated] = 1 [airport] = 4 [alarm] = 2 [alcohol] = 5 [alert] = 1 [all] = 2 [allegedly] = 2 [allow] = 1 [along] = 2 [also] = 14 [altercation] = 2 [am] = 16 ---End Message--- ---BeginMessage--- On Mon, Sep 3, 2012 at 8:33 PM, John Taylor-Johnston jt.johns...@usherbrooke.ca wrote: Hi, ?php ... $words
Re: [PHP] templeting
2012/9/4 tamouse mailing lists tamouse.li...@gmail.com On Mon, Sep 3, 2012 at 8:49 PM, David McGlone da...@dmcentral.net wrote: On Monday, September 03, 2012 09:45:23 PM David OBrien wrote: On Sep 3, 2012 9:15 PM, David McGlone da...@dmcentral.net wrote: Does anyone use any templeting system for any projects? If so what would anyone recommend? I looked at Code Ignitor, but it seems the templeting system is optional and left out by default. I use smarty I've used smarty in the past and was thinking about that, but PEAR is absolete anymore and I don't really know of a good replacement. :-/ I use Smarty as well, but I've never used it from PEAR. I just use the version downloadable from http://www.smarty.net -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php I'm mostly working with twig, a symfony2 framework component. I especially like it's template inheritance and the (in my opinion) very clear syntax. http://twig.sensiolabs.org/
Re: [PHP] templeting
On Tue, Sep 4, 2012 at 8:16 AM, Louis Huppenbauer louis.huppenba...@gmail.com wrote: I'm mostly working with twig, a symfony2 framework component. I especially like it's template inheritance and the (in my opinion) very clear syntax. http://twig.sensiolabs.org/ Hi, all I most like to use template-engines that does not allow to write direct PHP code in the template. This restricts you to split the logic from the displaying code. Template-engines I know of: * Smarty * Twig * FLUID * OPT (Open Power Template) If you want a bigger list, visit wikipedia: http://de.wikipedia.org/wiki/Template-Engine#Template-Engines_f.C3.BCr_PHP http://en.wikipedia.org/wiki/Template_engine_%28web%29#Comparison What I used most is Twig. For the next project (if it has no template-engine build in in the system I choose) I'll give OPT a try. It looks promising ;) Bye Simon -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] templeting
tamouse mailing lists wrote: I've used smarty in the past and was thinking about that, but PEAR is absolete anymore and I don't really know of a good replacement. :-/ I use Smarty as well, but I've never used it from PEAR. I just use the version downloadable fromhttp://www.smarty.net I'm still on Smarty2 and we 'maintain' our own copy, but starting a new setup, Smarty3 just needs a different style of working if you have used 2 in the past. -- Lester Caine - G8HFL - Contact - http://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk Rainbow Digital Media - http://rainbowdigitalmedia.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] array.sorting.php
Hi, Sorting question. http://www.php.net/manual/en/array.sorting.php I'm using ksort, which sorts like this. I don't want to use strolower. Is there a function/switch in one of the sort functions where I could get another aphabetical sort? http://www.php.net/manual/en/array.sorting.php has a lot of options. I,m not sure which one I should choose. This is what I get: LABRADOR CITY LACOSTA LARGE Labrador Labrador City Labrador Sea Lacosta Large labrador labrador sea lacosta large This is what I want: LABRADOR Labrador labrador LABRADOR CITY Labrador City Labrador Sea labrador sea LACOSTA Lacosta lacosta LARGE Large large -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] array.sorting.php
On Tue, Sep 4, 2012 at 1:15 PM, John Taylor-Johnston jt.johns...@usherbrooke.ca wrote: Hi, Sorting question. http://www.php.net/manual/en/**array.sorting.phphttp://www.php.net/manual/en/array.sorting.php I'm using ksort, which sorts like this. I don't want to use strolower. Is there a function/switch in one of the sort functions where I could get another aphabetical sort? http://www.php.net/manual/en/**array.sorting.phphttp://www.php.net/manual/en/array.sorting.phphas a lot of options. I,m not sure which one I should choose. This is what I get: LABRADOR CITY LACOSTA LARGE Labrador Labrador City Labrador Sea Lacosta Large labrador labrador sea lacosta large This is what I want: LABRADOR Labrador labrador LABRADOR CITY Labrador City Labrador Sea labrador sea LACOSTA Lacosta lacosta LARGE Large large -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php natsort natcasesort
Re: [PHP] array.sorting.php
The problem is I'm sorting the key. The alphabetical thing is in the key. David OBrien wrote: On Tue, Sep 4, 2012 at 1:15 PM, John Taylor-Johnston jt.johns...@usherbrooke.ca mailto:jt.johns...@usherbrooke.ca wrote: Hi, Sorting question. http://www.php.net/manual/en/array.sorting.php I'm using ksort, which sorts like this. I don't want to use strolower. Is there a function/switch in one of the sort functions where I could get another aphabetical sort? http://www.php.net/manual/en/array.sorting.php has a lot of options. I,m not sure which one I should choose. This is what I get: LABRADOR CITY LACOSTA LARGE Labrador Labrador City Labrador Sea Lacosta Large labrador labrador sea lacosta large This is what I want: LABRADOR Labrador labrador LABRADOR CITY Labrador City Labrador Sea labrador sea LACOSTA Lacosta lacosta LARGE Large large -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php natsort natcasesort
[PHP] PHP CURL JSON POST Firebug
I am hoping someone can spot what is missing here. I am getting null result from curl-ing a page with json post variables. I try this url in my Firefox browser - http://www.targetsite.com/search.php#somevar.someothervar (#somevar.someothervar are irrelevant, I think, as I get the curl variables from Firebug below.) In Firebug, this shows: POST http://www.targetsite.com/ajax/search.xml In Firebug, below this link are tabs for: Headers, Post, Response, XML and Cookies. Post tab shows like: JSON VAR1 1 VAR2 2012-09-12 VAR3 null CACHED [] OPTIONSnull To prove there is output, the Firebug Response tab shows: ?xml version=1.0 encoding=utf-8? JSON various JSON encoded stuff /JSON The above is what I am trying to curl. My php code: $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, 1); //target page from Firebug above: curl_setopt($ch, CURLOPT_URL, http://www.targetsite.com/ajax/search.xml;); //I was not sure how to represent CACHED [], so set it to null $data = array( VAR1 = 1, VAR2 = 2012-09-12, VAR3 = null, CACHED=null, OPTIONS=null, ); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); //make the request $result = curl_exec($ch); //this returns null Any ideas where to go with this? Maybe I need to include the Cookies? I use the above php and curl functions normally so it's all installed on the server. John -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] array.sorting.php
On Tue, Sep 4, 2012 at 7:23 PM, John Taylor-Johnston jt.johns...@usherbrooke.ca wrote: The problem is I'm sorting the key. The alphabetical thing is in the key. David OBrien wrote: Taken from the natsort manual page comments: ?php /** * keyNatSort does a natural sort via key on the supplied array. * * @param $array The array to natural sort via key. * @param $saveMemory If true will delete values from the original array as it builds the sorted array. * @return Sorted array on success. Boolean false if sort failed or null if the object was not an array. */ function keyNatSort($array, $saveMemory=false) { if(is_array($array)) { $keys = array_keys($array); if(natsort($keys)) { $result = array(); foreach($keys as $key) { $result[$key] = $array[$key]; if($saveMemory) unset($array[$key]); } } else $result = false; } else $result = null; return $result; } ? - Matijn PS. Please bottom post on this and probably any mailing list -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] array.sorting.php
David OBrien wrote: On Tue, Sep 4, 2012 at 1:15 PM, John Taylor-Johnston jt.johns...@usherbrooke.ca mailto:jt.johns...@usherbrooke.ca wrote: Hi, Sorting question. http://www.php.net/manual/en/array.sorting.php I'm using ksort, which sorts like this. I don't want to use strolower. Is there a function/switch in one of the sort functions where I could get another aphabetical sort? http://www.php.net/manual/en/array.sorting.php has a lot of options. I,m not sure which one I should choose. This is what I get: LABRADOR CITY LACOSTA LARGE Labrador Labrador City Labrador Sea Lacosta Large labrador labrador sea lacosta large This is what I want: LABRADOR Labrador labrador LABRADOR CITY Labrador City Labrador Sea labrador sea LACOSTA Lacosta lacosta LARGE Large large natsort natcasesort I'm sorting the key. It doesn't work. ksort is the only choice I have, right? Ok, let's approach this question differently. Right now the frequency of each word is in value. How do I put the frequency of each word in the key? I'm fuzzy when it comes to arrays. I can do this is MySQL. All I need is an id and two varchars and then I know how to sort any way I want. But I am processing dynamic text files. MySQL is not an option; data changes too much. PHP is faster and more efficient. I'm just no good at arrays. Here is my code: ---snip--- $mynewstring = http://foo.com/bigtextfile.txt;; $words = preg_split('/[[:space:]]+/',$mynewstring); foreach ($words as $word) { $freq[$word]++; } #natcasesort($freq); ksort($freq); John
Re: [PHP] PHP CURL JSON POST Firebug
On Tue, Sep 4, 2012 at 7:35 PM, ioan...@btinternet.com ioan...@btinternet.com wrote: I am hoping someone can spot what is missing here. I am getting null result from curl-ing a page with json post variables. I try this url in my Firefox browser - http://www.targetsite.com/search.php#somevar.someothervar (#somevar.someothervar are irrelevant, I think, as I get the curl variables from Firebug below.) In Firebug, this shows: POST http://www.targetsite.com/ajax/search.xml In Firebug, below this link are tabs for: Headers, Post, Response, XML and Cookies. Post tab shows like: JSON VAR1 1 VAR2 2012-09-12 VAR3 null CACHED [] OPTIONSnull To prove there is output, the Firebug Response tab shows: ?xml version=1.0 encoding=utf-8? JSON various JSON encoded stuff /JSON The above is what I am trying to curl. My php code: $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, 1); //target page from Firebug above: curl_setopt($ch, CURLOPT_URL, http://www.targetsite.com/ajax/search.xml;); //I was not sure how to represent CACHED [], so set it to null try CACHED=array() $data = array( VAR1 = 1, VAR2 = 2012-09-12, VAR3 = null, CACHED=null, OPTIONS=null, ); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); //make the request $result = curl_exec($ch); //this returns null Any ideas where to go with this? Maybe I need to include the Cookies? I use the above php and curl functions normally so it's all installed on the server. John It might be that the site is using sessions/cookies. Have a look at the header data with firebug. Not sure if that's the problem, to find out what's really going on, call echo curl_error($ch); after curl_exec to find out what went wrong exactly. If you still don't know how to proceed, paste the result of the curl_error call in your reply. - Matijn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] array.sorting.php
http://php.net/uksort -- Sent from my leaf blower On 4 Sep 2012 18:39, John Taylor-Johnston jt.johns...@usherbrooke.ca wrote: David OBrien wrote: On Tue, Sep 4, 2012 at 1:15 PM, John Taylor-Johnston jt.johns...@usherbrooke.ca mailto:jt.johnston@**usherbrooke.cajt.johns...@usherbrooke.ca wrote: Hi, Sorting question. http://www.php.net/manual/en/**array.sorting.phphttp://www.php.net/manual/en/array.sorting.php I'm using ksort, which sorts like this. I don't want to use strolower. Is there a function/switch in one of the sort functions where I could get another aphabetical sort? http://www.php.net/manual/en/**array.sorting.phphttp://www.php.net/manual/en/array.sorting.phphas a lot of options. I,m not sure which one I should choose. This is what I get: LABRADOR CITY LACOSTA LARGE Labrador Labrador City Labrador Sea Lacosta Large labrador labrador sea lacosta large This is what I want: LABRADOR Labrador labrador LABRADOR CITY Labrador City Labrador Sea labrador sea LACOSTA Lacosta lacosta LARGE Large large natsort natcasesort I'm sorting the key. It doesn't work. ksort is the only choice I have, right? Ok, let's approach this question differently. Right now the frequency of each word is in value. How do I put the frequency of each word in the key? I'm fuzzy when it comes to arrays. I can do this is MySQL. All I need is an id and two varchars and then I know how to sort any way I want. But I am processing dynamic text files. MySQL is not an option; data changes too much. PHP is faster and more efficient. I'm just no good at arrays. Here is my code: ---snip---** $mynewstring = http://foo.com/bigtextfile.**txthttp://foo.com/bigtextfile.txt ; $words = preg_split('/[[:space:]]+/',$**mynewstring); foreach ($words as $word) { $freq[$word]++; } #natcasesort($freq); ksort($freq); John
Re: [PHP] array.sorting.php
On Tue, Sep 4, 2012 at 7:38 PM, John Taylor-Johnston jt.johns...@usherbrooke.ca wrote: David OBrien wrote: On Tue, Sep 4, 2012 at 1:15 PM, John Taylor-Johnston jt.johns...@usherbrooke.ca mailto:jt.johns...@usherbrooke.ca wrote: Hi, Sorting question. http://www.php.net/manual/en/array.sorting.php I'm using ksort, which sorts like this. I don't want to use strolower. Is there a function/switch in one of the sort functions where I could get another aphabetical sort? http://www.php.net/manual/en/array.sorting.php has a lot of options. I,m not sure which one I should choose. This is what I get: LABRADOR CITY LACOSTA LARGE Labrador Labrador City Labrador Sea Lacosta Large labrador labrador sea lacosta large This is what I want: LABRADOR Labrador labrador LABRADOR CITY Labrador City Labrador Sea labrador sea LACOSTA Lacosta lacosta LARGE Large large natsort natcasesort I'm sorting the key. It doesn't work. ksort is the only choice I have, right? Ok, let's approach this question differently. Right now the frequency of each word is in value. How do I put the frequency of each word in the key? try array_flip(), keep in mind though, that when two words have the same frequency, one of them will get lost because the keys are identical. I'm fuzzy when it comes to arrays. I can do this is MySQL. All I need is an id and two varchars and then I know how to sort any way I want. But I am processing dynamic text files. MySQL is not an option; data changes too much. PHP is faster and more efficient. I'm just no good at arrays. Here is my code: ---snip--- $mynewstring = http://foo.com/bigtextfile.txt;; $words = preg_split('/[[:space:]]+/',$mynewstring); foreach ($words as $word) { $freq[$word]++; } #natcasesort($freq); ksort($freq); John You can try uksort with a custom compare function. - Matijn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP CURL JSON POST Firebug
On 04/09/2012 18:41, Matijn Woudt wrote: On Tue, Sep 4, 2012 at 7:35 PM, ioan...@btinternet.com ioan...@btinternet.com wrote: I am hoping someone can spot what is missing here. I am getting null result from curl-ing a page with json post variables. I try this url in my Firefox browser - http://www.targetsite.com/search.php#somevar.someothervar (#somevar.someothervar are irrelevant, I think, as I get the curl variables from Firebug below.) In Firebug, this shows: POST http://www.targetsite.com/ajax/search.xml In Firebug, below this link are tabs for: Headers, Post, Response, XML and Cookies. Post tab shows like: JSON VAR1 1 VAR2 2012-09-12 VAR3 null CACHED [] OPTIONSnull To prove there is output, the Firebug Response tab shows: ?xml version=1.0 encoding=utf-8? JSON various JSON encoded stuff /JSON The above is what I am trying to curl. My php code: $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, 1); //target page from Firebug above: curl_setopt($ch, CURLOPT_URL, http://www.targetsite.com/ajax/search.xml;); //I was not sure how to represent CACHED [], so set it to null try CACHED=array() $data = array( VAR1 = 1, VAR2 = 2012-09-12, VAR3 = null, CACHED=null, OPTIONS=null, ); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); //make the request $result = curl_exec($ch); //this returns null Any ideas where to go with this? Maybe I need to include the Cookies? I use the above php and curl functions normally so it's all installed on the server. John It might be that the site is using sessions/cookies. Have a look at the header data with firebug. Not sure if that's the problem, to find out what's really going on, call echo curl_error($ch); after curl_exec to find out what went wrong exactly. If you still don't know how to proceed, paste the result of the curl_error call in your reply. - Matijn I added the cookies to the post array. I changed php array to CACHED=array() for the JSON CACHED:[], and corrected php's null to NULL. It is not returning any error. The browser was showing 'resource not present' before I added the cookies to the post array, now it just returns null $result. Looks like I am transcribing something incorrectly. John -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] templeting
On Mon, Sep 3, 2012 at 9:14 PM, David McGlone da...@dmcentral.net wrote: Does anyone use any templeting system for any projects? If so what would anyone recommend? I looked at Code Ignitor, but it seems the templeting system is optional and left out by default. -- Regards David M. Well, for a different take on templating, my web framework is basically just a combination of input validation and output mechanisms (templating.) The library takes a functional programming approach in terms of architecture. Here's an example of the markup: http://nephtaliproject.com/documentation/markup/ Page output regions are broken up into pipes, and if one pipe errors out, it does not impact the other output regions. It does other things, too (config settings, debugging output, avoid prompts on back clicks after posting data, convenient PDO wrappers, etc.), but at its core, it's really a templating framework with input validation capabilities. Adam -- Nephtali: A simple, flexible, fast, and security-focused PHP framework http://nephtaliproject.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] array.sorting.php
On Tue, Sep 4, 2012 at 9:20 PM, John Taylor-Johnston jt.johns...@usherbrooke.ca wrote: Here is my code: ---snip--- $mynewstring = http://foo.com/bigtextfile.txt;; $words = preg_split('/[[:space:]]+/',$mynewstring); foreach ($words as $word) { $freq[$word]++; } #natcasesort($freq); ksort($freq); John You can try uksort with a custom compare function. - Matijn Custom compare function? Yes, for example: function insensitive_uksort($a,$b) { return strtolower($a)strtolower($b); } or use a function like strnatcasecmp. you can then call uksort($array, insensitive_uksort); or uksort($array, strnatcasecmp); - Matijn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] array.sorting.php
Matijn Woudt wrote: Taken from the natsort manual page comments: ?php /** * keyNatSort does a natural sort via key on the supplied array. * * @param $array The array to natural sort via key. * @param $saveMemory If true will delete values from the original array as it builds the sorted array. * @return Sorted array on success. Boolean false if sort failed or null if the object was not an array. */ PS. Please bottom post on this and probably any mailing list I've tried it. I don't see it sorting anything? http://cegepsherbrooke.qc.ca/~languesmodernes/test/keynatsort.php $words = preg_split('/[[:space:]]+/',$mynewstring); foreach ($words as $word) { $freq[$word]++; } function keyNatSort($array, $saveMemory=false) { if(is_array($array)) { $keys = array_keys($array); if(natsort($keys)) { $result = array(); foreach($keys as $key) { $result[$key] = $array[$key]; if($saveMemory) unset($array[$key]); } } else $result = false; } else $result = null; return $result; } keyNatSort($freq); echo table\n; foreach ($freq as $key = $val) { # echo $key = $val br /\n; echo trtd.str_replace(_, , $key)./tdtd$val/td/tr\n; } echo /table\n; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] array.sorting.php
On Tue, Sep 4, 2012 at 9:33 PM, John Taylor-Johnston jt.johns...@usherbrooke.ca wrote: Matijn Woudt wrote: Taken from the natsort manual page comments: ?php /** * keyNatSort does a natural sort via key on the supplied array. * * @param $array The array to natural sort via key. * @param $saveMemory If true will delete values from the original array as it builds the sorted array. * @return Sorted array on success. Boolean false if sort failed or null if the object was not an array. */ PS. Please bottom post on this and probably any mailing list I've tried it. I don't see it sorting anything? http://cegepsherbrooke.qc.ca/~languesmodernes/test/keynatsort.php $words = preg_split('/[[:space:]]+/',$mynewstring); foreach ($words as $word) { $freq[$word]++; } function keyNatSort($array, $saveMemory=false) { if(is_array($array)) { $keys = array_keys($array); if(natsort($keys)) { $result = array(); foreach($keys as $key) { $result[$key] = $array[$key]; if($saveMemory) unset($array[$key]); } } else $result = false; } else $result = null; return $result; } keyNatSort($freq); Try : $freq = keyNatSort($freq); - Matijn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php