Re: [PHP] Embedding foreach loops
On Tue, 2009-08-11 at 16:00 -0400, Eddie Drapkin wrote: On Tue, Aug 11, 2009 at 3:56 PM, teddtedd.sperl...@gmail.com wrote: At 12:44 PM -0700 8/11/09, Ben Dunlap wrote: This is probably flame-war tinder, so I'll try to tread more delicately in the future. Next you know we'll be on the ternary operator and which is better, Mac or Windows. ;-) Ben That was won long ago, it's Mac. :-) Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php If by Mac you mean Linux, you're entirely correct. Linux +100 Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Embedding foreach loops
On Tue, 2009-08-11 at 16:23 -0400, Rick Duval wrote: OK, first guys, I'm sorry to have to do this but I can't get off this list!!! I've followed the instructions on a couple of occasions (the ones at the bottom of every email): PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Been There, done that. I can't get off the list!!! I use Gmail and I use an an alias as well, tried them both, still on the list. No reply from Majordomo. Yes, I've check my spam filter for a unsubscribe confirmation (if it sends one which I presume it's supposed to). Headers tell me that this list is php-general@lists.php.net. Sent the unsubscribe emails. No replies. Again. I apologize but have no idea what to do to get off this list! THis is the only list server I can't seem to get off of. Help! On Mon, Aug 10, 2009 at 6:04 PM, John Butlergovinda.webdnat...@gmail.com wrote: I can't seem to get my foreach loops to work, will PHP parse embedded loops? yes. Is this something I need to have in a database to work? no, you can do it with the arrays... but it may be easier to work with over the long run if that data was in a db. Anyway right after you finish creating the array and it's embedded arrays, in your code, then add this: var_dump($shows); //--so you can see what you just created. If it looks right, THEN go on bothering to try and parse it with your (embedded) foreach's { John Butler (Govinda) govinda.webdnat...@gmail.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -This message has been scanned for viruses and dangerous content byAccurate Anti-Spam Technologies. www.AccurateAntiSpam.com Use the unsubscribe email address that's in the header (this is very different from the footer) of every email from the list. Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Embedding foreach loops
Do *NOT* get into the habit of outputting your HTML using echo or print statements, it becomes unmaintainable very quickly, use a templating language, ether with a framework(recomended) or standalone. You should learn the basics of HTML and CSS, go and read http://htmldog.com/, btw to add a newline you need to use br /. I am using the print function to display my html. I cannot get the line return ( \n ) character to actually push the html onto the next line, it just gets displayed instead. Should I be using echo? Allen, you off and running again? echo blah.. \n; //-- this will print the literal 'blah.. ' and then a newline into your HTML *source code* echo 'blah.. \n'; //-- this will print the literal 'blah.. \n' into your HTML *source code* IIRC print is the same as echo. That is not your apparent issue. Say if you are stuck again, and on what exactly. -John -- 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] Embedding foreach loops
On Tue, 2009-08-11 at 07:13 +, hessi...@hessiess.com wrote: Do *NOT* get into the habit of outputting your HTML using echo or print statements, it becomes unmaintainable very quickly, use a templating language, ether with a framework(recomended) or standalone. You should learn the basics of HTML and CSS, go and read http://htmldog.com/, btw to add a newline you need to use br /. I am using the print function to display my html. I cannot get the line return ( \n ) character to actually push the html onto the next line, it just gets displayed instead. Should I be using echo? Allen, you off and running again? echo blah.. \n; //-- this will print the literal 'blah.. ' and then a newline into your HTML *source code* echo 'blah.. \n'; //-- this will print the literal 'blah.. \n' into your HTML *source code* IIRC print is the same as echo. That is not your apparent issue. Say if you are stuck again, and on what exactly. -John -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php *Or* you could use the heredoc syntax, which I'm quite a fan of. print EOC psome content here/p pcontent with a php $variable here/p pthis gets displayed after the extra new lines in the source/p EOC; Still easy to maintain. Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Embedding foreach loops
On Aug 11, 2009, at 12:13 AM, hessi...@hessiess.com wrote: Do *NOT* get into the habit of outputting your HTML using echo or print statements, it becomes unmaintainable very quickly, use a templating language, ether with a framework(recomended) or standalone. This sounds interesting. Could you expound on this a little more and perhaps list a couple of the templates you mention? Thanks, Frank -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Embedding foreach loops
statements, it becomes unmaintainable very quickly, use a templating language, ether with a framework(recomended) or standalone. But he /is/ using a templating language... PHP. ;-) Ben
Re: [PHP] Embedding foreach loops
Ben Dunlap wrote: statements, it becomes unmaintainable very quickly, use a templating language, ether with a framework(recomended) or standalone. But he /is/ using a templating language... PHP. ;-) Keep telling yourself that... and be sure to pat your own back. Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Embedding foreach loops
On Aug 11, 2009, at 12:13 AM, hessi...@hessiess.com wrote: Do *NOT* get into the habit of outputting your HTML using echo or print statements, it becomes unmaintainable very quickly, use a templating language, ether with a framework(recomended) or standalone. This sounds interesting. Could you expound on this a little more and perhaps list a couple of the templates you mention? Thanks, Frank There are a number of options for templating in PHP such as smarty, Dwoo and PHP itself, though the syntax can be rather messy. Personally I just use a simple find and replace macro system to expand custom short-hand code into the more verbose PHP, then run it through exec and capture the result to a variable with output buffering, the class folows: ?php class view { var $str; /*++ * Load in template file and expand macros into PHP ++*/ function __CONSTRUCT($tplname) { $fh = fopen($tplname, 'r'); $this-str = fread($fh, filesize($tplname)); fclose($fh); $this-expand_macros(); } /*++ * Run the template and return a variable ++*/ public function parse_to_variable($array = array()) { extract($array); ob_start(); eval($this-str); $result = ob_get_contents(); ob_end_clean(); return $result; } /*++ * Expand macros into PHP ++*/ private function expand_macros() { // Expand if macro $this-str = str_replace(if, ?php if, $this-str); $this-str = str_replace(eif~, ?php endif;?, $this-str); // Expand loop macro $this-str = str_replace(loop, ?php foreach, $this-str); $this-str = str_replace(eloop~, ?php endforeach;?, $this-str); // Expand display macro $this-str = str_replace(dsp, ?php echo, $this-str); // Expand end tag macro $this-str = str_replace(~, ?, $this-str); // Add PHP close tag to exit PHP mode $this-str = ? . $this-str; } } This loads template files like the folowing: form enctype=multipart/form-data action=dsp $upload_url ~ method=post pinput type=hidden name=MAX_FILE_SIZE value=900 //p pUpload new file, max size dsp $max ~:/p p input name=uploaded_file type=file / input type=submit value=Send File / /p /form table tr th width=180pxFilename/th th width=60pxLink/th th width=90pxSize (KB)/th th width=50pxDelete/th tr loop ($files as $file): ~ tr tddsp $file['Name'] ~/td tda href=dsp $file['Path'] ~Link/a/td tddsp $file['Size'] / 1000 ~/td tda href=dsp $file['d_url'] ~X/a/td tr eloop~ /table --- And it can be used like this $dialogue = new view(template/file_display.tpl); $dialogue = $dialogue - parse_to_variable(array( 'upload_url' = $upload_url, 'max' = $max_size, 'files' = $files)); the $dialogue var now contains the compiled template, ready for displaying or integrating into another template. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Embedding foreach loops
statements, it becomes unmaintainable very quickly, use a templating language, ether with a framework(recomended) or standalone. But he /is/ using a templating language... PHP. ;-) Keep telling yourself that... and be sure to pat your own back. I'm sure there are plenty of situations that call for a more focused templating system than the one that PHP already is. And there are plenty that don't. From the earlier content of this thread, I suspect the problem the OP is currently working on falls into the latter camp. Didn't mean to bash templating systems. This is probably flame-war tinder, so I'll try to tread more delicately in the future. Next you know we'll be on the ternary operator and which is better, Mac or Windows. ;-) Ben
Re: [PHP] Embedding foreach loops
At 12:44 PM -0700 8/11/09, Ben Dunlap wrote: This is probably flame-war tinder, so I'll try to tread more delicately in the future. Next you know we'll be on the ternary operator and which is better, Mac or Windows. ;-) Ben That was won long ago, it's Mac. :-) Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Embedding foreach loops
On Tue, Aug 11, 2009 at 3:56 PM, teddtedd.sperl...@gmail.com wrote: At 12:44 PM -0700 8/11/09, Ben Dunlap wrote: This is probably flame-war tinder, so I'll try to tread more delicately in the future. Next you know we'll be on the ternary operator and which is better, Mac or Windows. ;-) Ben That was won long ago, it's Mac. :-) Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php If by Mac you mean Linux, you're entirely correct. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Embedding foreach loops
Allen, you off and running again? Sure am, thanks, on to the next set of issues. Seems like programming is always moving on from one error to the next :) Currently, I am having trouble with echo and php line-returns. It works on one part of the code, but not on another (instead, prints it to html). For example: [code] $show[show_01][price] * $show_01_qty = $Total_show_01; echo \ntr\n\t; echo tda.$show[show_01][price]./td/n/ttd*/td/n/ttdb. $show_01_qty./td/n/ttd=/td\n\ttdc.$Total_show_01./td; echo \n/tr; [/code] outputs this html [code] tr tda/td/n/ttd*/td/n/ttdb/td/n/ttd=/td tdc/td /tr [/code] Additionally, it won't display the variables, as you can see, even though they will echo out further above in the document. Odd... well you escape a newline char with this slash: \ and not this one: / notice you were not consistent with your use of them. as for the array not being parsed inside your echo statement - I don't see the issue by looking now. Are you saying the EXACT same code does output the expected value for those array elements higher up the script? Show us the code where it is working and again where it is not.. side by side (pasted just after each other in a new post to the list). I assume you are past this next point, but always remember var_dump($myArray); is your friend. Put it just before where you try to echo out some part of the array.. check to be sure the value is there is that element of the multi-dimensional array the way you think it is. -John -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Embedding foreach loops
OK, first guys, I'm sorry to have to do this but I can't get off this list!!! I've followed the instructions on a couple of occasions (the ones at the bottom of every email): PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Been There, done that. I can't get off the list!!! I use Gmail and I use an an alias as well, tried them both, still on the list. No reply from Majordomo. Yes, I've check my spam filter for a unsubscribe confirmation (if it sends one which I presume it's supposed to). Headers tell me that this list is php-general@lists.php.net. Sent the unsubscribe emails. No replies. Again. I apologize but have no idea what to do to get off this list! THis is the only list server I can't seem to get off of. Help! On Mon, Aug 10, 2009 at 6:04 PM, John Butlergovinda.webdnat...@gmail.com wrote: I can't seem to get my foreach loops to work, will PHP parse embedded loops? yes. Is this something I need to have in a database to work? no, you can do it with the arrays... but it may be easier to work with over the long run if that data was in a db. Anyway right after you finish creating the array and it's embedded arrays, in your code, then add this: var_dump($shows); //--so you can see what you just created. If it looks right, THEN go on bothering to try and parse it with your (embedded) foreach's { John Butler (Govinda) govinda.webdnat...@gmail.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -This message has been scanned for viruses and dangerous content byAccurate Anti-Spam Technologies. www.AccurateAntiSpam.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Embedding foreach loops
Let me be the first to welcome you to the list!!! Rick Duval wrote: OK, first guys, I'm sorry to have to do this but I can't get off this list!!! I've followed the instructions on a couple of occasions (the ones at the bottom of every email): PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Been There, done that. I can't get off the list!!! I use Gmail and I use an an alias as well, tried them both, still on the list. No reply from Majordomo. Yes, I've check my spam filter for a unsubscribe confirmation (if it sends one which I presume it's supposed to). Headers tell me that this list is php-general@lists.php.net. Sent the unsubscribe emails. No replies. Again. I apologize but have no idea what to do to get off this list! THis is the only list server I can't seem to get off of. Help! On Mon, Aug 10, 2009 at 6:04 PM, John Butlergovinda.webdnat...@gmail.com wrote: I can't seem to get my foreach loops to work, will PHP parse embedded loops? yes. Is this something I need to have in a database to work? no, you can do it with the arrays... but it may be easier to work with over the long run if that data was in a db. Anyway right after you finish creating the array and it's embedded arrays, in your code, then add this: var_dump($shows); //--so you can see what you just created. If it looks right, THEN go on bothering to try and parse it with your (embedded) foreach's { John Butler (Govinda) govinda.webdnat...@gmail.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -This message has been scanned for viruses and dangerous content byAccurate Anti-Spam Technologies. www.AccurateAntiSpam.com -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Embedding foreach loops
On Mon, Aug 10, 2009 at 6:44 PM, Allen McCabeallenmcc...@gmail.com wrote: Gmail automatically sent my last email, apologies. I am creating an order form for tickets for a list of performances at a performing arts center. Currently, the form is on paper, and is set up as follows: -Title - date - time - price - soldout - quantity - total($) -Nutcracker - Tues 10/13 - 9am - $4.00 - yes/no - - __ -Nutcracker - Tues 10/13 - 11am - $4.00 - yes/no - - __ -Mayhem P.. - Thur 01/21 - 9am - $4.00 - yes/no - - __ -Mayhem P.. - Thur 01/21 - 11am - $4.00 - yes/no - - __ -Max and... - Tues 04/21 - 9am - $4.00 - yes/no - - __ A given show may have between 1 and 4 performances, and I figured the best way to approach this was to consider each show time for each show as an entity. There are 19 unique titles, but given different showtimes, it becomes 38 'shows'. I have the shows in an array ($shows), and the details for each show in its own array (eg. $show_01) embedded into the show array. I need to generate a row for each show (so 38 rows), and assign quantity and total input fields a unique name and id. I can't seem to get my foreach loops to work, will PHP parse embedded loops? Here is an example of my embedded arrays: [code=shows.php] $shows = array(); $shows['show_01'] = $show_01; $show_01 = array(); $show_01['title'] = 'Van Cliburn Gold Medal Winner'; $show_01['date'] = 'Tues. 10/13/2009'; $show_01['time'] = '11am'; $show_01['price'] = 4.00; $show_01['soldout'] = 0; //IF THE SHOW SELLS OUT, CHANGE 0 to 1 (without quotations). $shows['show_02'] = $show_02; $show_02 = array(); $show_02['title'] = 'Jack and the Beanstalk'; $show_02['date'] = 'Fri. 10/23/2009'; $show_02['time'] = '11am'; $show_02['price'] = 4.00; $show_02['soldout'] = 0; //IF THE SHOW SELLS OUT, CHANGE 0 to 1 (without quotations). [/code] And here are the foreach loops I'm trying to build the rows with: [code=order.php] ?php foreach ($shows as $key = $value) { foreach ($value as $key2 = $value2) { print ' td bgcolor=#DD'. $value2 .'/td'; } print 'trtd'; print ' td colspan=3 bgcolor=#DDinput name='.$value.'_qty type=text id='.$value.'_qty size=5 //td'; print ' th bgcolor=#DDspan class=style6$/span'; print ' input name='.$value.'_total type=text id='.$value.'_total size=15 maxlength=6 //th'; print ' th bgcolor=#DD class=instructyes/no/th'; print '/tr'; } ? [/code] In case you were wondering why I embedded the foreach statement, I need each array (eg. $show_22) to display in a row, and I need PHP to build as many rows are there are shows. Is this something I need to have in a database to work? Thanks! Embedded loops are OK, actually I don't know a language where you can't do it :) I think that your problem is the $shows array creation, you do this: $shows = array(); $shows['show_01'] = $show_01; $show_01 = array(); Note that you are assigning $show_01 to a key in $shows before creating $show_01, you should first create and fill $show_01 and then assign it to a key in $shows. Hope that helps. Jonathan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Embedding foreach loops
I can't seem to get my foreach loops to work, will PHP parse embedded loops? yes. Is this something I need to have in a database to work? no, you can do it with the arrays... but it may be easier to work with over the long run if that data was in a db. Anyway right after you finish creating the array and it's embedded arrays, in your code, then add this: var_dump($shows); //--so you can see what you just created. If it looks right, THEN go on bothering to try and parse it with your (embedded) foreach's { John Butler (Govinda) govinda.webdnat...@gmail.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Embedding foreach loops
John, I did this, and got my arrays dumped (on one line). After adding line returns, here is a snippet: [code=array dump] array(38) { [show_01]= array(5) { [title]= string(29) Van Cliburn Gold Medal Winner [date]= string(16) Tues. 10/13/2009 [time]= string(4) 11am [price]= float(4) [soldout]= int(0) } [show_02]= array(5) { [title]= string(22) Jack and the Beanstalk [date]= string(15) Fri. 10/23/2009 [time]= string(4) 11am [price]= float(4) [soldout]= int(0) } [/code] and for reference, my original php used to set up arrays [code=shows.php] $shows = array(); $show_01 = array(); $show_01['title'] = 'Van Cliburn Gold Medal Winner'; $show_01['date'] = 'Tues. 10/13/2009'; $show_01['time'] = '11am'; $show_01['price'] = 4.00; $show_01['soldout'] = 0; //IF THE SHOW SELLS OUT, CHANGE 0 to 1 (without quotations). $shows['show_01'] = $show_01; $show_02 = array(); $show_02['title'] = 'Jack and the Beanstalk'; $show_02['date'] = 'Fri. 10/23/2009'; $show_02['time'] = '11am'; $show_02['price'] = 4.00; $show_02['soldout'] = 0; //IF THE SHOW SELLS OUT, CHANGE 0 to 1 (without quotations). $shows['show_02'] = $show_02; [/code] Does this dump look right? On Mon, Aug 10, 2009 at 3:04 PM, John Butler govinda.webdnat...@gmail.comwrote: I can't seem to get my foreach loops to work, will PHP parse embedded loops? yes. Is this something I need to have in a database to work? no, you can do it with the arrays... but it may be easier to work with over the long run if that data was in a db. Anyway right after you finish creating the array and it's embedded arrays, in your code, then add this: var_dump($shows); //--so you can see what you just created. If it looks right, THEN go on bothering to try and parse it with your (embedded) foreach's { John Butler (Govinda) govinda.webdnat...@gmail.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Embedding foreach loops
I did this, and got my arrays dumped (on one line). After adding line returns, here is a snippet: it looks OK. Note that you can see (copy/paste) that array which you just dumped, much better, if you view the source code of the html page. OR you can use pre to make that format persist thru' to what you see without viewing the source., Like so: echo hr /pre\n; var_dump($theArray); echo /pre\n; echo hr /\n; My brain is so full of my own work.. and I am newbie compared to most lurking here.. but I am sure we'll figure out your issue if we work on it systematically. OK, your OP just said, ..I can't seem to get my foreach loops to work.. , but you never said exactly what is the problem. Break the problem down to the smallest thing that you can find that is not behaving as you expect it to, and explain THAT to me. We'll do this step by step. -John -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Embedding foreach loops
I am using the print function to display my html. I cannot get the line return ( \n ) character to actually push the html onto the next line, it just gets displayed instead. Should I be using echo? On Mon, Aug 10, 2009 at 3:41 PM, John Butler govinda.webdnat...@gmail.comwrote: I did this, and got my arrays dumped (on one line). After adding line returns, here is a snippet: it looks OK. Note that you can see (copy/paste) that array which you just dumped, much better, if you view the source code of the html page. OR you can use pre to make that format persist thru' to what you see without viewing the source., Like so: echo hr /pre\n; var_dump($theArray); echo /pre\n; echo hr /\n; My brain is so full of my own work.. and I am newbie compared to most lurking here.. but I am sure we'll figure out your issue if we work on it systematically. OK, your OP just said, ..I can't seem to get my foreach loops to work.. , but you never said exactly what is the problem. Break the problem down to the smallest thing that you can find that is not behaving as you expect it to, and explain THAT to me. We'll do this step by step. -John -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Embedding foreach loops
$shows = array(); $show_01 = array(); $show_01['title'] = 'Van Cliburn Gold Medal Winner'; $show_01['date'] = 'Tues. 10/13/2009'; $show_01['time'] = '11am'; $show_01['price'] = 4.00; $show_01['soldout'] = 0; //IF THE SHOW SELLS OUT, CHANGE 0 to 1 (without quotations). $shows['show_01'] = $show_01; [etc.] If I'm setting up a lot of static data ahead of time like this, I prefer a slightly simpler syntax (or at least it seems simpler to me): $shows = array( 'show_01' = array( 'title' = 'Van Cliburn Gold Medal Winner', 'date' = [etc.] ), 'show_02' = array( 'title' = [etc.] ), [etc.] ); And sure, you could do all this in a database, or some other sort of external storage, but unless you're looking at creating a separate UI for someone other than yourself to input the data, it's probably simpler all around just to define the data directly in PHP. No reason you couldn't upgrade to something more sophisticated down the road, if the customer requires it. Ben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Embedding foreach loops
You're not using the pre and /pre tag most likely then. -Original Message- From: Allen McCabe [mailto:allenmcc...@gmail.com] Sent: Monday, August 10, 2009 4:11 PM To: John Butler Cc: phpList Subject: Re: [PHP] Embedding foreach loops I am using the print function to display my html. I cannot get the line return ( \n ) character to actually push the html onto the next line, it just gets displayed instead. Should I be using echo? On Mon, Aug 10, 2009 at 3:41 PM, John Butler govinda.webdnat...@gmail.comwrote: I did this, and got my arrays dumped (on one line). After adding line returns, here is a snippet: it looks OK. Note that you can see (copy/paste) that array which you just dumped, much better, if you view the source code of the html page. OR you can use pre to make that format persist thru' to what you see without viewing the source., Like so: echo hr /pre\n; var_dump($theArray); echo /pre\n; echo hr /\n; My brain is so full of my own work.. and I am newbie compared to most lurking here.. but I am sure we'll figure out your issue if we work on it systematically. OK, your OP just said, ..I can't seem to get my foreach loops to work.. , but you never said exactly what is the problem. Break the problem down to the smallest thing that you can find that is not behaving as you expect it to, and explain THAT to me. We'll do this step by step. -John -- 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] Embedding foreach loops
I am using the print function to display my html. I cannot get the line return ( \n ) character to actually push the html onto the next line, it just gets displayed instead. Should I be using echo? In the PHP code snippet you pasted above, you're using single-quotes to delimit your literal strings. In-between single-quotes, '\n' is not converted to a newline character. It's interpeted completely literally: http://us.php.net/manual/en/language.types.string.php#language.types.string.syntax.single Also, are you looking to insert a line break into the HTML itself -- just to keep your HTML code clean -- or into the visible page that's rendered from the HTML? Because newlines don't have any significance in HTML. You'd need to insert a br / or close a block-level element to get the effect of a line-break in the visible page. Ben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Embedding foreach loops
I am using the print function to display my html. I cannot get the line return ( \n ) character to actually push the html onto the next line, it just gets displayed instead. Should I be using echo? Allen, you off and running again? echo blah.. \n; //-- this will print the literal 'blah.. ' and then a newline into your HTML *source code* echo 'blah.. \n'; //-- this will print the literal 'blah.. \n' into your HTML *source code* IIRC print is the same as echo. That is not your apparent issue. Say if you are stuck again, and on what exactly. -John -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php