cesarcesar Posted February 13, 2007 Share Posted February 13, 2007 Hello, I am trying to clean up my "view source" code. Currently, due to the way i format my php/html code, the end viewable source looks really spread out with lots of white space between lines. Is there a way via CSS or using /n that will clean my code up a little. I have looked into Code Beautifing programs and am NOT intrested in them. Thanks. Example Code <table width="100%" border=0 cellspacing=0 cellpadding=5 style="text-align:left;padding:px;font-size:12px;"> </tr> <?php $x=0; /* get field names in Ranges tab */ $_conn2 = db_query(" Select sale_type_field.sale_type_field_name, sale_type_field.sale_type_field_value, sale_type_field.calc, sale_type_field.calc1, sale_type_field.calc2 From sale_type_field LEFT OUTER JOIN connector_sale_type_field ON sale_type_field.sale_type_field_id = connector_sale_type_field.sale_type_field_id Where connector_sale_type_field.sale_type_tab_id = 137 AND connector_sale_type_field.sale_type_id = 34 Order By connector_sale_type_field.stf_display_order Asc "); while($conn2 = db_fetch_array($_conn2)){ /* set underscored version of sale_type_field_name */ $sale_type_field_name = implode('_',explode(' ',strtolower($conn2['sale_type_field_name']))); /* get sale type field names */ if ($_vars['sale_id'] <> '') { $_stfv = db_query(" Select sale_type_subdivision.$sale_type_field_name, connector_sale.sale_id, connector_sale.ref_id From connector_sale LEFT OUTER JOIN sale_type_subdivision ON sale_type_subdivision.sale_type_subdivision_id = connector_sale.ref_id Where connector_sale.sale_id = '".$_vars['sale_id']."' limit 1 "); $stfv = db_fetch_array($_stfv); $sale_type_field_value = $stfv[$sale_type_field_name]; } /* if there is no saved value, set to default */ if ($stfv[$sale_type_field_name] == "") { $sale_type_field_value = $conn2['sale_type_field_value']; } /* set lot array */ $number = ""; $lot_sales = array('First Lot Sale ','Second Lot Sale ','Third Lot Sale ','Home Sale '); // /* set some vars for determining what lot sale it is */ if (in_array(substr($conn2['sale_type_field_name'],0,15),$lot_sales)){ $number = 15; }elseif (in_array(substr($conn2['sale_type_field_name'],0,16),$lot_sales)){ $number = 16; }elseif (in_array(substr($conn2['sale_type_field_name'],0,10),$lot_sales)){ $number = 10; } /* re-set sale_type_field_name so that proper fielt type is set */ $sale_type_field_name2 = $sale_type_field_name; $sale_type_field_name = strtolower(substr($sale_type_field_name,$number)); ?> <?php /* if the field a calculation.. */ ?> <?php if ($conn2['calc'] != "") { if ($conn2['calc1'] == "") { $conn2['calc1'] = $sale_type_field_name2; }else{ $_ft = db_query(" Select sale_type_field.sale_type_field_name From sale_type_field Where sale_type_field.sale_type_field_id = '".$conn2['calc1']."' limit 1 "); $ft = db_fetch_array($_ft); $conn2['calc1'] = implode('_',explode(' ',strtolower($ft['sale_type_field_name']))); } /* get low hi ave numbers */ $_avg = db_query(" Select Count(sale_type_lot_sale.$conn2[calc1]) AS count_$conn2[calc1], Sum(sale_type_lot_sale.$conn2[calc1]) AS sum_$conn2[calc1], Min(sale_type_lot_sale.$conn2[calc1]) AS min_$conn2[calc1], Max(sale_type_lot_sale.$conn2[calc1]) AS max_$conn2[calc1] From sale_type_lot_sale Where sale_type_lot_sale.sale_id = '".$_vars['sale_id']."' AND sale_type_lot_sale.$conn2[calc1] <> '' limit 1 "); $avg = db_fetch_array($_avg); if ($conn2['calc'] == "lot absorption") { /* total lot count minus */ $absorption = $lot_count['count_lot_nbr'] - $avg['count_'.$conn2['calc1']]; $_value = $absorption; }elseif ($conn2['calc'] == "lot absorb perc") { /* total lot count minus */ $absorption = $avg['count_'.$conn2['calc1']] / $lot_count['count_lot_nbr']; if ($absorption == 1) { $absorption = 100; }else{ $absorption = substr($absorption,0,4); } $_value = $absorption."%"; }elseif ($conn2['calc'] == "lot count") { $_value = $avg['count_'.$conn2['calc1']]; }elseif ($conn2['calc'] == "lot low") { $_value = $avg['min_'.$conn2['calc1']]; }elseif ($conn2['calc'] == "lot high") { $_value = $avg['max_'.$conn2['calc1']]; } ?> <?php if ($x == 0) { ?><tr><?php } ?> <th valign="top" align="right"><?php pv($conn2['sale_type_field_name']); ?>:</td> <td valign="top"><?php pv($_value); ?></td> <?php if ($x == 2) { $x=0; }else{ $x++; } ?> <?php } ?> <?php } ?> <?php for ($i = 0; $i < 2-$x; $i++) { ?><td></td><?php } ?> </tr> </table> Example View Source <table width="100%" border=0 cellspacing=0 cellpadding=5 style="text-align:left;padding:px;font-size:12px;"> </tr> <tr> <th valign="top" align="right">First Lot Sale:</td> <td valign="top">2004-09-03</td> <th valign="top" align="right">No Closed Home Sales:</td> <td valign="top">-3</td> <th valign="top" align="right">Lots Sold:</td> <td valign="top">4</td> <tr> <th valign="top" align="right">Last Lot Sale:</td> <td valign="top">2005-01-19</td> <th valign="top" align="right">Lots Left:</td> <td valign="top">-4</td> <th valign="top" align="right">Absob As Of:</td> <td valign="top">2005-01-19</td> <tr> <th valign="top" align="right">Pct Absorb:</td> <td valign="top">%</td> <th valign="top" align="right">Homes Sold:</td> <td valign="top">3</td> </tr> </table> Link to comment https://forums.phpfreaks.com/topic/38352-cleaning-up-white-space/ Share on other sites More sharing options...
JJohnsenDK Posted February 13, 2007 Share Posted February 13, 2007 So when you go to browser-> view source, the example code is displayed, right? Why would you want to clean this up? And does these whitespaces include in both IE and MF? Link to comment https://forums.phpfreaks.com/topic/38352-cleaning-up-white-space/#findComment-183837 Share on other sites More sharing options...
genericnumber1 Posted February 13, 2007 Share Posted February 13, 2007 one of the code beautifying things that comes with php that said you don't care about... http://devzone.zend.com/node/view/id/761 more reading... http://www.hudzilla.org/phpbook/read.php/19_11_0 I don't know why you say you want to clean up your HTML but don't want to use a script to do it? is that like driving without a car? the reason you would want to clean up your source jjohnsen, is it just looks more professional, there really is no reason other than that. ps. if you wanted to know why you have so many line breaks it's because you have them in your code.. all those line breaks outside of the <?php ?> tags show through in the browser. Link to comment https://forums.phpfreaks.com/topic/38352-cleaning-up-white-space/#findComment-183839 Share on other sites More sharing options...
cesarcesar Posted February 13, 2007 Author Share Posted February 13, 2007 the EXAMPLE code is the actual code before browser output. the other is the browser output. i wans to remove the large amnount of new lines from the browser output code. Link to comment https://forums.phpfreaks.com/topic/38352-cleaning-up-white-space/#findComment-183841 Share on other sites More sharing options...
cesarcesar Posted February 13, 2007 Author Share Posted February 13, 2007 i understand the line breaks are due to them in the HTML. i am just looking for a way to remove them after/while the code is being rendered. I don't know why you say you want to clean up your HTML but don't want to use a script to do it? is that like driving without a car? ok, very good point. my findings are that code beautifying programs are either stand alone and reformat to something other than my custom formating style, or they do not format HTML and PHP together. I did find, http://pear.php.net/package/PHP_Beautifier but i still would like to do it all myself in the actual code if possible. http://devzone.zend.com/node/view/id/761..... looks appealing. Link to comment https://forums.phpfreaks.com/topic/38352-cleaning-up-white-space/#findComment-183845 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.