Project

General

Profile

SnipPets » History » Revision 6

Revision 5 (Simon, 01/20/2011 12:07 PM) → Revision 6/7 (Simon, 01/20/2011 12:07 PM)

 
 h1. = Snippets 
 


 h2. =  

 == 15 usefull regex 

 == 
 http://www.catswhocode.com/blog/15-php-regular-expressions-for-web-developers 


 h2. 

 == Convert relative to absolute URL 


 *Certainly == 

 '''Certainly the best and safer way* way''' 
  - http://nadeausoftware.com/node/79 

 *the '''the way it simply works* 


  works'''[[BR]] 

  - from http://www.howtoforge.com/forums/showthread.php?t=4 
 <pre> 
 {{{ 
 function absolute_url($txt, $base_url){ 
   $needles = array('href="', 'src="', 'background="'); 
   $new_txt = _; ''; 
   if(substr($base_url,-1) != '/') $base_url .= '/'; 
   $new_base_url = $base_url; 
   $base_url_parts = parse_url($base_url); 

   foreach($needles as $needle){ 
     while($pos = strpos($txt, $needle)){ 
       $pos += strlen($needle); 
       if(substr($txt,$pos,7) != 'http://' && substr($txt,$pos,8) != 'https://' && substr($txt,$pos,6) != 'ftp://' && substr($txt,$pos,9) != 'mailto://'){ 
         if(substr($txt,$pos,1) == '/') $new_base_url = $base_url_parts['scheme'].'://'.$base_url_parts['host']; 
         $new_txt .= substr($txt,0,$pos).$new_base_url; 
       } else { 
         $new_txt .= substr($txt,0,$pos); 
       } 
       $txt = substr($txt,$pos); 
     } 
     $txt = $new_txt.$txt; 
     $new_txt = _; ''; 
   } 
   return $txt; 
 }   
 </pre> 



 h2. }}} 


 == Remove trailing whitespaces 


 == 

 http://jimbojw.com/wiki/index.php?title=How_to_find_PHP_files_with_trailing_whitespace 

 *Command '''Command Line :* :'''  
 <pre> 
 {{{ 
 echo '<?php foreach (glob("**/*.php") as $file){if (preg_match( "/\\?".">\\s\\s+\\Z/m", file_get_contents($file))) echo("$file\n");} ?>' | php 
 </pre> 


 *PHP }}} 


 '''PHP file script :* :''' 
 <pre> 
 {{{ 
 <?php 
 foreach (glob('**/*.php') as $file){ 
   if (preg_match('/\\?'.'>\\s\\s+\\Z/m',file_get_contents($file))) 
     echo("$file\n"); 
 } 
 ?> 
 </pre> 



 h2. }}} 


 == Remove .svn folders under Windows 


 <pre> 
 == 

 {{{ 
 for /r repository %f in (.svn) do rd /S /Q "%f" 
 </pre> 

 }}} 

 from : http://www.jonathan-petitcolas.com/fr/supprimer-recursivement-les-dossiers-svn-sous-windows/ 


 h2. 

 == Ignore specific subfolders in .htaccess (URL rewrite) 
 


 *Method ==  


 '''Method 1 :* :''' 
 <pre> 
   [[RewriteEngine]] {{{ 
   RewriteEngine on 
   # 
   # stuff to let through (ignore) 
   [[RewriteCond]] RewriteCond %{REQUEST_URI} "/folder1/" [OR] 
   [[RewriteCond]] RewriteCond %{REQUEST_URI} "/folder2/" 
   [[RewriteRule]] RewriteRule (.*) $1 [L] 
   # 
 </pre> 

 *Method }}} 

 '''Method 2 :* :''' 
 <pre> 
 [[RewriteEngine]] {{{ 
 RewriteEngine On 
 [[RewriteBase]] RewriteBase / 
 Rewritecond    %{REQUEST_URI} !^/linea21/.*$ [NC] 
 [[RewriteCond]] RewriteCond %{REQUEST_FILENAME} !-f 
 [[RewriteCond]] RewriteCond %{REQUEST_FILENAME} !-d 
 [[RewriteRule]] RewriteRule . /index.php [L] 
 </pre> 

 }}} 

 (Ignore rules for _linea21_ ''linea21'' sub-folder)