Page 1 of 1

Cleaning up White Space

Posted: Tue Feb 13, 2007 1:37 pm
by cesarcesar
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


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

Code: Select all

<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

Code: Select all

<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>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Re: Cleaning up White Space

Posted: Tue Feb 13, 2007 1:46 pm
by Kieran Huggins
cesarcesar wrote:I have looked into Code Beautifing programs and am NOT intrested in them.
You want to beautify your code, but you don't want software that beautifies your code?

Then "no".

If I've misunderstood, there's always the "tidy" functions in PHP

Posted: Tue Feb 13, 2007 1:52 pm
by cesarcesar
the 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 fine http://pear.php.net/package/PHP_Beautifier but i still would like to do it all myself in the actual code.

TIDY has been little help. Inner tangled PHP seems to break it.

Posted: Tue Feb 13, 2007 2:00 pm
by feyd
Stopping and starting php processing with <?php and ?> intermixed with indentation and other lines is the cause of all the additional whitespace. Consolidate your blocks of PHP.

Posted: Tue Feb 13, 2007 2:05 pm
by Kieran Huggins
You'll need to use an output buffer - tidy has it's own. check out http://ca3.php.net/manual/en/ref.tidy.php for more

Posted: Tue Feb 13, 2007 3:39 pm
by cesarcesar
looking into http://devzone.zend.com/node/view/id/761, looks promising.