php-general Digest 16 Nov 2006 09:19:33 -0000 Issue 4462
php-general Digest 16 Nov 2006 09:19:33 - Issue 4462 Topics (messages 244694 through 244708): cURL uses 244694 by: Philip Thompson 244695 by: Dave Goodchild 244696 by: Jon Anderson 244697 by: Eric Butera 244698 by: cajbecu 244708 by: clive Re: Splitting a string 244699 by: Børge Holen 244701 by: Chris 244702 by: Robert Cummings 244703 by: Chris 244704 by: Paul Novitski Re: Highjack? 244700 by: Chris Smart Quotes not so smart 244705 by: Larry Garfield 244706 by: Robert Cummings 244707 by: Travis Doherty Administrivia: To subscribe to the digest, e-mail: [EMAIL PROTECTED] To unsubscribe from the digest, e-mail: [EMAIL PROTECTED] To post to the list, e-mail: php-general@lists.php.net -- ---BeginMessage--- Hi. I've been doing some reading trying to figure out why I would want to use cURL. I have not found a solid reason yet. Does anyone have a useful example on why you would want to use cURL? Thanks, ~Philip ---End Message--- ---BeginMessage--- You would use cURL to achieve the things cURL is built to achieve? ---End Message--- ---BeginMessage--- Philip Thompson wrote: I've been doing some reading trying to figure out why I would want to use cURL. I have not found a solid reason yet. Does anyone have a useful example on why you would want to use cURL? It allows significant configurability and flexibility over PHP's more direct functions, for example, the ability to set a timeout, or get more direct control over output. You only have to read the curl documentation to see that it can do a lot of things that other PHP functions just can't do. I would suggest that you probably shouldn't try to find a reason to use curl, rather a reason to use curl will find you. jon ---End Message--- ---BeginMessage--- On 11/15/06, Philip Thompson [EMAIL PROTECTED] wrote: Hi. I've been doing some reading trying to figure out why I would want to use cURL. I have not found a solid reason yet. Does anyone have a useful example on why you would want to use cURL? Thanks, ~Philip -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Interfacing with payment/shipping gateway APIs. For example, in my store I must send post data to a payment gateway to tell them the amount, cc#, etc. and they will return text telling me the transaction passed/failed/etc. ---End Message--- ---BeginMessage--- well, there are more reasons you should use cURL .. - control and flexibility of the output, - post variables, - can interact with secure servers (ssl - supports certificates) - can use with proxys (http/socks) - set timeouts - easily modify headers :) - use different ip`s of the server when it`s used (if it is configured to do so) please read documentation at php.net/curl before changing your mind to not use it. it helps you a lot in your applications. an old frend told me.. you`ll love this class - what to see.. it happend :) On 11/15/06, Philip Thompson [EMAIL PROTECTED] wrote: Hi. I've been doing some reading trying to figure out why I would want to use cURL. I have not found a solid reason yet. Does anyone have a useful example on why you would want to use cURL? Thanks, ~Philip -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php ---End Message--- ---BeginMessage--- Dave Goodchild wrote: You would use cURL to achieve the things cURL is built to achieve? Wow that answer is not even worth the calories your burned type it. Theres not such thing as stupid questions, only stupid answers In your case this phrase holds some truth. ---End Message--- ---BeginMessage--- Oh this was good. I added a while loop to insert extra strings 0 in front of the number to add if the string is less than 5 chars short. I forgot to mentinon that the string actually could be shorter (just found out) and the code didn't work with fewer than 5 char strings. But now is rocks. Thanks again. On Wednesday 15 November 2006 06:24, Paul Novitski wrote: At 11/14/2006 03:17 PM, Børge Holen wrote: $number = 123456789 should print as following: var1: 12345 (and it is this lengt witch varies) var2: 67 var3: 89. You can also do this with a regular expression: $iNumber = '123456789'; $sPattern = '/(\d+)(\d{2})(\d{2})$/'; preg_match($sPattern, $iNumber, $aMatches); Then $aMatches contains: Array ( [0] = 123456789 [1] = 12345 [2] = 67 [3] = 89 ) The regexp pattern /(\d+)(\d{2})(\d{2})$/ means: (one or more digits) (two digits) (two digits) [end of string] preg_match http://ca3.php.net/manual/en/function.preg-match.php Pattern Syntax http://ca3.php.net/manual/en/reference.pcre.pattern.syntax.php Regards, Paul -- --- Børge Kennel Arivene
Re: [PHP] cURL uses
Dave Goodchild wrote: You would use cURL to achieve the things cURL is built to achieve? Wow that answer is not even worth the calories your burned type it. Theres not such thing as stupid questions, only stupid answers In your case this phrase holds some truth. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] file_get_contents
I am trying to read the contents of a PHP page for an audio player and put it into a textarea to be copied and pasted into an HTML page. The trouble is the textarea shows unparsed PHP code and I just want the HTML. The code is: $player = file_get_contents('player.php'); //Strip out unnecessary HTML Code if(preg_match('/!-- Start Player Code --(.*)!-- End Player Code --/s', $player, $matches)) { $code = $matches[1]; } echo textarea name=\textarea\ cols=\70\ rows=\15\ . $code . /textarea; echo BR; echo a href=\player.php\Click Here/a to view the player \n; Looked at using eval() but found this: Kepp the following Quote in mind: If eval() is the answer, you're almost certainly asking the wrong question. -- Rasmus Lerdorf, BDFL of PHP (Hmmm...) Any help much appreciated. Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Smart Quotes not so smart
Larry Garfield wrote: On our new devel setup (SQL Server 2k, OpenTDS ODBC driver, Apache, PHP 5.1.6), it works fine. On their new live setup, however, (same, but again not sure of the ODBC driver) they're getting the dreaded squares or question marks or accented characters that signify a garbled smart quote. I know they're not unicode characters because Windows, the DB server, and the driver are all set to either UTF-8 or UTF-16. I had a similar probelm before, but in my case a had to commetn out this line: AddDefaultCharset ISO-8859-1 in my httpd.conf file for apache -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] file_get_contents
Tom Chubb wrote: I am trying to read the contents of a PHP page for an audio player and put it into a textarea to be copied and pasted into an HTML page. The trouble is the textarea shows unparsed PHP code and I just want the HTML. The code is: $player = file_get_contents('player.php'); file_get_content('http://blabla.com/player.php'); // requires allow_url_fopen to be set to On. //Strip out unnecessary HTML Code if(preg_match('/!-- Start Player Code --(.*)!-- End Player Code --/s', $player, $matches)) { $code = $matches[1]; } echo textarea name=\textarea\ cols=\70\ rows=\15\ . $code . htmlentities($code) /textarea; echo BR; echo a href=\player.php\Click Here/a to view the player \n; Looked at using eval() but found this: Kepp the following Quote in mind: If eval() is the answer, you're almost certainly asking the wrong question. -- Rasmus Lerdorf, BDFL of PHP indeed eval is probably not the answer. (Hmmm...) Any help much appreciated. Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] taking a one off payment
Hi, What is the best way to take a one off payent (non-paypal). I have used oscommece but never attempted a one payment like a subscription charge. I would probalby be looking to use a trusted gateway like worldpay. R. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] taking a one off payment
Ross wrote: Hi, What is the best way to take a one off payent (non-paypal). cash in a stable currency ;-) I have used oscommece but never attempted a one payment like a subscription charge. I would probalby be looking to use a trusted gateway like worldpay. R. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] taking a one off payment
On 16 Nov 2006, at 05:20 , Ross wrote: What is the best way to take a one off payent Paypal. (non-paypal) Well then, when you eliminate the obvious choice... I have used oscommece Speaking of oscommerce, has that package ever been fixed to run without register_globals? -- I don't want to sell anything, buy anything, or process anything as a career. I don't want to sell anything bought or processed, or buy anything sold or processed, or process anything sold, bought, or processed, or repair anything sold, bought, or processed. You know, as a career, I don't want to do that. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] ob_start() and a callback function within a class, not updating ob_get_level().
Hello there, I have a question about ob_start() and ob_get_level(). When i use ob_start(), and then check ob_get_level(), it shows me 1. This is a normal behavior. Now when i do the following ob_start(array('ClassName', 'ClassMethod')). It does execute the methode, but it doesn't update ob_get_level(). Is this a normal behavior? Thx in advance. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] printing page functionality
Hi, We are in need of a printing functionality for our webpage. The problem is that some of our pages has a greater width than a A4 paper so not all of the content will be printed when using the built in printer functionality in the browser. Is there any useful script out there that can take the necessary content of the page and convert it to simple text and columns that will fit the paper when printing? or even better, a server application that can take the full content of the page and convert it to pdf or an image in a rescaled version that will fit the A4 paper? I've had a look at these HTML to PDF conversion apps: http://www.digitaljunkies.ca/dompdf/ http://www.rustyparts.com/pdf.php But they don't really cut it as we are using relative and absolute positioned divs and they don't have support for this. Thanks in advance -Ulf -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] CSS / PHP / Javascript
You can use a browser sniffer, where they've done all the work for you, and then link in the appropriate stylesheet using document.write(). I don't have personal experience with the IE conditionals, but I would be concerned that they'd get you into a bit of a box when it comes to recognizing other browsers. See: http://www.webreference.com/tools/browser/javascript.html Jochem Maas wrote: hmmm, this reply turned into something that resembles a rant about halfway thru... still ... maybe it's helpful in some way. Ed Lazor wrote: I'm reading a book on CSS and how you can define different style sheets for different visitors. I'm wondering how you guys do it. The book recommends using Javascript functions for identifying the user's browser and matching them with the corresponding style sheets. Anyone using PHP for this instead - specifically with defining style sheets for different target browsers and platforms? having to define CSS files for particular browsers and/or platforms is indicative of the crap we have to deal with - in theory you should NOT be targeting browser/platform specificallt AT ALL. you should be writing stylesheets for different types of user-agents (as defined by the W3C media types) - but who is really doing that. I recommend trying to build your sites using CSS that all browsers understand - i.e. avoid software/platform/version specific hacks whenever possible - when you have to add such a hack try to use a technique that you can unobtrusively incorporate into an existing CSS file. the man named tantek has lots of techniques you can abuses ;-) : e.g. http://tantek.com/CSS/Examples/midpass.html also consider that maybe you shouldn't try and tackle every visual discrepency between 2 different browsers/platforms! - you may have clients who bully you into 'fixing' layout in WeirdBrowser1.4 for instance - you need to develop a means to explain the problem to clients in such a way that they understand that not everything is under your control, and that they can't make you endlessly chase moving targets (i.e. make the client understand that web != print). if a client is willing to pay for every mindnumbing hour spent fixing arcane browser specific display 'bugs' then everything is okay - but don't get stuck working for weeks for no pay because some marketing manager has 'decided' he/she knows better what a website is and to what extent you must comply to his implicit wishes [i.e. you can break every 'rule' of website building and ignore/rape any/every relevant specification/standard so long as everything ispixel perfect in every browser according to the original mockup supplied by a graphic designer who can't even grasp the concept of screen resolution (I know plenty of print-based designers that fall into this category)] -Ed --PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- _ Myron Turner http://www.room535.org http://www.bstatzero.org http://www.mturner.org/XML_PullParser/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Sorting multidimensional arrays
Hi all. I have a multidimensional array here: array(6) { [0]= array(25) { [0]= string(1) 7 [eventid]= string(1) 7 [1]= string(2) 17 [cat_id]= string(2) 17 [2]= string(13) Tits And Bums [name]= string(13) Tits And Bums [3]= string(19) The Pleasure Centre [venue]= string(19) The Pleasure Centre [4]= string(17) �8.00 per session [fee]= string(17) �8.00 per session [5]= string(12) 01297 453555 [c_phone]= string(12) 01297 453555 [6]= string(0) [c_site]= string(0) [7]= string(4) RG29 [postcode]= string(4) RG29 [8]= string(10) 2006-12-17 [start_date]= string(10) 2006-12-17 [9]= string(10) 2007-08-18 [end_date]= string(10) 2007-08-18 [10]= string(5) 16.00 [start_time]= string(5) 16.00 [11]= string(6) weekly [frequency]= string(6) weekly [date]= int(1171753200) } [1]= array(25) { [0]= string(1) 7 [eventid]= string(1) 7 [1]= string(2) 17 [cat_id]= string(2) 17 [2]= string(13) Tits And Bums [name]= string(13) Tits And Bums [3]= string(19) The Pleasure Centre [venue]= string(19) The Pleasure Centre [4]= string(17) �8.00 per session [fee]= string(17) �8.00 per session [5]= string(12) 01297 453555 [c_phone]= string(12) 01297 453555 [6]= string(0) [c_site]= string(0) [7]= string(4) RG29 [postcode]= string(4) RG29 [8]= string(10) 2006-12-17 [start_date]= string(10) 2006-12-17 [9]= string(10) 2007-08-18 [end_date]= string(10) 2007-08-18 [10]= string(5) 16.00 [start_time]= string(5) 16.00 [11]= string(6) weekly [frequency]= string(6) weekly [date]= int(1172358000) } [2]= array(25) { [0]= string(2) 10 [eventid]= string(2) 10 [1]= string(2) 17 [cat_id]= string(2) 17 [2]= string(16) Fitness For Life [name]= string(16) Fitness For Life [3]= string(19) The Pleasure Centre [venue]= string(19) The Pleasure Centre [4]= string(17) �8.00 per session [fee]= string(17) �8.00 per session [5]= string(12) 01297 453555 [c_phone]= string(12) 01297 453555 [6]= string(0) [c_site]= string(0) [7]= string(4) RG29 [postcode]= string(4) RG29 [8]= string(10) 2006-12-17 [start_date]= string(10) 2006-12-17 [9]= string(10) 2007-12-23 [end_date]= string(10) 2007-12-23 [10]= string(5) 16.00 [start_time]= string(5) 16.00 [11]= string(6) weekly [frequency]= string(6) weekly [date]= int(1171753200) } [3]= array(25) { [0]= string(2) 10 [eventid]= string(2) 10 [1]= string(2) 17 [cat_id]= string(2) 17 [2]= string(16) Fitness For Life [name]= string(16) Fitness For Life [3]= string(19) The Pleasure Centre [venue]= string(19) The Pleasure Centre [4]= string(17) �8.00 per session [fee]= string(17) �8.00 per session [5]= string(12) 01297 453555 [c_phone]= string(12) 01297 453555 [6]= string(0) [c_site]= string(0) [7]= string(4) RG29 [postcode]= string(4) RG29 [8]= string(10) 2006-12-17 [start_date]= string(10) 2006-12-17 [9]= string(10) 2007-12-23 [end_date]= string(10) 2007-12-23 [10]= string(5) 16.00 [start_time]= string(5) 16.00 [11]= string(6) weekly [frequency]= string(6) weekly [date]= int(1172358000) } [4]= array(25) { [0]= string(2) 11 [eventid]= string(2) 11 [1]= string(2) 30 [cat_id]= string(2) 30 [2]= string(15) The Flea Market [name]= string(15) The Flea Market [3]= string(18) The Covered Market [venue]= string(18) The Covered Market [4]= string(1) 0 [fee]= string(1) 0 [5]= string(12) 0186 577 [c_phone]= string(12) 0186 577 [6]= string(0) [c_site]= string(0) [7]= string(4) SW20 [postcode]= string(4) SW20 [8]= string(10) 2006-12-17 [start_date]= string(10) 2006-12-17 [9]= string(10) 2007-12-17 [end_date]= string(10) 2007-12-17 [10]= string(5) 16.00 [start_time]= string(5) 16.00 [11]= string(8) biweekly [frequency]= string(8) biweekly [date]= int(1172358000) } [5]= array(25) { [0]= string(1) 4 [eventid]= string(1) 4 [1]= string(2) 21 [cat_id]= string(2) 21 [2]= string(16) The Kickabout II [name]= string(16) The Kickabout II [3]= string(18) The Football Pitch [venue]= string(18) The Football Pitch [4]= string(1) 0 [fee]= string(1) 0 [5]= string(12) 01737 453666 [c_phone]= string(12) 01737 453666 [6]= string(0) [c_site]= string(0) [7]= string(3) RH1 [postcode]= string(3) RH1 [8]= string(10) 2007-02-19 [start_date]= string(10) 2007-02-19 [9]= string(10) -00-00 [end_date]= string(10) -00-00 [10]= string(4) 3.00 [start_time]= string(4) 3.00 [11]= string(6) single [frequency]= string(6) single [date]= int(1171839600) } } ...which comprises a set of returned results for an events search - with the date computed dynamically and added to the end of the array in each case. What I want to do with this data is display the array in an html table, sorted by the date. At the moment the display shows each event from earliest to last date, then the next event from earliest to last etc. What I want to do is display all the data from earliest to last date - my question is, how do I sort the entire array based on the date value in the second level array? -- http://www.web-buddha.co.uk
Re: [PHP] Sorting multidimensional arrays
On Thu, 2006-11-16 at 15:28 +, Dave Goodchild wrote: Hi all. I have a multidimensional array here: Bums [name]= string(13) Tits And Bums [3]= string(19) The Pleasure [--SNIP--] ...which comprises a set of returned results for an events search - with the date computed dynamically and added to the end of the array in each case. What I want to do with this data is display the array in an html table, sorted by the date. At the moment the display shows each event from earliest to last date, then the next event from earliest to last etc. What I want to do is display all the data from earliest to last date - my question is, how do I sort the entire array based on the date value in the second level array? usort() Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] file_get_contents
Thanks Jochem, Tried that, but it's still showing php code in the text area! Any other ideas? The url is http://www.tnhosting.co.uk/scripts/gclub/updateplaylist.php and you see it on submission. Feel free to post. It's a testing server. On 16/11/06, Jochem Maas [EMAIL PROTECTED] wrote: Tom Chubb wrote: I am trying to read the contents of a PHP page for an audio player and put it into a textarea to be copied and pasted into an HTML page. The trouble is the textarea shows unparsed PHP code and I just want the HTML. The code is: $player = file_get_contents('player.php'); file_get_content('http://blabla.com/player.php'); // requires allow_url_fopen to be set to On. //Strip out unnecessary HTML Code if(preg_match('/!-- Start Player Code --(.*)!-- End Player Code --/s', $player, $matches)) { $code = $matches[1]; } echo textarea name=\textarea\ cols=\70\ rows=\15\ . $code . htmlentities($code) /textarea; echo BR; echo a href=\player.php\Click Here/a to view the player \n; Looked at using eval() but found this: Kepp the following Quote in mind: If eval() is the answer, you're almost certainly asking the wrong question. -- Rasmus Lerdorf, BDFL of PHP indeed eval is probably not the answer. (Hmmm...) Any help much appreciated. Tom -- Tom Chubb [EMAIL PROTECTED] 07915 053312 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] file_get_contents
Use curl or fopen() to make a request to that PHP page, instead of reading in the actual contents of the file. Example: ?php $url = 'http://blabla.com/player.php'; $ch=curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); curl_setopt($ch, CURLOPT_TIMEOUT, 120); curl_setopt($ch, CURLOPT_USERAGENT, Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $buffer = curl_exec($ch); curl_close($ch); echo TEXTAREA ... . $buffer . /TEXTAREA; ? -Original Message- From: Tom Chubb [mailto:[EMAIL PROTECTED] Sent: Thursday, November 16, 2006 10:49 AM To: [php] PHP General List Subject: Re: [PHP] file_get_contents Thanks Jochem, Tried that, but it's still showing php code in the text area! Any other ideas? The url is http://www.tnhosting.co.uk/scripts/gclub/updateplaylist.php and you see it on submission. Feel free to post. It's a testing server. On 16/11/06, Jochem Maas [EMAIL PROTECTED] wrote: Tom Chubb wrote: I am trying to read the contents of a PHP page for an audio player and put it into a textarea to be copied and pasted into an HTML page. The trouble is the textarea shows unparsed PHP code and I just want the HTML. The code is: $player = file_get_contents('player.php'); file_get_content('http://blabla.com/player.php'); // requires allow_url_fopen to be set to On. //Strip out unnecessary HTML Code if(preg_match('/!-- Start Player Code --(.*)!-- End Player Code --/s', $player, $matches)) { $code = $matches[1]; } echo textarea name=\textarea\ cols=\70\ rows=\15\ . $code . htmlentities($code) /textarea; echo BR; echo a href=\player.php\Click Here/a to view the player \n; Looked at using eval() but found this: Kepp the following Quote in mind: If eval() is the answer, you're almost certainly asking the wrong question. -- Rasmus Lerdorf, BDFL of PHP indeed eval is probably not the answer. (Hmmm...) Any help much appreciated. Tom -- Tom Chubb [EMAIL PROTECTED] 07915 053312 -- 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] file_get_contents
Tom Chubb wrote: Thanks Jochem, Tried that, but it's still showing php code in the text area! Any other ideas? vanilla sky (go search for the tagline) ... if I request the following I get a page with a player into: http://www.tnhosting.co.uk/scripts/gclub/player.php if you do the following you will get the same html source as my browser does - if it doesn't then you are doing something wrong - quite simply php is transparently making a http request to the webserver there is no way the webserver will differentiate between your script and every other request and give your the scrip the source code while everyone else is recieving the result of running the script: file_get_contents(http://www.tnhosting.co.uk/scripts/gclub/player.php;); below is the oneliner I used to prove this: php -r 'echo file_get_contents(http://www.tnhosting.co.uk/scripts/gclub/player.php;);' OUTPUT: (oh look no php) == html head titleTest Audio Player/title meta http-equiv=Content-Type content=text/html; charset=iso-8859-1 meta http-equiv=Expires content=Mon, 26 Jul 1997 05:00:00 GMT/ meta http-equiv=Pragma content=no-cache / /head body !-- Start Player Code -- !-- Contact [EMAIL PROTECTED] if you have any problems -- object classid=clsid:d27cdb6e-ae6d-11cf-96b8-44455354 codebase=http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0; width=400 height=15 param name=allowScriptAccess value=sameDomain/ param name=movie value=http://www.tnhosting.co.uk/scripts/gclub/xspf_player_slim.swf?song_url= http://www.tnhosting.co.uk/scripts/gclub/audio/faith.mp3song_title=Another Stomping Funker!autoplay=true / param name=quality value=high/ param name=bgcolor value=#E6E6E6/ embed src=http://www.tnhosting.co.uk/scripts/gclub/xspf_player_slim.swf?song_url= http://www.tnhosting.co.uk/scripts/gclub/audio/faith.mp3song_title=Another Stomping Funker!autoplay=true width=400 height=15 align=center quality=high bgcolor=#E6E6E6 allowscriptaccess=sameDomain type=application/x-shockwave-flash pluginspage=http://www.macromedia.com/go/getflashplayer; /embed /object !-- End Player Code -- /body /html The url is http://www.tnhosting.co.uk/scripts/gclub/updateplaylist.php and you see it on submission. Feel free to post. It's a testing server. On 16/11/06, Jochem Maas [EMAIL PROTECTED] wrote: Tom Chubb wrote: I am trying to read the contents of a PHP page for an audio player and put it into a textarea to be copied and pasted into an HTML page. The trouble is the textarea shows unparsed PHP code and I just want the HTML. The code is: $player = file_get_contents('player.php'); file_get_content('http://blabla.com/player.php'); // requires allow_url_fopen to be set to On. //Strip out unnecessary HTML Code if(preg_match('/!-- Start Player Code --(.*)!-- End Player Code --/s', $player, $matches)) { $code = $matches[1]; } echo textarea name=\textarea\ cols=\70\ rows=\15\ . $code . htmlentities($code) /textarea; echo BR; echo a href=\player.php\Click Here/a to view the player \n; Looked at using eval() but found this: Kepp the following Quote in mind: If eval() is the answer, you're almost certainly asking the wrong question. -- Rasmus Lerdorf, BDFL of PHP indeed eval is probably not the answer. (Hmmm...) Any help much appreciated. Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] file_get_contents
Brad Fuller wrote: Use curl or fopen() to make a request to that PHP page, instead of reading in the actual contents of the file. heh Brad wtf do you think thw following line does??: $html = file_get_contents(http://www.tnhosting.co.uk/scripts/gclub/player.php;); Example: ?php $url = 'http://blabla.com/player.php'; $ch=curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); curl_setopt($ch, CURLOPT_TIMEOUT, 120); curl_setopt($ch, CURLOPT_USERAGENT, Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $buffer = curl_exec($ch); curl_close($ch); echo TEXTAREA ... . $buffer . /TEXTAREA; ? -Original Message- From: Tom Chubb [mailto:[EMAIL PROTECTED] Sent: Thursday, November 16, 2006 10:49 AM To: [php] PHP General List Subject: Re: [PHP] file_get_contents Thanks Jochem, Tried that, but it's still showing php code in the text area! Any other ideas? The url is http://www.tnhosting.co.uk/scripts/gclub/updateplaylist.php and you see it on submission. Feel free to post. It's a testing server. On 16/11/06, Jochem Maas [EMAIL PROTECTED] wrote: Tom Chubb wrote: I am trying to read the contents of a PHP page for an audio player and put it into a textarea to be copied and pasted into an HTML page. The trouble is the textarea shows unparsed PHP code and I just want the HTML. The code is: $player = file_get_contents('player.php'); file_get_content('http://blabla.com/player.php'); // requires allow_url_fopen to be set to On. //Strip out unnecessary HTML Code if(preg_match('/!-- Start Player Code --(.*)!-- End Player Code --/s', $player, $matches)) { $code = $matches[1]; } echo textarea name=\textarea\ cols=\70\ rows=\15\ . $code . htmlentities($code) /textarea; echo BR; echo a href=\player.php\Click Here/a to view the player \n; Looked at using eval() but found this: Kepp the following Quote in mind: If eval() is the answer, you're almost certainly asking the wrong question. -- Rasmus Lerdorf, BDFL of PHP indeed eval is probably not the answer. (Hmmm...) Any help much appreciated. Tom -- Tom Chubb [EMAIL PROTECTED] 07915 053312 -- 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] file_get_contents
Yes, I realize that now ;) I didn't read it thoroughly enough before I posted :P I think what Tom is referring to as PHP code is just the extra HTML tags around the object tag that he is trying to strip out. Tom - Try this: ?php $code = file_get_contents(http://www.tnhosting.co.uk/scripts/gclub/player.php;); $nstart = strpos($code, '!-- Start Player Code --'); $nstop = strpos($code, '!-- End Player Code --'); echo TEXTAREA . substr($code, $nstart, $nstop-$nstart) . /TEXTAREA; ? -Original Message- From: Jochem Maas [mailto:[EMAIL PROTECTED] Sent: Thursday, November 16, 2006 11:12 AM To: Brad Fuller Cc: php-general@lists.php.net Subject: Re: [PHP] file_get_contents Brad Fuller wrote: Use curl or fopen() to make a request to that PHP page, instead of reading in the actual contents of the file. heh Brad wtf do you think thw following line does??: $html = file_get_contents(http://www.tnhosting.co.uk/scripts/gclub/player.php;); Example: ?php $url = 'http://blabla.com/player.php'; $ch=curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); curl_setopt($ch, CURLOPT_TIMEOUT, 120); curl_setopt($ch, CURLOPT_USERAGENT, Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $buffer = curl_exec($ch); curl_close($ch); echo TEXTAREA ... . $buffer . /TEXTAREA; ? -Original Message- From: Tom Chubb [mailto:[EMAIL PROTECTED] Sent: Thursday, November 16, 2006 10:49 AM To: [php] PHP General List Subject: Re: [PHP] file_get_contents Thanks Jochem, Tried that, but it's still showing php code in the text area! Any other ideas? The url is http://www.tnhosting.co.uk/scripts/gclub/updateplaylist.php and you see it on submission. Feel free to post. It's a testing server. On 16/11/06, Jochem Maas [EMAIL PROTECTED] wrote: Tom Chubb wrote: I am trying to read the contents of a PHP page for an audio player and put it into a textarea to be copied and pasted into an HTML page. The trouble is the textarea shows unparsed PHP code and I just want the HTML. The code is: $player = file_get_contents('player.php'); file_get_content('http://blabla.com/player.php'); // requires allow_url_fopen to be set to On. //Strip out unnecessary HTML Code if(preg_match('/!-- Start Player Code --(.*)!-- End Player Code --/s', $player, $matches)) { $code = $matches[1]; } echo textarea name=\textarea\ cols=\70\ rows=\15\ . $code . htmlentities($code) /textarea; echo BR; echo a href=\player.php\Click Here/a to view the player \n; Looked at using eval() but found this: Kepp the following Quote in mind: If eval() is the answer, you're almost certainly asking the wrong question. -- Rasmus Lerdorf, BDFL of PHP indeed eval is probably not the answer. (Hmmm...) Any help much appreciated. Tom -- Tom Chubb [EMAIL PROTECTED] 07915 053312 -- 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] Sorting multidimensional arrays
Result. Cheers! On 11/16/06, Robert Cummings [EMAIL PROTECTED] wrote: On Thu, 2006-11-16 at 15:28 +, Dave Goodchild wrote: Hi all. I have a multidimensional array here: Bums [name]= string(13) Tits And Bums [3]= string(19) The Pleasure [--SNIP--] ...which comprises a set of returned results for an events search - with the date computed dynamically and added to the end of the array in each case. What I want to do with this data is display the array in an html table, sorted by the date. At the moment the display shows each event from earliest to last date, then the next event from earliest to last etc. What I want to do is display all the data from earliest to last date - my question is, how do I sort the entire array based on the date value in the second level array? usort() Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- http://www.web-buddha.co.uk
[PHP] Re: PHP 5.2.0 Session Handling Bug? Can someone test this please?
Colin Guthrie wrote: Hi, I've noticed a bug with PHP 5.2.0 when dealing with sessions and posting quite large forms. I've attached a file that highlights the bug. Can people test this please and if it is confirmed i'll post upsteam. Just want to rule out my distro's packaging being at fault I am using the suochsim, soouishm, soushim ach the security patch thing, so that may be what is at fault here. Anyway, I don't think the data itself is to blame but I didn't fiddle too much with it as I didn't see the point. I've tested this on PHP 5.1.6 and it is not affected. I should also say that I'm 64-bit everything if that makes a difference. If other people do NOT get this bug, I'd appreciate it if they could say their arch too (also if it's windoze/osx etc.). I'm using Mandriva Cooker FWIW (and no this is not a production box... wouldn't run Cooker on that!!) Col. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] file_get_contents
Confused! I'm now getting: file_get_contents(http://www.tnhosting.co.uk/scripts/gclub/player.php) [function.file-get-contents]: failed to open stream: Connection refused in /home/sites/tnhosting.co.uk/public_html/scripts/gclub/updateplaylist.php on line 75 How come you can access it and I can't?!? Permissions are 755. Obviously I was getting it when using file_get_contents('player.php') but when using the URL I get connection refused. (Don't think that it makes any difference, but allow_url_fopen is on) BTW, Brad, I was stripping the HTML tags around the object ok, but I'm echoing variables in player.php. $song_url $song_title, are read from a seperate file after upload and that is what's being updated by this script, but the textarea was showing the php code. Thanks for your patience, guys. T On 16/11/06, Jochem Maas [EMAIL PROTECTED] wrote: Tom Chubb wrote: Thanks Jochem, Tried that, but it's still showing php code in the text area! Any other ideas? vanilla sky (go search for the tagline) ... if I request the following I get a page with a player into: http://www.tnhosting.co.uk/scripts/gclub/player.php if you do the following you will get the same html source as my browser does - if it doesn't then you are doing something wrong - quite simply php is transparently making a http request to the webserver there is no way the webserver will differentiate between your script and every other request and give your the scrip the source code while everyone else is recieving the result of running the script: file_get_contents(http://www.tnhosting.co.uk/scripts/gclub/player.php;); below is the oneliner I used to prove this: php -r 'echo file_get_contents(http://www.tnhosting.co.uk/scripts/gclub/player.php;);' OUTPUT: (oh look no php) == html head titleTest Audio Player/title meta http-equiv=Content-Type content=text/html; charset=iso-8859-1 meta http-equiv=Expires content=Mon, 26 Jul 1997 05:00:00 GMT/ meta http-equiv=Pragma content=no-cache / /head body !-- Start Player Code -- !-- Contact [EMAIL PROTECTED] if you have any problems -- object classid=clsid:d27cdb6e-ae6d-11cf-96b8-44455354 codebase=http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0; width=400 height=15 param name=allowScriptAccess value=sameDomain/ param name=movie value=http://www.tnhosting.co.uk/scripts/gclub/xspf_player_slim.swf?song_url= http://www.tnhosting.co.uk/scripts/gclub/audio/faith.mp3song_title=Another Stomping Funker!autoplay=true / param name=quality value=high/ param name=bgcolor value=#E6E6E6/ embed src=http://www.tnhosting.co.uk/scripts/gclub/xspf_player_slim.swf?song_url= http://www.tnhosting.co.uk/scripts/gclub/audio/faith.mp3song_title=Another Stomping Funker!autoplay=true width=400 height=15 align=center quality=high bgcolor=#E6E6E6 allowscriptaccess=sameDomain type=application/x-shockwave-flash pluginspage=http://www.macromedia.com/go/getflashplayer; /embed /object !-- End Player Code -- /body /html The url is http://www.tnhosting.co.uk/scripts/gclub/updateplaylist.php and you see it on submission. Feel free to post. It's a testing server. On 16/11/06, Jochem Maas [EMAIL PROTECTED] wrote: Tom Chubb wrote: I am trying to read the contents of a PHP page for an audio player and put it into a textarea to be copied and pasted into an HTML page. The trouble is the textarea shows unparsed PHP code and I just want the HTML. The code is: $player = file_get_contents('player.php'); file_get_content('http://blabla.com/player.php'); // requires allow_url_fopen to be set to On. //Strip out unnecessary HTML Code if(preg_match('/!-- Start Player Code --(.*)!-- End Player Code --/s', $player, $matches)) { $code = $matches[1]; } echo textarea name=\textarea\ cols=\70\ rows=\15\ . $code . htmlentities($code) /textarea; echo BR; echo a href=\player.php\Click Here/a to view the player \n; Looked at using eval() but found this: Kepp the following Quote in mind: If eval() is the answer, you're almost certainly asking the wrong question. -- Rasmus Lerdorf, BDFL of PHP indeed eval is probably not the answer. (Hmmm...) Any help much appreciated. Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP 5.2.0 Session Handling Bug? Can someone test this please?
The ID never changed for me. PHP 5.2.0 Apache 1.3.33 Mac OS X 10.4.8 On Nov 16, 2006, at 9:28 AM, Colin Guthrie wrote: I've noticed a bug with PHP 5.2.0 when dealing with sessions and posting quite large forms. I've attached a file that highlights the bug. Can people test this please and if it is confirmed i'll post upsteam. Just want to rule out my distro's packaging being at fault I am using the suochsim, soouishm, soushim ach the security patch thing, so that may be what is at fault here. Anyway, I don't think the data itself is to blame but I didn't fiddle too much with it as I didn't see the point. I've tested this on PHP 5.1.6 and it is not affected. Thanks. Col. bug.php Frank Schima Foraker Design http://www.foraker.com 303-449-0202
RE: [PHP] Re: PHP 5.2.0 Session Handling Bug? Can someone test this please?
Have you checked your error_log? I've had this problem when the wrong permissions were set on /var/lib/php/session which meant PHP couldn't write it's session files and hence generated a new ID each time. The error_log will tell you if this is the case. Edward Colin Guthrie wrote: Hi, I've noticed a bug with PHP 5.2.0 when dealing with sessions and posting quite large forms. I've attached a file that highlights the bug. Can people test this please and if it is confirmed i'll post upsteam. Just want to rule out my distro's packaging being at fault I am using the suochsim, soouishm, soushim ach the security patch thing, so that may be what is at fault here. Anyway, I don't think the data itself is to blame but I didn't fiddle too much with it as I didn't see the point. I've tested this on PHP 5.1.6 and it is not affected. I should also say that I'm 64-bit everything if that makes a difference. If other people do NOT get this bug, I'd appreciate it if they could say their arch too (also if it's windoze/osx etc.). I'm using Mandriva Cooker FWIW (and no this is not a production box... wouldn't run Cooker on that!!) Col. -- 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] Re: PHP 5.2.0 Session Handling Bug? Can someone test this please?
Frank J. Schima wrote: The ID never changed for me. PHP 5.2.0 Apache 1.3.33 Mac OS X 10.4.8 Cheers mate. I guess that could mean its: * Apache 2 thing * x86_64 thing * suhosin thing * mandriva thing More tests to narrow those down would be appreciated if anyone has appropriate installs to hand. Col. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: PHP 5.2.0 Session Handling Bug? Can someone test this please?
Edward Kay wrote: Have you checked your error_log? I've had this problem when the wrong permissions were set on /var/lib/php/session which meant PHP couldn't write it's session files and hence generated a new ID each time. The error_log will tell you if this is the case. No, but the problem doesn't exhibit those characteristics. Sessions work generally, and I can log in to my application and do certain things that require a working session etc. It's only when I used a page that posts a large amount of data that the problem is apparent. I've tried it with overridden session handling functions that store session in a db too with the same results. In my test here, you can do a GET request several times and get the same id, it's only when you do the POST request that the bug is presented (at least for me). Cheers for the suggestion tho'. Col. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP 5.2.0 Session Handling Bug? Can someone test this please?
Colin Guthrie-6 wrote: Hi, I've noticed a bug with PHP 5.2.0 when dealing with sessions and posting quite large forms. I've attached a file that highlights the bug. Can people test this please and if it is confirmed i'll post upsteam. Just want to rule out my distro's packaging being at fault I am using the suochsim, soouishm, soushim ach the security patch thing, so that may be what is at fault here. Anyway, I don't think the data itself is to blame but I didn't fiddle too much with it as I didn't see the point. I've tested this on PHP 5.1.6 and it is not affected. Thanks. Col. as you mentioned using hardened php: maybe you have to adjust hphp.post.max_value_length = and/or some other settings -- View this message in context: http://www.nabble.com/PHP-5.2.0-Session-Handling-Bug--Can-someone-test-this-please--tf2644202.html#a7382877 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] Re: [RESOLVED] PHP 5.2.0 Session Handling Bug? Can someone test this please?
Jürgen Wind wrote: as you mentioned using hardened php: maybe you have to adjust hphp.post.max_value_length = and/or some other settings Thanks to Mr Oden Eriksson @ Mandriva, he pointed out that I needed to up the value for suhosin.request.max_vars from the default of 200. So you were very much on the right track. Thanks for everyone's testing and sorry for the nonsense! Col. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Excel problem
Hello all, Am pretty new to the world of PHP. And am now stuck. Its like i am displayin the data from a database on to my webpage in the form of tables. but now i also want an option for the user to download the above data into an excel format for the offline use. I dont want to create the excel file for each of the webpage i am displaying as they are all dynamic so there can be many. is there a way so that only if user click the given link at the bottm of the page then only the data is transferred to excel. i.e how to i write the displayed data dynamically to the excel without storing anything on the server. I am able to config the pear:excelwriter but dont know hwo to get it working according to my requirements. please advice. thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Excel problem
[snip] please advice. [/snip] Have you read the documentation? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Excel problem
?php $query = SELECT ; $result = mysql_query($query); header (Content-Type: application/octet-stream); header (Content-Disposition: attachment; filename=whatever.xls); echo Field1\tField2\r\n; // Column names while($row = mysql_fetch_array($result)) { echo $row['field1'] . \t . $row['field2']. \r\n; // Data } ? You could also name the file *.csv and use a comma as a delimiter instead. Don't forget to put quotes around any data that may have tab characters in it. (Or commas if you're using csv) Hope that helps -B -Original Message- From: amit hetawal [mailto:[EMAIL PROTECTED] Sent: Thursday, November 16, 2006 2:26 PM To: php-general@lists.php.net Subject: [PHP] Excel problem Hello all, Am pretty new to the world of PHP. And am now stuck. Its like i am displayin the data from a database on to my webpage in the form of tables. but now i also want an option for the user to download the above data into an excel format for the offline use. I dont want to create the excel file for each of the webpage i am displaying as they are all dynamic so there can be many. is there a way so that only if user click the given link at the bottm of the page then only the data is transferred to excel. i.e how to i write the displayed data dynamically to the excel without storing anything on the server. I am able to config the pear:excelwriter but dont know hwo to get it working according to my requirements. please advice. thanks -- 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] Excel problem
hello, Yes i have gone through the documentation. bu ti can find a way to link the download excel thing with the link which says donwload in excel. Is it that i have to fetch the data 2 times , one for displayin it in table and the other time downloadin in excel Any suggestions Thanks On 11/16/06, Jay Blanchard [EMAIL PROTECTED] wrote: [snip] please advice. [/snip] Have you read the documentation? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Smart Quotes not so smart
Larry Garfield wrote: I've run into this sort of issue a few times before, and never found a good solution. Not sure if this is the solution you're looking for, but you can convert them to regular quotes: http://shiflett.org/archive/165 Hope that helps. Chris -- Chris Shiflett http://shiflett.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Looping through array
Say I have an array containing ten items, and I want to display them in a table as follows: 5 4 3 2 1 10 9 8 7 6 What's the best way to loop through that array to do that? My thinking gets me to create a loop for 5 through 1, repeated twice, and the second time I add '5' to the index value. There's got to be a saner way... -- W | It's not a bug - it's an undocumented feature. + Ashley M. Kirchner mailto:[EMAIL PROTECTED] . 303.442.6410 x130 IT Director / SysAdmin / Websmith . 800.441.3873 x130 Photo Craft Imaging . 3550 Arapahoe Ave. #6 http://www.pcraft.com . . .. Boulder, CO 80303, U.S.A. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Looping through array
Ashley M. Kirchner wrote: Say I have an array containing ten items, and I want to display them in a table as follows: 5 4 3 2 1 10 9 8 7 6 What's the best way to loop through that array to do that? My thinking gets me to create a loop for 5 through 1, repeated twice, and the second time I add '5' to the index value. There's got to be a saner way... Something like this perhaps... $arr = array(...); $per_row = 5; $elem = count($arr); for($i=0; $i$elem; $i++) { if( $i == 0 ) echo tr; if( $i % $per_row == 0 ) echo /trtr; echo td$arr[$i]/td; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Looping through array
Ashley M. Kirchner wrote: Say I have an array containing ten items, and I want to display them in a table as follows: 5 4 3 2 1 10 9 8 7 6 What's the best way to loop through that array to do that? My thinking gets me to create a loop for 5 through 1, repeated twice, and the second time I add '5' to the index value. There's got to be a saner way... Something like this perhaps... $arr = array(...); $per_row = 5; $elem = count($arr); for($i=0; $i$elem; $i++) { if( $i == 0 ) echo tr; else if( $i % $per_row == 0 ) echo /trtr; echo td$arr[$i]/td; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Looping through array
?php $arr = array(5, 4, 3, 2, 1, 10, 9, 8, 7, 6,); echo 'table border=1'; echo 'tr'; for ($x=0,$y=sizeof($arr); $x$y; ++$x) { echo td{$arr[$x]}/td; if ($x == 4) { echo '/trtr'; } } echo '/tr'; echo '/table'; ? On Nov 16, 2006, at 1:19 PM, Ashley M. Kirchner wrote: Say I have an array containing ten items, and I want to display them in a table as follows: 5 4 3 2 1 10 9 8 7 6 What's the best way to loop through that array to do that? My thinking gets me to create a loop for 5 through 1, repeated twice, and the second time I add '5' to the index value. There's got to be a saner way... -- W | It's not a bug - it's an undocumented feature. + Ashley M. Kirchner mailto:[EMAIL PROTECTED] . 303.442.6410 x130 IT Director / SysAdmin / Websmith . 800.441.3873 x130 Photo Craft Imaging . 3550 Arapahoe Ave. #6 http://www.pcraft.com . . .. Boulder, CO 80303, U.S.A. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Darrell Brogdon [EMAIL PROTECTED] http://darrell.brogdon.net * ** Prepare for PHP Certication!** ** http://phpflashcards.com** *
Re: [PHP] Looping through array
Brad Bonkoski wrote: Something like this perhaps... $arr = array(...); $per_row = 5; $elem = count($arr); for($i=0; $i$elem; $i++) { if( $i == 0 ) echo tr; else if( $i % $per_row == 0 ) echo /trtr; echo td$arr[$i]/td; } That simply displays things in order, 1 through 5, then 6 through 10. -- W | It's not a bug - it's an undocumented feature. + Ashley M. Kirchner mailto:[EMAIL PROTECTED] . 303.442.6410 x130 IT Director / SysAdmin / Websmith . 800.441.3873 x130 Photo Craft Imaging . 3550 Arapahoe Ave. #6 http://www.pcraft.com . . .. Boulder, CO 80303, U.S.A. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Looping through array
If you know the array elements, you may not need to loop. Why not just echo the particular array elements i.e. td?php echo $array[2]; ?/td for example?
Re: [PHP] Looping through array
$arr = array(...); $first_row = ''; $second_row = ''; for ($i=4; $i=0; $i--){ $first_row = $first_row . td{$arr[$x]}/td; $second_row = $second_row . td{$arr[$x + 5]}/td; } print 'tr' . $first_row . '/tr'; print 'tr' . $second_row . '/tr'; On Nov 16, 2006, at 3:19 PM, Ashley M. Kirchner wrote: Say I have an array containing ten items, and I want to display them in a table as follows: 5 4 3 2 1 10 9 8 7 6 What's the best way to loop through that array to do that? My thinking gets me to create a loop for 5 through 1, repeated twice, and the second time I add '5' to the index value. There's got to be a saner way... -- W | It's not a bug - it's an undocumented feature. + Ashley M. Kirchner mailto:[EMAIL PROTECTED] . 303.442.6410 x130 IT Director / SysAdmin / Websmith . 800.441.3873 x130 Photo Craft Imaging . 3550 Arapahoe Ave. #6 http://www.pcraft.com . . .. Boulder, CO 80303, U.S.A. -- 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] Looping through array
So in other words, you have an array like $arr = array (1,2,3,4,5,6,7,8,9,10) but you want it to render on the page as: 5 4 3 2 1 10 9 8 7 6 right? -D On Nov 16, 2006, at 1:35 PM, Ashley M. Kirchner wrote: Darrell Brogdon wrote: $arr = array(5, 4, 3, 2, 1, 10, 9, 8, 7, 6,); The array is in order, from 1 to 10. It was populated that way. -- W | It's not a bug - it's an undocumented feature. + Ashley M. Kirchner mailto:[EMAIL PROTECTED] . 303.442.6410 x130 IT Director / SysAdmin / Websmith . 800.441.3873 x130 Photo Craft Imaging . 3550 Arapahoe Ave. #6 http://www.pcraft.com . . .. Boulder, CO 80303, U.S.A. Darrell Brogdon [EMAIL PROTECTED] http://darrell.brogdon.net * ** Prepare for PHP Certication!** ** http://phpflashcards.com** *
[PHP] Space in regex
I'm trying to match alphanumeric characters, some common symbols, and spaces. Why does this NOT match strings containing spaces?: [A-Za-z0-9\'.-:underscore::space:] I've also tried these, that also fail to match strings containing spaces: [A-Za-z0-9\'.- :underscore:] [A-Z a-z0-9\'.-:underscore:] [:space:A-Za-z0-9\'.-:underscore:] All these regexes match strings containing the specified characters, but none of them match strings with spaces. Dotan Cohen http://what-is-what.com/ http://technology-sleuth.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Looping through array
Darrell Brogdon wrote: So in other words, you have an array like $arr = array(1,2,3,4,5,6,7,8,9,10) but you want it to render on the page as: 5 4 3 2 1 10 9 8 7 6 right? That would be correct. James Tu provided a solution that I think will work. I'm always open to other suggestions of course. -- W | It's not a bug - it's an undocumented feature. + Ashley M. Kirchner mailto:[EMAIL PROTECTED] . 303.442.6410 x130 IT Director / SysAdmin / Websmith . 800.441.3873 x130 Photo Craft Imaging . 3550 Arapahoe Ave. #6 http://www.pcraft.com . . .. Boulder, CO 80303, U.S.A. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Looping through array
At 1:19 PM -0700 11/16/06, Ashley M. Kirchner wrote: Say I have an array containing ten items, and I want to display them in a table as follows: 5 4 3 2 1 10 9 8 7 6 What's the best way to loop through that array to do that? My thinking gets me to create a loop for 5 through 1, repeated twice, and the second time I add '5' to the index value. There's got to be a saner way... Ashley: Look into array_chunk() and array_flip(). The first can break your main array into two and the second can reverse the results. 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] Re: Space in regex
On 16/11/06, Dotan Cohen [EMAIL PROTECTED] wrote: I'm trying to match alphanumeric characters, some common symbols, and spaces. Why does this NOT match strings containing spaces?: [A-Za-z0-9\'.-:underscore::space:] I've also tried these, that also fail to match strings containing spaces: [A-Za-z0-9\'.- :underscore:] [A-Z a-z0-9\'.-:underscore:] [:space:A-Za-z0-9\'.-:underscore:] All these regexes match strings containing the specified characters, but none of them match strings with spaces. Dotan Cohen http://what-is-what.com/ http://technology-sleuth.com/ I should add more information. This is the entire regex: $text=preg_replace_callback('/\[([A-Za-z0-9\'.-:underscore:]+)\|([A-Za-z0-9\'. -:underscore:]+)\]/i' , findLinks, $text); This regex should match any pair of square brackets, with two bits of text between them seperated by a pipe, like these: [Ety|wife] [Jarred|brother] [Ahmed|neighbor] [Gili and Gush|pets] [Bill Clinton|horny] I would expect that the . would match spaces, but it doesn't. So the first three examples that I've shown are matched, but the last two are not. I've even added \w, \s, , and :space: to the regex, but of course that's not matching, either. What am I doing wrong? Note that I've been honing my regex skills for the past few days, but I've not so much experience with them. Thanks in advance to whoever can help me understand this. Dotan Cohen http://lyricslist.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Looping through array
At 11/16/2006 12:19 PM, Ashley M. Kirchner wrote: Say I have an array containing ten items, and I want to display them in a table as follows: 5 4 3 2 1 10 9 8 7 6 What's the best way to loop through that array to do that? My thinking gets me to create a loop for 5 through 1, repeated twice, and the second time I add '5' to the index value. There's got to be a saner way... In order to figure out the best PHP logic to generate the series, I'd first make sure the markup is solid. I realize that you've already indicated a table markup in two rows, but I'd like to examine that. Can you tell us why the numbers are in this particular sequence? Do the numbers represent items that are conceptually in ascending order but are presented in reverse order on the screen? If so, I'd wonder whether someone reading the page with assistive technology might be confused by the reverse order, and I'd try to find a way to mark them up ascending and then change the sequence stylistically. Are they split into two rows because they represent two discrete groups in the data set or because of display considerations? If the latter, I'd argue that they don't really belong in two table rows; that using tables to force presentation is misapplying the tool. Have you considered an unordered list, floated right, wrapped in a container whose width naturally forces a wrap after the fifth item? I like that solution because it allows you to mark up the numbers in sequence and in future change the number of items in the sequence and/or change the way the series is presented visually without having to mess with the logic generating the markup. Regards, Paul -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Space in regex
I ran this expression through Regex Coach: \[([A-Za-z0-9\'.-:underscore:\s]+)\|([A-Za-z0-9\'. -:underscore:]+)\] ...and it matched the patterns your describe.
Re: [PHP] Re: Space in regex
Dotan Cohen wrote: I should add more information. This is the entire regex: $text=preg_replace_callback('/\[([A-Za-z0-9\'.-:underscore:]+)\|([A-Za-z0-9\'. -:underscore:]+)\]/i' , findLinks, $text); This regex should match any pair of square brackets, with two bits of text between them seperated by a pipe, like these: [Ety|wife] [Jarred|brother] [Ahmed|neighbor] [Gili and Gush|pets] [Bill Clinton|horny] I would expect that the . would match spaces, but it doesn't. So the first three examples that I've shown are matched, but the last two are not. I've even added \w, \s, , and :space: to the regex, but of course that's not matching, either. What am I doing wrong? Note that I've been honing my regex skills for the past few days, but I've not so much experience with them. Thanks in advance to whoever can help me understand this. This appears to work for me: preg_match('/\[([A-Za-z0-9\s\'.-:underscore:]+)\|([A-Za-z0-9\s\'.-:underscore:]+)\]/i','[Test 1|Test 2]',$matches); print_r($matches); produces: Array ( [0] = [Test 1|Test 2] [1] = Test1 [2] = Test2 ) Alternately, I would use the following regex: /\[([^\|]+)\|([^\|]+)\]/ which is a little cryptic, but very flexible for what you mention above. It works for me as well... jon -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Space in regex
At 11/16/2006 01:56 PM, Dotan Cohen wrote: $text=preg_replace_callback('/\[([A-Za-z0-9\'.-:underscore:]+)\|([A-Za-z0-9\'. -:underscore:]+)\]/i' , findLinks, $text); This regex should match any pair of square brackets, with two bits of text between them seperated by a pipe, like these: [Ety|wife] [Jarred|brother] [Ahmed|neighbor] [Gili and Gush|pets] [Bill Clinton|horny] I would expect that the . would match spaces, but it doesn't. So the first three examples that I've shown are matched, but the last two are not. I've even added \w, \s, , and :space: to the regex, but of course that's not matching, either. What am I doing wrong? Note that I've been honing my regex skills for the past few days, but I've not so much experience with them. Thanks in advance to whoever can help me understand this. Dotan, I'm surmising what you really want to do is grab all the characters between [ and | for the first field, and everything from | to ] as the second field. I would therefore identify the first field with: [^\]|] anything except the close-bracket and the vertical pipe and the second field with: [^\]] anything except the close-bracket Therefore: /\[([^\]|]+)\|([^\]]+)\]/ Regards, Paul -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Excel problem
On Thursday 16 November 2006 21:25, amit hetawal wrote: Hello all, Am pretty new to the world of PHP. And am now stuck. Its like i am displayin the data from a database on to my webpage in the form of tables. but now i also want an option for the user to download the above data into an excel format for the offline use. I dont want to create the excel file for each of the webpage i am displaying as they are all dynamic so there can be many. is there a way so that only if user click the given link at the bottm of the page then only the data is transferred to excel. i.e how to i write the displayed data dynamically to the excel without storing anything on the server. I am able to config the pear:excelwriter but dont know hwo to get it working according to my requirements. please advice. thanks Hi maybe 5 years ago I had same kind of problem. I solve this way.. Excel 2000 has able to save excel document as web page. I generate a excell page and format it. Then I save it html. It was MS xml format. After then that. I use my excel xml file as template for my datas. When user click the link php connects to mysql then create ms xml formatted values then combine with excell xml file. If correct dll's are loaded, an excell sheet will show in IE. It behaves like excel. Also you can easly save it excel file. Regards Sancar -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Space in regex
On 17/11/06, Paul Novitski [EMAIL PROTECTED] wrote: Dotan, I'm surmising what you really want to do is grab all the characters between [ and | for the first field, and everything from | to ] as the second field. I would therefore identify the first field with: [^\]|] anything except the close-bracket and the vertical pipe and the second field with: [^\]] anything except the close-bracket Therefore: /\[([^\]|]+)\|([^\]]+)\]/ Regards, Paul Thanks, Paul. I've been refining my methods, and I think it's better (for me) to just match everything between [ and ], including spaces, underscores, apostrophies, and pipes. I'll explode on the pipe inside the function. So I thought that a simple /\[([.]+)\]/i should do it. This is the line: $text=preg_replace_callback('/\[([.]+)\]/i' , findLinks, $text); This is what it is doing: 1) on [~~] where ~~ does not include spaces nor pipes: The function replaces [~~] with . 2) on [~~] where ~~ includes a pipe, but no space: The function does not replace anything. 3) on [~~] where ~~ includes a space, but no pipe: The function does not do what I intend it to do, and I am unable to figure out exactly what it is doing. 3) on [~~] where ~~ includes a space and a pipe: The function does not replace anything. However, this function: $text=preg_replace_callback('/\[([A-Za-z0-9\|\'.-:underscore:]+)\]/i' , findLinks, $text); Does what I want it to when there is no space, regardless of whether or not there is a pipe. It does not replace anything if there is a space. Dotan Cohen http://what-is-what.com/ http://gmail-com.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Splitting a string
On Thursday 16 November 2006 01:12, Robert Cummings wrote: On Thu, 2006-11-16 at 10:47 +1100, Chris wrote: Børge Holen wrote: Oh this was good. I added a while loop to insert extra strings 0 in front of the number to add if the string is less than 5 chars short. sprintf is your friend here, no need to use a loop. sprintf('%05d', '1234'); No need to use a sledgehammer when a screwdriver will suffice: ?php echo str_pad( '1234', 5, '0', STR_PAD_LEFT ) Yes this is perfect. Thanks... I repeat this step for about a few hundred values. So this speedup is greatly appreciated. ? Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | | :: : | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- --- Børge Kennel Arivene http://www.arivene.net --- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Splitting a string
On Thursday 16 November 2006 01:38, Paul Novitski wrote: At 11/15/2006 02:06 PM, Børge Holen wrote: Oh this was good. I added a while loop to insert extra strings 0 in front of the number to add if the string is less than 5 chars short. I forgot to mentinon that the string actually could be shorter (just found out) and the code didn't work with fewer than 5 char strings. But now is rocks. Hey Børge, If you need to left-pad with zeroes, PHP comes to the rescue: http://php.net/str_pad However, if you're using the regular expression method then you might not need to pad the number. You can change the pattern from this: /(\d+)(\d{2})(\d{2})$/' to this: /(\d*)(\d{2})(\d{2})$/' so it won't require any digits before the final two pairs. * 0 or more quantifier + 1 or more quantifier http://ca.php.net/manual/en/reference.pcre.pattern.syntax.php Paul Cool solution, and it works. =D I do however need some chars to fill in on the finished product for the look of it all, so the 0 is needed... Witch is a bit of a shame with this cool string. -- --- Børge Kennel Arivene http://www.arivene.net --- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Splitting a string
On Thursday 16 November 2006 01:38, Paul Novitski wrote: If you need to left-pad with zeroes, PHP comes to the rescue: http://php.net/str_pad However, if you're using the regular expression method then you might not need to pad the number. You can change the pattern from this: /(\d+)(\d{2})(\d{2})$/' to this: /(\d*)(\d{2})(\d{2})$/' At 11/16/2006 03:23 PM, Børge Holen wrote: Cool solution, and it works. =D I do however need some chars to fill in on the finished product for the look of it all, so the 0 is needed... Witch is a bit of a shame with this cool string. Well, just to make sure you don't discard regexp unnecessarily... // the pattern guarantees five digits, then two, then two: $sPattern = '/(\d{5})(\d{2})(\d{2})$/'; // prepend 9 zeroes to the number to enforce the minimum requirements: preg_match($sPattern, '0' . $iNumber, $aMatches); Results: $iNumber = ''; $aMatches: ( [0] = 0 [1] = 0 [2] = 00 [3] = 00 ) $iNumber = '123'; $aMatches: ( [0] = 00123 [1] = 0 [2] = 01 [3] = 23 ) $iNumber = '12345'; $aMatches: ( [0] = 12345 [1] = 1 [2] = 23 [3] = 45 ) $iNumber = '123456789'; $aMatches: ( [0] = 123456789 [1] = 12345 [2] = 67 [3] = 89 ) Paul -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Space in regex
The underscore plus alphanumeric are included in \w, so to get a regex such as you want: [\w\s\.\-\']+ You should escape the dot because the unescaped dot stands for any single character, which is why .* stands for any and all characters. Dotan Cohen wrote: I'm trying to match alphanumeric characters, some common symbols, and spaces. Why does this NOT match strings containing spaces?: [A-Za-z0-9\'.-:underscore::space:] I've also tried these, that also fail to match strings containing spaces: [A-Za-z0-9\'.- :underscore:] [A-Z a-z0-9\'.-:underscore:] [:space:A-Za-z0-9\'.-:underscore:] All these regexes match strings containing the specified characters, but none of them match strings with spaces. Dotan Cohen http://what-is-what.com/ http://technology-sleuth.com/ -- _ Myron Turner http://www.room535.org http://www.bstatzero.org http://www.mturner.org/XML_PullParser/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Space in regex
The \w regex includes all alphanumeric characters plus the underscore, i.e. all valid characters that make up a C identifier. So what you want can be expressed as follows: [\w\s\.\-]+ You have to escape the dot because in a regular espression it represents any single character, which is why .* represents all characters. Myron Turner http://www.mturner.org/XML_PullParser/ On Thu, 16 Nov 2006 23:08:34 +0200, [EMAIL PROTECTED] (Dotan Cohen) wrote: I'm trying to match alphanumeric characters, some common symbols, and spaces. Why does this NOT match strings containing spaces?: [A-Za-z0-9\'.-:underscore::space:] I've also tried these, that also fail to match strings containing spaces: [A-Za-z0-9\'.- :underscore:] [A-Z a-z0-9\'.-:underscore:] [:space:A-Za-z0-9\'.-:underscore:] All these regexes match strings containing the specified characters, but none of them match strings with spaces. Dotan Cohen http://what-is-what.com/ http://technology-sleuth.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Space in regex
At 11/16/2006 08:46 PM, Myron Turner wrote: The underscore plus alphanumeric are included in \w, so to get a regex such as you want: [\w\s\.\-\']+ You should escape the dot because the unescaped dot stands for any single character, which is why .* stands for any and all characters. Not actually. Inside a character class, a dot is just a period. You may escape it (or any other character) but you don't need to. To quote the manual: __ Meta-characters ... In a character class the only meta-characters are: \ general escape character ^ negate the class, but only if the first character - indicates character range ] terminates the character class ... Square brackets ... A closing square bracket on its own is not special. If a closing square bracket is required as a member of the class, it should be the first data character in the class (after an initial circumflex, if present) or escaped with a backslash. ... All non-alphanumeric characters other than \, -, ^ (at the start) and the terminating ] are non-special in character classes, but it does no harm if they are escaped. __ http://ca.php.net/manual/en/reference.pcre.pattern.syntax.php Regards, Paul -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Dynamic Year Drop Down
I want to build a select drop down that includes last year, the current year and 3 years into the future. Obviously, I could easily hard code this or use a combination of the date and mktime functions to populate the select. However, I'm looking for a more elegant way of doing this. Thanks for pointing me in the right direction. Al Padley -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Dynamic Year Drop Down
Quite simple: $this_year = date('Y'); for ($i= $this_year-1; $i $this_year+3; ++$i) { print option value='$i' . ($i==$this_year ? selected='selected' : '') . $i/option\n; } Obviously modify for however you're doing output. (Note that you DO want to have the redundant value attribute in there, otherwise some Javascript things don't work right in IE. Good habit to get into.) I don't think it can really get more simple and elegant. On Thursday 16 November 2006 23:26, Albert Padley wrote: I want to build a select drop down that includes last year, the current year and 3 years into the future. Obviously, I could easily hard code this or use a combination of the date and mktime functions to populate the select. However, I'm looking for a more elegant way of doing this. Thanks for pointing me in the right direction. Al Padley -- Larry Garfield AIM: LOLG42 [EMAIL PROTECTED] ICQ: 6817012 If nature has made any one thing less susceptible than all others of exclusive property, it is the action of the thinking power called an idea, which an individual may exclusively possess as long as he keeps it to himself; but the moment it is divulged, it forces itself into the possession of every one, and the receiver cannot dispossess himself of it. -- Thomas Jefferson -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Dynamic Year Drop Down
On Nov 16, 2006, at 11:04 PM, Tom Ray [Lists] wrote: Albert Padley wrote: I want to build a select drop down that includes last year, the current year and 3 years into the future. Obviously, I could easily hard code this or use a combination of the date and mktime functions to populate the select. However, I'm looking for a more elegant way of doing this. Thanks for pointing me in the right direction. This works for me, simple and easy. // Grabs current Year $year=date(Y); // Number of years you want total $yearEnd=$year+10; // Generate Drop Down for($year=$year; $year = $yearEnd; $year++) { print option value=\$year\$year/option; } Thanks. This was close, but it didn't account for the first option being last year. I edited and ended up with this which works. // Grabs current Year $year=date(Y); $yearFirst = $year-1; // Number of years you want total $yearEnd=$year+2; // Generate Drop Down echo select\n; for($year=$yearFirst; $year = $yearEnd; $year++) { print option value=\$year\$year/option; } echo /select\n; Al Padley -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Dynamic Year Drop Down
Thanks, Larry. This was close, but didn't quite work. I played around with the syntax and the following worked great. $this_year = date('Y'); echo select\n; for ($i= $this_year-1; $i $this_year+3; ++$i) { echo option value='$i'; if($i == $this_year) echo selected = 'selected'; echo . $i . /option\n; } echo /select\n; Al Padley On Nov 16, 2006, at 11:32 PM, Larry Garfield wrote: Quite simple: $this_year = date('Y'); for ($i= $this_year-1; $i $this_year+3; ++$i) { print option value='$i' . ($i==$this_year ? selected='selected' : '') . $i/option\n; } Obviously modify for however you're doing output. (Note that you DO want to have the redundant value attribute in there, otherwise some Javascript things don't work right in IE. Good habit to get into.) I don't think it can really get more simple and elegant. On Thursday 16 November 2006 23:26, Albert Padley wrote: I want to build a select drop down that includes last year, the current year and 3 years into the future. Obviously, I could easily hard code this or use a combination of the date and mktime functions to populate the select. However, I'm looking for a more elegant way of doing this. Thanks for pointing me in the right direction. Al Padley -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Space in regex
On 17/11/06, Paul Novitski [EMAIL PROTECTED] wrote: At 11/16/2006 08:46 PM, Myron Turner wrote: The underscore plus alphanumeric are included in \w, so to get a regex such as you want: [\w\s\.\-\']+ You should escape the dot because the unescaped dot stands for any single character, which is why .* stands for any and all characters. Not actually. Inside a character class, a dot is just a period. You may escape it (or any other character) but you don't need to. To quote the manual: __ Meta-characters ... In a character class the only meta-characters are: \ general escape character ^ negate the class, but only if the first character - indicates character range ] terminates the character class ... Square brackets ... A closing square bracket on its own is not special. If a closing square bracket is required as a member of the class, it should be the first data character in the class (after an initial circumflex, if present) or escaped with a backslash. ... All non-alphanumeric characters other than \, -, ^ (at the start) and the terminating ] are non-special in character classes, but it does no harm if they are escaped. __ http://ca.php.net/manual/en/reference.pcre.pattern.syntax.php In any case, none of those solutions work. Try code: ?php $makeLinkPlaceHolder=0; function findLinks ($matches) { global $linkTextArrayPlaceHolder; ++$linkTextArrayPlaceHolder; // Make two peices and fill them with what they should be $matches[0]=str_replace([, , $matches[0] ); $matches[0]=str_replace(], , $matches[0] ); $parts=explode(|, $matches[0]); print br /br /$parts[0] | $parts[1]; $returnString=[.$linkTextArrayPlaceHolder.]; return $returnString; } $text=This is some text. This tag has no spaces and no pipes [TestTag] This tag has no spaces and a pipe [TestTag|AfterPipe] This tag has a space and no pipes [Test Tag] This tag has a space and a pipe [Test Tag|AfterPipe]; // Clean up the text $text=str_replace(\r\n, \n, $text); $text=str_replace(\r, \n, $text); $text=str_replace(\n, br /, $text); print $text; // THIS IS THE PROBLEMATIC CODE $text=preg_replace_callback('/\[([A-Za-z0-9\¦\'.-]+)\]/i' , findLinks, $text); print br /br /.$text; ? Dotan Cohen http://lyricslist.com/ http://what-is-what.com/
[PHP] odd behavior of stripos() with === operator
HEllo all, After pulling my hair out for several hours trying to figure out why my code wasn't working I built this little test and ran it, the results are interesting in the least, and to me, surprising. It is possible that I have done something wrong, but I checked and rechecked this in the documentation. It appears there is either a problem with the === operator (or my brain...) If you don't mind, I'd like to see what you all think. I am running php 5.2.0 on a linux redhat 9 box with Apache 2.2 (the php 5.2.0 install is brand new, perhaps I set it up wrong?) anyway here is the code I wrote, and the output from it... $found = stripos(abcdefg, abcdefg); echo found = stripos(\abcdefg\, \abcdefg\);\n echo The value of found is = : $found\n // 1a) --- needle was found in haystack THIS SHOULD BE if ( $found !== FALSE ) { echo found does not equal FALSE\n } // 1b) --- needle was found in haystack THIS SHOULD ALSO BE if ($found === TRUE ) { echo found is equal to TRUE\n } //1c) --- needle was NOT found in haystack THIS SHOULD NOT BE if ( $found === FALSE ) { echo found is equal to FALSE\n } //1d) --- needle was NOT found in haystack THIS ALSO SHOULD NOT BE if ($found !== TRUE ) { echo found does not equal TRUE\n } $found = stripos(abcdefg, tuvwxyz); echo \$found = stripos(\abcdefg\, \tuvwxyz\);br\n echo The value of found is = : $found\n //2a) --- needle was found in haystack THIS SHOULD NOT BE if ( $found !== FALSE ) { echo found does not equal FALSE\n } //2b) --- needle was found in haystack THIS ALSO SHOULD NOT BE if ($found === TRUE ) { echo found is equal to TRUE\n } //2c) --- needle was NOT found in haystack THIS SHOULD BE if ( $found === FALSE ) { echo found is equal to FALSE\n } //2d) --- needle was NOT found in haystack THIS SHOULD ALSO BE if ($found !== TRUE ) { echo found does not equal TRUE\n } the output: $found = stripos(abcdefg, abcdefg); The value of found is = : 0 found does not equal FALSE //this is from section 1a) of the code found does not equal TRUE//this is from section 1d) of the code // I expected the code from 1b) to be executed $found = stripos(abcdefg, tuvwxyz); The value of found is = : found is equal to FALSE //this is from section 2c) of the code found does not equal TRUE//this is from section 2d) of the code I have underlined the output I am interested in... How can the variable $found be both TRUE and FALSE at the same time? Anyone who can provide me some insight on this, please enlighten me. If my code is correct, then this behavior of the === operator is counter-intuitive, it was my understanding that the === and !== operators were supposed to be used with the output of stripos() for just this situation, but === does not appear to recognize that the returned 0 (because the string was found at index 0) ; whereas the !== does recognize this... is === buggy? or am I? heh thoughts? comments? Thanks all, Michael -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Space in regex
At 11/16/2006 03:19 PM, Dotan Cohen wrote: However, this function: $text=preg_replace_callback('/\[([A-Za-z0-9\|\'.-:underscore:]+)\]/i' , findLinks, $text); Does what I want it to when there is no space, regardless of whether or not there is a pipe. It does not replace anything if there is a space. I see your problem -- you're omitting the brackets around your metacharacters. I believe you should be using [:underscore:] not :underscore: -- therefore, /\[([A-Za-z0-9\|\'.-[:underscore:]]+)\]/i I'm not sure why you need those metacharacters, however; I've never had trouble matching literal space and underscore characters, e.g. [ _] Also: - You don't need to escape the vertical pipe. - You don't need to escape the apostrophe. - You do need to escape the hyphen unless you mean it to indicate a range, which I'm sure you don't here. On other regexp points: Thanks, Paul. I've been refining my methods, and I think it's better (for me) to just match everything between [ and ], including spaces, underscores, apostrophies, and pipes. I'll explode on the pipe inside the function. So I thought that a simple /\[([.]+)\]/i should do it. Oops: [.]+ will look for one or more periods. .+ means one or more character of any kind. So you'd want: /\[(.+)\]/i In a case like this where you're not using any alphabetic letters in the pattern, the -i pattern modifier is irrelevant, so I'd drop it: /\[(.+)\]/ Then your problem is that regexp is 'greedy' and will grab as long a matching string as it can. If there's more than one of your link structures in your text, the regexp above will grab everything from the beginning of the first link to the end of the last. That's why I excluded the close-bracket in my pattern: /\[([^]]+)]/ I know [^]] looks funny but the close-bracket doesn't need to be escaped if it's in the first position, which includes the first position after the negating circumflex. I've also omitted the backslash before the final literal close-bracket which doesn't need one because there's no open bracket context for it to be confused with. Regards, Paul -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] odd behavior of stripos() with === operator
On Fri, 2006-11-17 at 00:24 -0700, Michael wrote: HEllo all, After pulling my hair out for several hours trying to figure out why my code wasn't working I built this little test and ran it, the results are interesting in the least, and to me, surprising. It is possible that I have done something wrong, but I checked and rechecked this in the documentation. It appears there is either a problem with the === operator (or my brain...) If you don't mind, I'd like to see what you all think. I am running php 5.2.0 on a linux redhat 9 box with Apache 2.2 (the php 5.2.0 install is brand new, perhaps I set it up wrong?) anyway here is the code I wrote, and the output from it... $found = stripos(abcdefg, abcdefg); echo found = stripos(\abcdefg\, \abcdefg\);\n echo The value of found is = : $found\n // 1a) --- needle was found in haystack THIS SHOULD BE if ( $found !== FALSE ) { echo found does not equal FALSE\n } // 1b) --- needle was found in haystack THIS SHOULD ALSO BE if ($found === TRUE ) { echo found is equal to TRUE\n } //1c) --- needle was NOT found in haystack THIS SHOULD NOT BE if ( $found === FALSE ) { echo found is equal to FALSE\n } //1d) --- needle was NOT found in haystack THIS ALSO SHOULD NOT BE if ($found !== TRUE ) { echo found does not equal TRUE\n } $found = stripos(abcdefg, tuvwxyz); echo \$found = stripos(\abcdefg\, \tuvwxyz\);br\n echo The value of found is = : $found\n //2a) --- needle was found in haystack THIS SHOULD NOT BE if ( $found !== FALSE ) { echo found does not equal FALSE\n } //2b) --- needle was found in haystack THIS ALSO SHOULD NOT BE if ($found === TRUE ) { echo found is equal to TRUE\n } //2c) --- needle was NOT found in haystack THIS SHOULD BE if ( $found === FALSE ) { echo found is equal to FALSE\n } //2d) --- needle was NOT found in haystack THIS SHOULD ALSO BE if ($found !== TRUE ) { echo found does not equal TRUE\n } the output: $found = stripos(abcdefg, abcdefg); The value of found is = : 0 found does not equal FALSE //this is from section 1a) of the code found does not equal TRUE//this is from section 1d) of the code // I expected the code from 1b) to be executed $found = stripos(abcdefg, tuvwxyz); The value of found is = : found is equal to FALSE //this is from section 2c) of the code found does not equal TRUE//this is from section 2d) of the code I have underlined the output I am interested in... You did??? Where? How can the variable $found be both TRUE and FALSE at the same time? None of your output above indicates that it is both equal to TRUE and FALSE at the same time. It does indicate that $found does NOT equal TRUE and does NOT equal FALSE at the same time and that is because it returned the integer value 0 which is the location of the string in the haystack. Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] odd behavior of stripos() with === operator
At 12:29 AM 11/17/2006 , you wrote: I have underlined the output I am interested in... You did??? Where? Ok, my bad, I sent the mail as plain text instead of styled :P oops How can the variable $found be both TRUE and FALSE at the same time? None of your output above indicates that it is both equal to TRUE and FALSE at the same time. It does indicate that $found does NOT equal TRUE and does NOT equal FALSE at the same time and that is because it returned the integer value 0 which is the location of the string in the haystack. Ok, picking gnits... I should have said NOT true and NOT false at the same time. As for the return of the integer 0.. The documentation indicates that the === and !== operators take this into account in fact there is a specific example in the manual. My point here is that if !== works , why does === not? thanks for responding. Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php