SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Jun 2005
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cleaning up White Space

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

  2. #2
    *********! *********!!! jackli's Avatar
    Join Date
    Sep 2005
    Posts
    436
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    have a meta-php script that replaces the blocky spaces.

    PHP Code:
    $content=file_get_content("original_script.php") ;
    str_replace("                ","",$content); 
    or you can always use regular expressions to be sure.

  3. #3
    SitePoint Addict
    Join Date
    Jun 2005
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    can you provide a regular expressions example?

    i will try your first suggestion. thank you

  4. #4
    SitePoint Evangelist Jedi007's Avatar
    Join Date
    Aug 2005
    Posts
    463
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $content file_get_content("original_script.php") ;
    $content preg_replace("\s"" "$content); 
    (not tested) It basically converts every type of whitespace into a normal space (so things don't completely dissapear)

    hope it helps

  5. #5
    Obey the Purebreed trib4lmaniac's Avatar
    Join Date
    Dec 2004
    Location
    Cornwall, UK
    Posts
    594
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quicker would be to just replace tabs:
    PHP Code:
    $content str_replace("\t"" "$content); 


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •