<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://entorb.net//wiki/index.php?action=history&amp;feed=atom&amp;title=PHP</id>
	<title>PHP - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://entorb.net//wiki/index.php?action=history&amp;feed=atom&amp;title=PHP"/>
	<link rel="alternate" type="text/html" href="https://entorb.net//wiki/index.php?title=PHP&amp;action=history"/>
	<updated>2026-05-06T10:24:47Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>https://entorb.net//wiki/index.php?title=PHP&amp;diff=4860&amp;oldid=prev</id>
		<title>Torben at 20:27, 30 October 2024</title>
		<link rel="alternate" type="text/html" href="https://entorb.net//wiki/index.php?title=PHP&amp;diff=4860&amp;oldid=prev"/>
		<updated>2024-10-30T20:27:02Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[[Category:Coding]]&lt;br /&gt;
==Basics==&lt;br /&gt;
PHP Variables&lt;br /&gt;
 $DOCUMENT_ROOT&lt;br /&gt;
 $PHP_SELF&lt;br /&gt;
 $_GET[&amp;#039;url_param&amp;#039;]&lt;br /&gt;
 $_POST[&amp;#039;form_param&amp;#039;]&lt;br /&gt;
 $my_param = htmlentities($_POST[&amp;#039;form_param&amp;#039;]);&lt;br /&gt;
&lt;br /&gt;
Check variables&lt;br /&gt;
 is_numeric()&lt;br /&gt;
 is_file()&lt;br /&gt;
 is_dir()&lt;br /&gt;
&lt;br /&gt;
===Strings===&lt;br /&gt;
Usefull stuff&lt;br /&gt;
 strtolower&lt;br /&gt;
 strtoupper&lt;br /&gt;
 trim  // trims spaces at the ends of string &lt;br /&gt;
 nl2br // \n -&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 // Search in string&lt;br /&gt;
 ereg[i](was,wo);          // i: case insensitive&lt;br /&gt;
 // Replace chars&lt;br /&gt;
 ereg[i]_replace (was,womit,wo);  // i: case insensitive&lt;br /&gt;
 str_replace(was,womit,wo);       // case sensitive, works on arrays as well&lt;br /&gt;
 // Pos of substring&lt;br /&gt;
 strpos ($file_name,&amp;quot;.&amp;quot;[,startint]); // start from left&lt;br /&gt;
 strrpos($file_name,&amp;quot;.&amp;quot;[,startint]); // start from right&lt;br /&gt;
&lt;br /&gt;
 // Part of string&lt;br /&gt;
 $ext = strrchr($file_name,&amp;quot;.&amp;quot;);  // start from right and take all up to the end&lt;br /&gt;
 $filename = str[i]str($file_name,&amp;quot;.&amp;quot;); // start from left, i: case insensitive&lt;br /&gt;
 // Return a substring&lt;br /&gt;
 substr($string, pos [, number]); // pos can be negative&lt;br /&gt;
&lt;br /&gt;
Work on special chars&lt;br /&gt;
 stripslashes // removes \&lt;br /&gt;
 addslashes   // adds \ to &amp;quot; \ NULL&lt;br /&gt;
 quotemeta    // adds \ to . \\ + * ? [ ] ^ ( ) $ &lt;br /&gt;
 htmlentities // converts into HTML chars&lt;br /&gt;
 // Umlaute: utf8 -&amp;gt; htmlcode&lt;br /&gt;
 $text = htmlentities(utf8_decode($text));&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Arrays===&lt;br /&gt;
Split string to array&lt;br /&gt;
 explode(&amp;quot; und &amp;quot;,$str);&lt;br /&gt;
 split[i](&amp;quot; UnD &amp;quot;,$Str);  // i: case insensitive&lt;br /&gt;
Array to string&lt;br /&gt;
 implode(&amp;quot;, &amp;quot;,$moin);&lt;br /&gt;
&lt;br /&gt;
Sort&lt;br /&gt;
 sort($array);&lt;br /&gt;
 natsort($array); // 2 before 10&lt;br /&gt;
&lt;br /&gt;
Remove items&lt;br /&gt;
 unset($array[$x]);&lt;br /&gt;
 // nicer:&lt;br /&gt;
 $raus = array();&lt;br /&gt;
 $raus[] = $array[$x];&lt;br /&gt;
 $array = array_diff($array,$raus);&lt;br /&gt;
&lt;br /&gt;
 while (($id = array_search($what,$where))&amp;gt;-1)&lt;br /&gt;
   unset ($files[$id]);&lt;br /&gt;
&lt;br /&gt;
Remove duplicates&lt;br /&gt;
 $a = array_values(array_unique($a));&lt;br /&gt;
&lt;br /&gt;
Compare arrays&lt;br /&gt;
 $c = array_diff ($a, $b);&lt;br /&gt;
 $c = array_intersect ($a, $b);&lt;br /&gt;
 $c = array_merge ($a, $b);&lt;br /&gt;
&lt;br /&gt;
Print a hash&lt;br /&gt;
 foreach ($array as $key=&amp;gt;$val)&lt;br /&gt;
   echo &amp;quot;key = $key, val = $val&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
==Regular Expressions==&lt;br /&gt;
Special chars&lt;br /&gt;
 .  = 1 char&lt;br /&gt;
 .? = 0,1 chars&lt;br /&gt;
 .* = 0-oo chars&lt;br /&gt;
 .+ = 1-oo chars&lt;br /&gt;
&lt;br /&gt;
 \s = whitespace&lt;br /&gt;
 \S = no whitespace&lt;br /&gt;
 \w = word char (=a-z,0-9,_)&lt;br /&gt;
 \W = no word char&lt;br /&gt;
 \d = decimal number&lt;br /&gt;
 \D = no decimal number&lt;br /&gt;
 \b = word boundary&lt;br /&gt;
 \B = no word boundary&lt;br /&gt;
 \n = new line (Linux)&lt;br /&gt;
 \r = CR (Windows: \n\r)&lt;br /&gt;
&lt;br /&gt;
Options&lt;br /&gt;
 i = case insensitive&lt;br /&gt;
 e = execute php code inside expression&lt;br /&gt;
 s = single string, (search passes lineends)&lt;br /&gt;
 U = ungreegy&lt;br /&gt;
&lt;br /&gt;
Search&lt;br /&gt;
 eregi(&amp;#039;EXPRESSION&amp;#039;, $string)&lt;br /&gt;
 preg_match(&amp;quot;&amp;#039;EXPRESSION&amp;#039;is&amp;quot;, $where, $results);&lt;br /&gt;
 preg_match_all(&amp;quot;&amp;#039;EXPRESSION&amp;#039;is&amp;quot;, $where, $results);&lt;br /&gt;
 $result1 = $results[1];&lt;br /&gt;
 //Check eMail-Syntax&lt;br /&gt;
&lt;br /&gt;
Replace&lt;br /&gt;
 preg_replace($patterns, $replacements, $where);&lt;br /&gt;
 preg_replace(&amp;quot;&amp;#039;&amp;lt;title&amp;gt;[^&amp;lt;]*&amp;lt;/title&amp;gt;&amp;#039;is&amp;quot;,&amp;quot;&amp;quot;,$htmlinhalt);&lt;br /&gt;
&lt;br /&gt;
 $was = array();&lt;br /&gt;
 $womit = array();&lt;br /&gt;
  ..&lt;br /&gt;
 $text = preg_replace($was,$womit,$text);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Other Stuff==&lt;br /&gt;
 $date = date(&amp;quot;Y-m-d&amp;quot;); // Date to mysql format&lt;br /&gt;
&lt;br /&gt;
===Run External Command===&lt;br /&gt;
 exec(&amp;quot;command&amp;quot;); //waits until command is finnished&lt;br /&gt;
 exec(&amp;quot;command &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&amp;quot;); // ignores output, so php continues right away&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Images===&lt;br /&gt;
Read Image Size&lt;br /&gt;
 $array = getimagesize($file);&lt;br /&gt;
&lt;br /&gt;
===Char Encoding===&lt;br /&gt;
[http://htmlpurifier.org/docs/enduser-utf8.html]&lt;br /&gt;
The simplest way to handle this problem is to send the encoding yourself, via your programming language. The appropriate code is:&lt;br /&gt;
 header(&amp;#039;Content-Type:text/html; charset=UTF-8&amp;#039;);&lt;br /&gt;
This code must come before any output, so be careful about stray whitespace in your application (i.e., any whitespace before output excluding whitespace within &amp;lt;?php ?&amp;gt; tags).&lt;br /&gt;
&lt;br /&gt;
Encode spaces etc from a string for usage as url-paramter:&lt;br /&gt;
 $file = rawurlencode ($file);&lt;br /&gt;
 $file = rawurldecode ($file);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Functions==&lt;br /&gt;
 function delTree($dir) {&lt;br /&gt;
      $files = glob( $dir . &amp;#039;*&amp;#039;, GLOB_MARK );&lt;br /&gt;
      foreach( $files as $file ){&lt;br /&gt;
          if( is_dir( $file ) )&lt;br /&gt;
              delTree( $file );&lt;br /&gt;
          else&lt;br /&gt;
              unlink( $file );&lt;br /&gt;
      }&lt;br /&gt;
      if (is_dir($dir)) rmdir( $dir );&lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
 function recurse_chown_chgrp($mypath, $uid, $gid) {&lt;br /&gt;
   $d = opendir ($mypath) ;&lt;br /&gt;
   while(($file = readdir($d)) !== false) {&lt;br /&gt;
     if ($file != &amp;quot;.&amp;quot; &amp;amp;&amp;amp; $file != &amp;quot;..&amp;quot;) {&lt;br /&gt;
       $typepath = $mypath . &amp;quot;/&amp;quot; . $file ;&lt;br /&gt;
       if (filetype ($typepath) == &amp;#039;dir&amp;#039;) {&lt;br /&gt;
         recurse_chown_chgrp ($typepath, $uid, $gid); }&lt;br /&gt;
       chown($typepath, $uid);&lt;br /&gt;
       chgrp($typepath, $gid);&lt;br /&gt;
 } } }&lt;br /&gt;
 &lt;br /&gt;
 function recurse_chmod($mypath, $mod) {&lt;br /&gt;
   $d = opendir ($mypath) ;&lt;br /&gt;
   while(($file = readdir($d)) !== false) {&lt;br /&gt;
     if ($file != &amp;quot;.&amp;quot; &amp;amp;&amp;amp; $file != &amp;quot;..&amp;quot;) {&lt;br /&gt;
       $typepath = $mypath . &amp;quot;/&amp;quot; . $file ;&lt;br /&gt;
       if (filetype ($typepath) == &amp;#039;dir&amp;#039;) {&lt;br /&gt;
         recurse_chmod ($typepath, $mod); }&lt;br /&gt;
       chmod($typepath, $mod);&lt;br /&gt;
 } } }&lt;br /&gt;
&lt;br /&gt;
==Login==&lt;br /&gt;
 function auth()&lt;br /&gt;
 {&lt;br /&gt;
 header(&amp;#039;WWW-authenticate: basic realm=&amp;quot;Name of realm&amp;quot;&amp;#039;);&lt;br /&gt;
 header(&amp;#039;HTTP/1.0 401 Unauthorized&amp;#039;);&lt;br /&gt;
 exit(&amp;quot;text...&amp;quot;);  &lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 // username / passwd in $PHP_AUTH_USER / $PHP_AUTH_PW&lt;br /&gt;
 if(!isset($PHP_AUTH_USER))&lt;br /&gt;
   auth();&lt;br /&gt;
 else {&lt;br /&gt;
  // check if $PHP_AUTH_USER / $PHP_AUTH_PW are fine. If not run auth()&lt;br /&gt;
 }&lt;/div&gt;</summary>
		<author><name>Torben</name></author>
	</entry>
</feed>