Location: PHPKode > projects > Aukyla Document Management System > doc/html/a00235.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <title>Aukyla PHP Framework</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <link rel="StyleSheet" href="auton.css" type="text/css" media="screen">
  </head>

  <body>
    <div id="mainmenu">
      <a href="http://www.auton.nl/" class="home">Home</a>
    </div>
    <div id="submenu">
      <a class="logo" href="http://www.auton.nl/"></a>

      <div class="head">Ads</div>
      <a href="http://sourceforge.net/"><img src="http://sourceforge.net/sflogo.php?group_id=116358&amp;type=1" alt="SourceForge.net Logo" style="padding: 2px 4px; width: 88px; height: 31px; border: 0px"></a>
      <a href="http://getfirefox.com/" title="Get Firefox - The Browser, Reloaded."><img src="http://www.mozilla.org/products/firefox/buttons/getfirefox_small.png" alt="Get Firefox" style="width: 110px; height: 32px; border: 0px"></a>
    </div>
    <div id="main">
<!-- Generated by Doxygen 1.3.9.1 -->
<div class="qindex"><a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="hierarchy.html">Class&nbsp;Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical&nbsp;List</a> | <a class="qindex" href="annotated.html">Class&nbsp;List</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Class&nbsp;Members</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a></div>
<div class="nav">
<a class="el" href="dir_000000.html">base</a></div>
<h1>String.php</h1><div class="fragment"><pre class="fragment">00001 &lt;?php
00002 <span class="comment">/*</span>
00003 <span class="comment">     String.php, contains handy string utility functions.</span>
00004 <span class="comment">     Copyright (C) 2004 Arend van Beelen, Auton Rijnsburg</span>
00005 <span class="comment"></span>
00006 <span class="comment">     This program is free software; you can redistribute it and/or modify it</span>
00007 <span class="comment">     under the terms of the GNU General Public License as published by the Free</span>
00008 <span class="comment">     Software Foundation; either version 2 of the License, or (at your option)</span>
00009 <span class="comment">     any later version.</span>
00010 <span class="comment"></span>
00011 <span class="comment">     This program is distributed in the hope that it will be useful, but WITHOUT</span>
00012 <span class="comment">     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or</span>
00013 <span class="comment">     FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for</span>
00014 <span class="comment">     more details.</span>
00015 <span class="comment"></span>
00016 <span class="comment">     You should have received a copy of the GNU General Public License along</span>
00017 <span class="comment">     with this program; if not, write to the Free Software Foundation, Inc.,</span>
00018 <span class="comment">     59 Temple Place, Suite 330, Boston, MA 02111-1307 USA</span>
00019 <span class="comment"></span>
00020 <span class="comment">     For any questions, comments or whatever, you may mail me at: hide@address.com</span>
00021 <span class="comment">*/</span>
00022 
<a name="l00029"></a><a class="code" href="a00153.html">00029</a> <span class="keyword">class </span><a class="code" href="a00153.html">String</a>
00030 {
<a name="l00038"></a><a class="code" href="a00153.html#e0">00038</a>         <span class="keyword">public</span> <span class="keyword">static</span> function substringBefore($string, $substring, $reverse = <span class="keyword">false</span>)
00039         {
00040                 <span class="keywordflow">return</span> ($reverse == <span class="keyword">false</span> ?
00041                         substr($string, 0, strpos($string, $substring)) :
00042                         substr($string, 0, strrpos($string, $substring)));
00043         }
00044 
<a name="l00053"></a><a class="code" href="a00153.html#e1">00053</a>         <span class="keyword">public</span> <span class="keyword">static</span> function substringAfter($string, $substring, $reverse = <span class="keyword">false</span>)
00054         {
00055                 $pos = ($reverse == <span class="keyword">false</span> ? strpos($string, $substring) :
00056                                             strrpos($string, $substring));
00057                 <span class="keywordflow">if</span>($pos === <span class="keyword">false</span>)
00058                 {
00059                         <span class="keywordflow">return</span> $string;
00060                 }
00061                 <span class="keywordflow">else</span>
00062                 {
00063                         <span class="keywordflow">return</span> substr($string, $pos + strlen($substring));
00064                 }
00065         }
00066 
<a name="l00070"></a><a class="code" href="a00153.html#e2">00070</a>         <span class="keyword">public</span> <span class="keyword">static</span> function startsWith($string, $substring)
00071         {
00072                 <span class="keywordflow">return</span> (substr($string, 0, strlen($substring)) == $substring);
00073         }
00074 
<a name="l00078"></a><a class="code" href="a00153.html#e3">00078</a>         <span class="keyword">public</span> <span class="keyword">static</span> function endsWith($string, $substring)
00079         {
00080                 <span class="keywordflow">return</span> (substr($string, -strlen($substring)) == $substring);
00081         }
00082 
<a name="l00087"></a><a class="code" href="a00153.html#e4">00087</a>         <span class="keyword">public</span> <span class="keyword">static</span> function stripSpecialChars($string)
00088         {
00089                 $result = '';
00090                 <span class="keywordflow">for</span>($i = 0; $i &lt; strlen($string); $i++)
00091                 {
00092                         $char = $string{$i};
00093                         <span class="keywordflow">if</span>(ctype_alnum($<span class="keywordtype">char</span>) || $char == <span class="charliteral">' '</span> || $char == <span class="charliteral">'.'</span> ||
00094                            $char == <span class="charliteral">'_'</span> || $char == <span class="charliteral">'-'</span>)
00095                         {
00096                                 $result .= $char;
00097                         }
00098                 }
00099                 <span class="keywordflow">return</span> $result;
00100         }
00101 
<a name="l00106"></a><a class="code" href="a00153.html#e5">00106</a>         <span class="keyword">public</span> <span class="keyword">static</span> function normalizeSlashes($string)
00107         {
00108                 $result = '';
00109                 $slash = <span class="keyword">false</span>;
00110                 $char = '';
00111                 <span class="keywordflow">for</span>($i = 0; $i &lt; strlen($string); $i++)
00112                 {
00113                         $char = $string{$i};
00114                         <span class="keywordflow">if</span>($slash == <span class="keyword">false</span> || $char != <span class="charliteral">'/'</span>)
00115                         {
00116                                 $result .= $char;
00117                         }
00118                         $slash = ($char == <span class="charliteral">'/'</span>);
00119                 }
00120                 <span class="keywordflow">if</span>($char == <span class="charliteral">'/'</span>)
00121                 {
00122                         $result = substr($result, 0, -1);
00123                 }
00124                 <span class="keywordflow">return</span> $result;
00125         }
00126 
<a name="l00134"></a><a class="code" href="a00153.html#e6">00134</a>         <span class="keyword">public</span> <span class="keyword">static</span> function simplifyPath($path)
00135         {
00136                 <span class="keywordflow">if</span>($path == '')
00137                 {
00138                         <span class="keywordflow">return</span> '';
00139                 }
00140 
00141                 $dirs = explode(<span class="charliteral">'/'</span>, $path);
00142 
00143                 <span class="keywordflow">for</span>($i = ($dirs[0] == '' ? 1 : 0); $i &lt; <span class="keyword">sizeof</span>($dirs); $i++)
00144                 {
00145                         <span class="keywordflow">if</span>($dirs[$i] == '' ||
00146                            $dirs[$i] == <span class="charliteral">'.'</span>)
00147                         {
00148                                 array_splice($dirs, $i, 1);
00149                                 $i--;
00150                         }
00151                         <span class="keywordflow">else</span> <span class="keywordflow">if</span>($dirs[$i] == '..' &amp;&amp; $i &gt; 0)
00152                         {
00153                                 array_splice($dirs, $i - 1, 2);
00154                                 $i -= 2;
00155                         }
00156                 }
00157 
00158                 <span class="keywordflow">return</span> ''.implode(<span class="charliteral">'/'</span>, $dirs);
00159         }
00160 
<a name="l00176"></a><a class="code" href="a00153.html#e7">00176</a>         <span class="keyword">public</span> <span class="keyword">static</span> function isIpInRange($range, $ip)
00177         {
00178                 <span class="keywordflow">if</span>($range == '')
00179                 {
00180                         <span class="keywordflow">return</span> <span class="keyword">true</span>;
00181                 }
00182 
00183                 $ranges = explode(<span class="charliteral">';'</span>, $range);
00184                 $ipFields = explode(<span class="charliteral">'.'</span>, $ip);
00185                 $ipFields[0] = (int) $ipFields[0];
00186                 $ipFields[1] = (int) $ipFields[1];
00187                 $ipFields[2] = (int) $ipFields[2];
00188                 $ipFields[3] = (int) $ipFields[3];
00189 
00190                 foreach($ranges as $range)
00191                 {
00192                         <span class="keywordflow">if</span>(strchr($range, <span class="charliteral">'-'</span>))
00193                         {
00194                                 list($range1, $range2) = explode(<span class="charliteral">'-'</span>, $range, 2);
00195                                 $range1Fields = explode(<span class="charliteral">'.'</span>, $range1);
00196                                 $range1Fields[0] = (int) $range1Fields[0];
00197                                 $range1Fields[1] = (int) $range1Fields[1];
00198                                 $range1Fields[2] = (int) $range1Fields[2];
00199                                 $range1Fields[3] = (int) $range1Fields[3];
00200                                 $range2Fields = explode(<span class="charliteral">'.'</span>, $range2);
00201                                 $range2Fields[0] = (int) $range2Fields[0];
00202                                 $range2Fields[1] = (int) $range2Fields[1];
00203                                 $range2Fields[2] = (int) $range2Fields[2];
00204                                 $range2Fields[3] = (int) $range2Fields[3];
00205 
00206                                 $match = <span class="keyword">true</span>;
00207                                 <span class="keywordflow">for</span>($i = 0; $i &lt; 4; $i++)
00208                                 {
00209                                         <span class="keywordflow">if</span>($ipFields[$i] &lt; $range1Fields[$i] ||
00210                                            $ipFields[$i] &gt; $range2Fields[$i])
00211                                         {
00212                                                 $match = <span class="keyword">false</span>;
00213                                                 <span class="keywordflow">break</span>;
00214                                         }
00215                                 }
00216 
00217                                 <span class="keywordflow">if</span>($match == <span class="keyword">true</span>)
00218                                 {
00219                                         <span class="keywordflow">return</span> <span class="keyword">true</span>;
00220                                 }
00221                         }
00222                         <span class="keywordflow">else</span>
00223                         {
00224                                 $rangeFields = explode(<span class="charliteral">'.'</span>, $range);
00225                                 $rangeFields[0] = ($rangeFields[0] == <span class="charliteral">'*'</span> ? <span class="charliteral">'*'</span> : (int) $rangeFields[0]);
00226                                 $rangeFields[1] = ($rangeFields[1] == <span class="charliteral">'*'</span> ? <span class="charliteral">'*'</span> : (int) $rangeFields[1]);
00227                                 $rangeFields[2] = ($rangeFields[2] == <span class="charliteral">'*'</span> ? <span class="charliteral">'*'</span> : (int) $rangeFields[2]);
00228                                 $rangeFields[3] = ($rangeFields[3] == <span class="charliteral">'*'</span> ? <span class="charliteral">'*'</span> : (int) $rangeFields[3]);
00229 
00230                                 $match = <span class="keyword">true</span>;
00231                                 <span class="keywordflow">for</span>($i = 0; $i &lt; 4; $i++)
00232                                 {
00233                                         <span class="keywordflow">if</span>($rangeFields[$i] == <span class="charliteral">'*'</span>)
00234                                         {
00235                                                 <span class="keywordflow">continue</span>;
00236                                         }
00237 
00238                                         <span class="keywordflow">if</span>($ipFields[$i] != $rangeFields[$i])
00239                                         {
00240                                                 $match = <span class="keyword">false</span>;
00241                                                 <span class="keywordflow">break</span>;
00242                                         }
00243                                 }
00244 
00245                                 <span class="keywordflow">if</span>($match == <span class="keyword">true</span>)
00246                                 {
00247                                         <span class="keywordflow">return</span> <span class="keyword">true</span>;
00248                                 }
00249                         }
00250                 }
00251 
00252                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
00253         }
00254 }
00255 
00256 ?&gt;
</pre></div>    </div>
  </body>
</html>
Return current item: Aukyla Document Management System