473,411 Members | 1,937 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

Cleaning up White Space

162 100+
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
Expand|Select|Wrap|Line Numbers
  1. <table width="100%" border=0 cellspacing=0 cellpadding=5 style="text-align:left;padding:px;font-size:12px;">
  2.     </tr>
  3.  
  4.         <?php
  5.         $x=0;
  6.         /*   get field names in Ranges tab  */
  7.         $_conn2 = db_query("
  8.         Select
  9.         sale_type_field.sale_type_field_name,
  10.         sale_type_field.sale_type_field_value,
  11.         sale_type_field.calc,
  12.         sale_type_field.calc1,
  13.         sale_type_field.calc2
  14.         From
  15.         sale_type_field
  16.         LEFT OUTER JOIN connector_sale_type_field ON sale_type_field.sale_type_field_id = connector_sale_type_field.sale_type_field_id
  17.         Where
  18.         connector_sale_type_field.sale_type_tab_id = 137 AND
  19.         connector_sale_type_field.sale_type_id = 34
  20.         Order By
  21.         connector_sale_type_field.stf_display_order Asc
  22.         ");
  23.         while($conn2 = db_fetch_array($_conn2)){
  24.  
  25.             /*   set underscored version of sale_type_field_name   */
  26.             $sale_type_field_name = implode('_',explode(' ',strtolower($conn2['sale_type_field_name'])));
  27.  
  28.             /*   get sale type field names   */
  29.             if ($_vars['sale_id'] <> '') {
  30.                 $_stfv = db_query("
  31.                 Select
  32.                 sale_type_subdivision.$sale_type_field_name,
  33.                 connector_sale.sale_id,
  34.                 connector_sale.ref_id
  35.                 From
  36.                 connector_sale
  37.                 LEFT OUTER JOIN sale_type_subdivision ON sale_type_subdivision.sale_type_subdivision_id = connector_sale.ref_id
  38.                 Where
  39.                 connector_sale.sale_id = '".$_vars['sale_id']."'
  40.                 limit 1
  41.                 ");
  42.                 $stfv = db_fetch_array($_stfv);
  43.                 $sale_type_field_value = $stfv[$sale_type_field_name];
  44.             }
  45.  
  46.             /*   if there is no saved value, set to default   */
  47.             if ($stfv[$sale_type_field_name] == "") {
  48.                 $sale_type_field_value = $conn2['sale_type_field_value'];
  49.             }
  50.  
  51.             /*   set lot array   */
  52.             $number = "";
  53.             $lot_sales = array('First Lot Sale ','Second Lot Sale ','Third Lot Sale ','Home Sale '); //
  54.  
  55.             /*   set some vars for determining what lot sale it is   */
  56.             if (in_array(substr($conn2['sale_type_field_name'],0,15),$lot_sales)){
  57.                 $number = 15;
  58.             }elseif (in_array(substr($conn2['sale_type_field_name'],0,16),$lot_sales)){
  59.                 $number = 16;
  60.             }elseif (in_array(substr($conn2['sale_type_field_name'],0,10),$lot_sales)){
  61.                 $number = 10;
  62.             }
  63.  
  64.             /*   re-set sale_type_field_name so that proper fielt type is set   */
  65.             $sale_type_field_name2 = $sale_type_field_name;
  66.             $sale_type_field_name = strtolower(substr($sale_type_field_name,$number));
  67.             ?>
  68.  
  69.  
  70.             <?php  /*  if the field a calculation..    */ ?>
  71.             <?php
  72.             if ($conn2['calc'] != "") {
  73.  
  74.                 if ($conn2['calc1'] == "") {
  75.                     $conn2['calc1'] = $sale_type_field_name2;
  76.                 }else{
  77.                     $_ft = db_query("
  78.                     Select
  79.                     sale_type_field.sale_type_field_name
  80.                     From
  81.                     sale_type_field
  82.                     Where
  83.                     sale_type_field.sale_type_field_id = '".$conn2['calc1']."'
  84.                     limit 1
  85.                     ");
  86.                     $ft = db_fetch_array($_ft);
  87.                     $conn2['calc1'] = implode('_',explode(' ',strtolower($ft['sale_type_field_name'])));
  88.                 }
  89.  
  90.                 /*   get low hi ave numbers   */
  91.                 $_avg = db_query("
  92.                 Select
  93.                 Count(sale_type_lot_sale.$conn2[calc1]) AS count_$conn2[calc1],
  94.                 Sum(sale_type_lot_sale.$conn2[calc1]) AS sum_$conn2[calc1],
  95.                 Min(sale_type_lot_sale.$conn2[calc1]) AS min_$conn2[calc1],
  96.                 Max(sale_type_lot_sale.$conn2[calc1]) AS max_$conn2[calc1]
  97.                 From
  98.                 sale_type_lot_sale
  99.                 Where
  100.                 sale_type_lot_sale.sale_id = '".$_vars['sale_id']."' AND
  101.                 sale_type_lot_sale.$conn2[calc1] <> ''
  102.                 limit 1
  103.                 ");
  104.                 $avg = db_fetch_array($_avg);
  105.  
  106.                 if ($conn2['calc'] == "lot absorption") {
  107.  
  108.                     /*   total lot count minus   */
  109.                     $absorption = $lot_count['count_lot_nbr'] - $avg['count_'.$conn2['calc1']];
  110.                     $_value = $absorption;
  111.  
  112.                 }elseif ($conn2['calc'] == "lot absorb perc") {
  113.  
  114.                     /*   total lot count minus   */
  115.                     $absorption = $avg['count_'.$conn2['calc1']] / $lot_count['count_lot_nbr'];
  116.                     if ($absorption == 1) { $absorption = 100; }else{ $absorption = substr($absorption,0,4); }
  117.                     $_value = $absorption."%";
  118.  
  119.                 }elseif ($conn2['calc'] == "lot count") {
  120.  
  121.                     $_value = $avg['count_'.$conn2['calc1']];
  122.  
  123.                 }elseif ($conn2['calc'] == "lot low") {
  124.  
  125.                     $_value = $avg['min_'.$conn2['calc1']];
  126.  
  127.                 }elseif ($conn2['calc'] == "lot high") {
  128.  
  129.                     $_value = $avg['max_'.$conn2['calc1']];
  130.  
  131.                 } ?>
  132.  
  133.                 <?php if ($x == 0) { ?><tr><?php } ?>
  134.                 <th valign="top" align="right"><?php pv($conn2['sale_type_field_name']); ?>:</td>
  135.                 <td valign="top"><?php pv($_value); ?></td>
  136.                 <?php if ($x == 2) { $x=0; }else{ $x++; } ?>
  137.  
  138.             <?php } ?>
  139.  
  140.         <?php } ?>
  141.  
  142.         <?php for ($i = 0; $i < 2-$x; $i++) { ?><td></td><?php } ?>
  143.  
  144.     </tr>
  145. </table>
  146.  
Example View Source
Expand|Select|Wrap|Line Numbers
  1. <table width="100%" border=0 cellspacing=0 cellpadding=5 style="text-align:left;padding:px;font-size:12px;">
  2.     </tr>
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.                 <tr>                <th valign="top" align="right">First Lot Sale:</td>
  11.                 <td valign="top">2004-09-03</td>
  12.  
  13.  
  14.  
  15.  
  16.  
  17.                                 <th valign="top" align="right">No Closed Home Sales:</td>
  18.                 <td valign="top">-3</td>
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.                                 <th valign="top" align="right">Lots Sold:</td>
  28.                 <td valign="top">4</td>
  29.  
  30.  
  31.  
  32.  
  33.  
  34.                 <tr>                <th valign="top" align="right">Last Lot Sale:</td>
  35.                 <td valign="top">2005-01-19</td>
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.                                 <th valign="top" align="right">Lots Left:</td>
  45.                 <td valign="top">-4</td>
  46.  
  47.  
  48.  
  49.  
  50.  
  51.                                 <th valign="top" align="right">Absob As Of:</td>
  52.                 <td valign="top">2005-01-19</td>
  53.  
  54.  
  55.  
  56.  
  57.  
  58.                 <tr>                <th valign="top" align="right">Pct Absorb:</td>
  59.                 <td valign="top">%</td>
  60.  
  61.  
  62.  
  63.  
  64.  
  65.                                 <th valign="top" align="right">Homes Sold:</td>
  66.                 <td valign="top">3</td>
  67.  
  68.  
  69.  
  70.  
  71.     </tr>
  72. </table>
  73.  
Feb 13 '07 #1
2 2284
Motoma
3,237 Expert 2GB
There are a number of ways to do this:
Use Templates.
Explicitly echo all HTML(i.e. entire php file is in one large set of <?php ?> brackets).
Don't be such a messy coder.

The first is most preferable, as it separates your user interface from your actual information.
The second takes a little bit of work, and the gains aren't that great for large unique pages.
The third is a horrible solution and should never be considered ;)
Feb 13 '07 #2
xwero
99
you could catch your output in a string and add the line breaks and indentation as hard code.

[PHP]
$output = '';
$output .= '<table>'.chr(10);
$output .= chr(32).chr(32).'<tr>'.chr(10);
[/PHP]

This is a monkey job so maybe a function is more usable

[PHP]
function createLine($html,$indentation = 0){
$output = '';
for($i=0;$i<$indentation;$i++){ $output .= chr(32); }
$output .= $html.chr(10);
return $output;
}

$html = '';
$html .= createLine('<table>');
$html .= createLine('<tr>',2);
[/PHP]


or you can skip this all together and seperate as much php code from your html code and even go the template way.
Feb 13 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Grumble | last post by:
Hello all, I want to read lines from a text file, where each line has the following syntax: token1:token2:token3 There could be white space between tokens and ':'
2
by: Malcolm Dew-Jones | last post by:
I am looking at xslt 1.0 and trying to understand if empty text nodes are supposed to be stripped or not as the default behaviour. 3.4 starts by listing rules for when white space is not stripped...
17
by: Stanimir Stamenkov | last post by:
Is it possible to make two inline elements to appear adjacent stripping any white space appearing in between in the source? Example: <span class="adj">1</span> <span class="adj">2</span>...
5
by: Applebrown | last post by:
Hello, basically, I'm just learning intermediate CSS and trying to convert my old table webpage completely to CSS. Hoorah, right? Well, it's not quite going as planned. It's an extremely simple...
0
by: Mark Moore | last post by:
I'm trying to layout a couple text input fields and their corresponding labels without using a table. When I was trying to debug my understanding of CSS, I was *very* surprised to see that span's...
8
by: Peter O'Reilly | last post by:
I have an HTML form with a textarea input box. When the user conducts a post request (e.g. clicks the submit button), an HTML preview page is presented to them with the information they have...
38
by: Xah Lee | last post by:
sometimes i wish to add white space in <p> as to achived effects similar to tab. what should i do? using empty image seems the sure way but rather complicated. (and dosen't change size with...
2
by: shagy | last post by:
Hi, I'm having a problem with a <select><option> which has white space in values... When I post the data I only get the first word (up to the white space). "Testing white space" becomes...
4
by: mosesdinakaran | last post by:
Can any one explain how the rule is applied for the following Regular expression $Str = 'the red king'; $Pattern = '/((red|white) (king|queen))/'; preg_match($Pattern,$Str,$Val); Result:
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.