Project

General

Profile

SnipPets » History » Version 4

Simon, 01/20/2011 11:50 AM

1 1 Simon
= Snippets = 
2
3 4 Simon
4
== Convert relative to absolute URL ==
5
6
'''Certainly the best and safer way'''
7
 - http://nadeausoftware.com/node/79
8
9
'''the way it simply works'''[[BR]]
10
11
 - from http://www.howtoforge.com/forums/showthread.php?t=4
12
{{{
13
function absolute_url($txt, $base_url){
14
  $needles = array('href="', 'src="', 'background="');
15
  $new_txt = '';
16
  if(substr($base_url,-1) != '/') $base_url .= '/';
17
  $new_base_url = $base_url;
18
  $base_url_parts = parse_url($base_url);
19
20
  foreach($needles as $needle){
21
    while($pos = strpos($txt, $needle)){
22
      $pos += strlen($needle);
23
      if(substr($txt,$pos,7) != 'http://' && substr($txt,$pos,8) != 'https://' && substr($txt,$pos,6) != 'ftp://' && substr($txt,$pos,9) != 'mailto://'){
24
        if(substr($txt,$pos,1) == '/') $new_base_url = $base_url_parts['scheme'].'://'.$base_url_parts['host'];
25
        $new_txt .= substr($txt,0,$pos).$new_base_url;
26
      } else {
27
        $new_txt .= substr($txt,0,$pos);
28
      }
29
      $txt = substr($txt,$pos);
30
    }
31
    $txt = $new_txt.$txt;
32
    $new_txt = '';
33
  }
34
  return $txt;
35
}  
36
}}}
37
38
39 1 Simon
== Remove trailing whitespaces ==
40
41
http://jimbojw.com/wiki/index.php?title=How_to_find_PHP_files_with_trailing_whitespace
42
43
'''Command Line :''' 
44
{{{
45
echo '<?php foreach (glob("**/*.php") as $file){if (preg_match( "/\\?".">\\s\\s+\\Z/m", file_get_contents($file))) echo("$file\n");} ?>' | php
46
}}}
47
48
49
'''PHP file script :'''
50
{{{
51
<?php
52
foreach (glob('**/*.php') as $file){
53
  if (preg_match('/\\?'.'>\\s\\s+\\Z/m',file_get_contents($file)))
54
    echo("$file\n");
55
}
56
?>
57
}}}
58 2 Simon
59
60 3 Simon
== Remove .svn folders under Windows ==
61 2 Simon
62
{{{
63
for /r repository %f in (.svn) do rd /S /Q "%f"
64
}}}
65
66 1 Simon
from : http://www.jonathan-petitcolas.com/fr/supprimer-recursivement-les-dossiers-svn-sous-windows/
67 3 Simon
68
== Ignore specific subfolders in .htaccess (URL rewrite) == 
69
70
71
'''Method 1 :'''
72
{{{
73
  RewriteEngine on
74
  #
75
  # stuff to let through (ignore)
76
  RewriteCond %{REQUEST_URI} "/folder1/" [OR]
77
  RewriteCond %{REQUEST_URI} "/folder2/"
78
  RewriteRule (.*) $1 [L]
79
  #
80
}}}
81
82
'''Method 2 :'''
83
{{{
84
RewriteEngine On
85
RewriteBase /
86
Rewritecond  %{REQUEST_URI} !^/linea21/.*$ [NC]
87
RewriteCond %{REQUEST_FILENAME} !-f
88
RewriteCond %{REQUEST_FILENAME} !-d
89
RewriteRule . /index.php [L]
90
}}}
91
92
(Ignore rules for ''linea21'' sub-folder)