\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{Torvak} \pdfinfo{ /Title (php.pdf) /Creator (Cheatography) /Author (Torvak) /Subject (php Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{453BA3} \definecolor{LightBackground}{HTML}{F3F2F9} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{php Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Torvak} via \textcolor{DarkBackground}{\uline{cheatography.com/32041/cs/9809/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}Torvak \\ \uline{cheatography.com/torvak} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 4th December, 2016.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{3} \begin{tabularx}{5.377cm}{x{2.33919 cm} x{2.63781 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Type managment functions}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{`is\_array()`} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} `is\_double(), is\_float(), is\_real()` & same function \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} `is\_long(), is\_int(), is\_integer()` & same function \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{`is\_string()`} \tn % Row Count 6 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{`is\_null()`} \tn % Row Count 7 (+ 1) % Row 5 \SetRowColor{white} `is\_scalar()` & if \$var is a whole number, a string or a double \tn % Row Count 10 (+ 3) % Row 6 \SetRowColor{LightBackground} `is\_numeric()` & is \$var. is a number or a numerical chain \tn % Row Count 12 (+ 2) % Row 7 \SetRowColor{white} `is\_callable()` & if \$var. is a valid function name \tn % Row Count 14 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.96811 cm} x{1.69349 cm} x{0.9154 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{5.377cm}}{\bf\textcolor{white}{Data type conversion}} \tn % Row 0 \SetRowColor{LightBackground} `int intval(var)` & \seqsplit{`intval('042')`} & Ret: 42 \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} `float floatval(var)` & \seqsplit{`floatval('a1.2')`} & Ret: 1.2 \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} `string strval(var)` & `strval(1.2)` & Ret: '1.2' \tn % Row Count 6 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.89126 cm} x{3.08574 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Varible scope and constant definition}} \tn % Row 0 \SetRowColor{LightBackground} `global myVar` & Will exists beyond its scope \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} `define("X", 3);` & Ex: echo 'Value'.PI; \tn % Row Count 4 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{PHP variables need not be declared in advance before being used} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{0.84609 cm} x{4.13091 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{File system Modes}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{`r`}} & read-only from start (File pointer starts at the beginning of the file) \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} {\bf{`r+`}} & read-write from start \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{`w`}} & write-only (Erases the contents of the file or creates a new file if it doesn't exist. File pointer starts at the beginning of the file) \tn % Row Count 10 (+ 5) % Row 3 \SetRowColor{white} {\bf{`w+`}} & read-write (erases content from file and creates it if it desn't exist) \tn % Row Count 13 (+ 3) % Row 4 \SetRowColor{LightBackground} {\bf{`a`}} & append-only to EOF (existing data is preserved, creates new file if doesn't exist) \tn % Row Count 16 (+ 3) % Row 5 \SetRowColor{white} {\bf{`a+`}} & read-write - append to EOF \tn % Row Count 18 (+ 2) % Row 6 \SetRowColor{LightBackground} {\bf{`x`}} & create new file for write only (ret. FALSE an ERROR if file already exists) \tn % Row Count 21 (+ 3) % Row 7 \SetRowColor{white} {\bf{`x+`}} & creates a new file for read/write (ret. FALSE an ERROR if file already exists) \tn % Row Count 24 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{fseek() can only work in mode {\bf{w+}} and NOT with {\bf{a}} or {\bf{a++}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{0.9954 cm} x{3.9816 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Functions indicating the state of the variables}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{`isset()`} & if the var. exists \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{`unset()`} & removes the var. passed in parameter \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \seqsplit{`empty()`} & return true if var. is null \tn % Row Count 6 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Get variables from \$\_FILES}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`{[}'OBJ FILE NAME'{]}{[}'name'{]}` -\textgreater{} gets name of file selected in a file {\bf{object}}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`{[}'OBJ FILE NAME'{]}{[}'tmp\_name'{]}` -\textgreater{} gets temp name saved in server, waiting for destination transfer} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`{[}'OBJ FILE NAME'{]}{[}'size'{]}` -\textgreater{} gets the file's size in octets} \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`{[}'OBJ FILE NAME'{]}{[}'type'{]}` -\textgreater{} gets the MIME type of the file} \tn % Row Count 8 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`{\bf{// File example}} \{\{nl\}\}foreach(\$\_FILES as \$curImg =\textgreater{} \$photo)\{\{\{nl\}\}\$file = \$\_FILES{[}\$curImg{]}{[}"name"{]}; {\bf{{\emph{//img.jpeg}}}}\{\{nl\}\}\$tmpName = \$\_FILES{[}\$curImg{]}{[}"tmp\_name"{]}; {\bf{{\emph{//tmp/phps6L}}}}\{\{nl\}\}\$size = \seqsplit{filesize(\$tmpName)/1024;} {\bf{{\emph{//43}}}}\{\{nl\}\}\$ext = pathinfo(\$file, PATHINFO\_EXTENSION); {\bf{{\emph{//jpeg}}}}\{\{nl\}\}\$type = filetype(\$tmpName); {\bf{{\emph{//file}}}}\{\{nl\}\}\$mimeType = \$\_FILES{[}\$curImg{]}{[}"type"{]}; {\bf{{\emph{//image/jpeg}}}}\{\{nl\}\}\}\{\{nl\}\}move\_uploaded\_file(\$tmpName, "\$path\$file"))`\{\{nl\}\}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.43873 cm} x{2.53827 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{String functions}} \tn % Row 0 \SetRowColor{LightBackground} `explode('sep', 'str')` & Ret. array without 'sep' \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{`implode(glue, arr)`} \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} `strlen(str)` & Ret. length of string \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{`substr(str, start, len)`} \tn % Row Count 6 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{`strtolower(str)`} \tn % Row Count 7 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{`strtoupper(str)`} \tn % Row Count 8 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{`nl2br(str)`} \tn % Row Count 9 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{`sprintf(frmt, args)`} \tn % Row Count 10 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{`strip\_tags(str,allowed\_tags)`} \tn % Row Count 11 (+ 1) % Row 9 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{`strpos(str,needle)`} \tn % Row Count 12 (+ 1) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{`strrev(str)`} \tn % Row Count 13 (+ 1) % Row 11 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{`strstr(str,needle)`} \tn % Row Count 14 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{`{\bf{//Exemple of substr de \$adresse = 127.0.0.1}} \{\{nl\}\}\$class = substr(\$adresse, 0, 3) // {\bf{{\emph{=\textgreater{} 127}}}}\{\{nl\}\}\$class = substr(\$adresse, 3) // {\bf{{\emph{=\textgreater{} .0.0.1}}}}\{\{nl\}\}\$class = substr(\$adresse, -3); // {\bf{{\emph{=\textgreater{} 0.1}}}}\{\{nl\}\}\$class = substr(\$adresse, 0, -3); // {\bf{{\emph{=\textgreater{} 127.0.}}}}\{\{nl\}\}`} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.38896 cm} x{2.58804 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Code reusability}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{`require('script.php')`} & Stops script if {\bf{error}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{\seqsplit{`require\_once('script.ph')`}} \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} \seqsplit{`include('script.php')`} & Warning if {\bf{error}} \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{\seqsplit{`include\_once('script.php')`}} \tn % Row Count 6 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{\_once -\textgreater{} makes sure that the code will be included or re-evaluated only once} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.64241 cm} x{3.33459 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{PHP Information}} \tn % Row 0 \SetRowColor{LightBackground} `phpinfo()` & Version of PHP + infos \tn % Row Count 1 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Image generation}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`header('Content-type: image/jpeg')`} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`\$img = ImageCreate(width, height)`} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`\$img = \seqsplit{ImageCreateTrueColor(width}, height)`} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`\$img = ImageCreateFrom{[}PNG|JPEG|GIF{]}('imgname');` //create from existing image} \tn % Row Count 5 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{`ImageColorAllocate(\$img}, r,v,b) // rvb in 0 to 255`} \tn % Row Count 7 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`Imagegammacorrect(\$img, int gamma\_in,int gamma\_out)`} \tn % Row Count 9 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`ImageFill(\$img, x start, y start, color)`} \tn % Row Count 10 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{`imagefilledrectangle(\$img}, \$x1, \$y1, \$x2, \$y2, \$color);`} \tn % Row Count 12 (+ 2) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`imagestring(\$img, \$font, \$x, \$y, \$string, \$color);`} \tn % Row Count 14 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`\textless{}?php\{\{nl\}\}header("Content-Type: image/png");\{\{nl\}\}\$im = imagecreate(110, 20);\{\{nl\}\}\$background\_color = imagecolorallocate(\$im, 0, 0, 0);\{\{nl\}\}\$text\_color = imagecolorallocate(\$im, 233, 14, 91);\{\{nl\}\}imagestring(\$im, 1, 5, 5, "A Simple Text String", \$text\_color);\{\{nl\}\}imagepng(\$im);\{\{nl\}\}imagedestroy(\$im);\{\{nl\}\}?\textgreater{}`} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.58804 cm} x{2.38896 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Arrays}} \tn % Row 0 \SetRowColor{LightBackground} `\$array{[}{]} = "a"` & No need to specifiy index \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} `count(array)` & Nb. elements in array \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} `sizeof(array)` & Nb. elements in array \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \seqsplit{`array\_count\_value(array)`} & value=\textgreater{}freq \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{`array\_diff(arr1,arr2)`} \tn % Row Count 9 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{`array\_filter(arr,function)`} \tn % Row Count 10 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{`array\_flip(arr)`} \tn % Row Count 11 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{`array\_intersect(arr1,arr2)`} \tn % Row Count 12 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{`array\_merge(arr1,arr2)`} \tn % Row Count 13 (+ 1) % Row 9 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{`array\_pop(\$arr)`} \tn % Row Count 14 (+ 1) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{`array\_push(arr,var1, var2...)`} \tn % Row Count 15 (+ 1) % Row 11 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{`array\_reverse(arr)`} \tn % Row Count 16 (+ 1) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{`array\_search(needle, arr)`} \tn % Row Count 17 (+ 1) % Row 13 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{`array\_walk(arr,function)`} \tn % Row Count 18 (+ 1) % Row 14 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{`in\_array(needle,haystack)`} \tn % Row Count 19 (+ 1) % Row 15 \SetRowColor{white} `sort(arr)` & smaller \textless{} bigger \tn % Row Count 20 (+ 1) % Row 16 \SetRowColor{LightBackground} `rsort(arr)` & bigger \textgreater{} smaller \tn % Row Count 21 (+ 1) % Row 17 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{`foreach (array\_expression as \$value) \{\{nl\}\} statement\{\{nl\}\} foreach (array\_expression as \$key =\textgreater{} \$value) \{\{nl\}\} statement`} \tn % Row Count 24 (+ 3) % Row 18 \SetRowColor{LightBackground} \seqsplit{`array\_slice(\$array}, 0, 3); & returns first 3 elements \tn % Row Count 26 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{{\bf{//Use of array\_slice()}} \newline `\$input = array("a", "b", "c", "d", "e");\{\{nl\}\}\$output = array\_slice(\$input, 2);` {\emph{ // returns "c", "d", and "e"}}\{\{nl\}\} `\$output = array\_slice(\$input, -2, 1);` {\emph{// returns "d"}} \{\{nl\}\}`\$output = array\_slice(\$input, 0, 3);` {\emph{//returns "a", "b", and "c"}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.43873 cm} x{2.53827 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{PHP integrated arrays}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{`\$\_GET`} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{`\$\_POST`} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{`\$\_FILES`} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{`\$\_COOKIES`} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{`\$\_SESSION`} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{`\$\_ENV`} \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{`\$\_SERVER`} \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} `extract(arr,type, pref)` & get vals. from assoc. arr; \tn % Row Count 9 (+ 2) % Row 8 \SetRowColor{LightBackground} `EXTR\_OVERWRITE` & ow existing vars. \tn % Row Count 10 (+ 1) % Row 9 \SetRowColor{white} `EXTR\_SKIP` & won't ow existing vars \tn % Row Count 12 (+ 2) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{`EXTR\_PREFIX\_ALL`} \tn % Row Count 13 (+ 1) % Row 11 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{`EXTR\_PREFIX\_INVALID`} \tn % Row Count 14 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{To get values easily from theses arrays, use function extract(). If we have: \newline \textgreater{} \$\_POST{[}'name'{]} \newline \textgreater{} \$\_POST{[}'surname'{]} \newline Using the function: extract(\$\_POST, EXTR\_OVERWRITE) will give us: \newline \textgreater{}\$name \newline \textgreater{}\$surname \newline -{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}-{}- \newline \textgreater{}EXTR\_PREFIX\_ALL // create new vars. with the prefix spcified in 3rd param for all keys present in the array \newline \textgreater{}EXTR\_PRERFIX\_ALL // creates new vars. with prefix specified in 3rd param only for invalid exsting variable names such as \$1} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.04057 cm} x{2.93643 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Environnement variables from \$\_SERVER}} \tn % Row 0 \SetRowColor{LightBackground} `PHP\_SELF` & path to curr. script \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} `SERVER\_NAME` & Ex: Localhost \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} `DOCUMENT\_ROOT` & root of curr.script \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} `REMOTE\_ADDR` & IP requesting curr. page \tn % Row Count 5 (+ 2) % Row 4 \SetRowColor{LightBackground} `REMOTE\_PORT` & client port -\textgreater{} server \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} \seqsplit{`SCRIPT\_FILENAME`} & abs. path to curr.script \tn % Row Count 8 (+ 2) % Row 6 \SetRowColor{LightBackground} `SERVER\_PORT` & Server port used \tn % Row Count 9 (+ 1) % Row 7 \SetRowColor{white} `REQUEST\_URI` & URI is for page access \tn % Row Count 10 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{\textgreater{}PHP\_SELF //return value is relative to root document \newline \textgreater{}SERVER\_PORT //server port used for communication (usually :80 but if using SSL can be replaced par number of secured HTTP \newline \textgreater{}REQUEST\_URI // can be for example '/index.html'} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.43873 cm} x{2.53827 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{File System Functions}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{`fopen('filename', 'mode')`} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{`fclose(\$handle)`} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} `fgets(\$handle, \$len)` & {\emph{ without 2nd param, fgets read line till EOL}} \tn % Row Count 5 (+ 3) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{`fputs(\$handle, 'str')`} \tn % Row Count 6 (+ 1) % Row 4 \SetRowColor{LightBackground} \seqsplit{`file('folder/file')`} & {\emph{can also be url}} \tn % Row Count 8 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{`copy(source, dest)`} \tn % Row Count 9 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{`filemtime(file)`} \tn % Row Count 10 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{\seqsplit{`filesize('folder/file')`}} \tn % Row Count 11 (+ 1) % Row 8 \SetRowColor{LightBackground} \seqsplit{`file\_exists(file)`} & {\bf{doesn't work with HTTP or FTP}} \tn % Row Count 13 (+ 2) % Row 9 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{`fread(handle, len)`} \tn % Row Count 14 (+ 1) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{`fwrite(handle, str)`} \tn % Row Count 15 (+ 1) % Row 11 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{`readfile(file)`} \tn % Row Count 16 (+ 1) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{`fgetcsv(handle,len,sep)`} \tn % Row Count 17 (+ 1) % Row 13 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{`fputcsv()`} \tn % Row Count 18 (+ 1) % Row 14 \SetRowColor{LightBackground} `fseek(handle,offset)` & goto line of curr. offset (needs {\bf{r+}} or {\bf{rw+}} mode) \tn % Row Count 21 (+ 3) % Row 15 \SetRowColor{white} `rewind(handle)` & goto start of file \tn % Row Count 22 (+ 1) % Row 16 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{`chmod(file, unix rights)`} \tn % Row Count 23 (+ 1) % Row 17 \SetRowColor{white} `unlink('file name')` & deletes file \tn % Row Count 25 (+ 2) % Row 18 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{`is\_link('filename')`} \tn % Row Count 26 (+ 1) % Row 19 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{\seqsplit{`is\_writeable('filename')`}} \tn % Row Count 27 (+ 1) % Row 20 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{\seqsplit{`is\_readable('filename')`}} \tn % Row Count 28 (+ 1) % Row 21 \SetRowColor{white} `pathinfo(\$file, \seqsplit{PATHINFO\_EXTENSION);`} & Ret. ex: pdf \tn % Row Count 30 (+ 2) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{2.43873 cm} x{2.53827 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{File System Functions (cont)}} \tn % Row 22 \SetRowColor{LightBackground} `filetype(\$file)` & Ret: {\bf{file}} or {\bf{dir}} \tn % Row Count 2 (+ 2) % Row 23 \SetRowColor{white} \seqsplit{`filesize(\$file)/1024`} & Ret. file size ( / 1024 to convert to octets) \tn % Row Count 5 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{`{\bf{//Example of openinng a file:}} \{\{nl\}\}\$handle = fopen("file.txt", "w");\{\{nl\}\}if (!\$handle) \{\{\{nl\}\}echo 'Can't create file';\{\{nl\}\}exit;\{\{nl\}\}\}\{\{nl\}\}else \{\{\{nl\}\}while(!feof(\$handle)) \{\{\{nl\}\}\$line = fgets(\$handle, 255);\{\{nl\}\}fputs(\$handle, \$line.'suffix');\{\{nl\}\}\$appendLine = fgets(\$handle, 255);\{\{nl\}\}echo \$appendLine.'\textless{}br\textgreater{}';\{\{nl\}\}\}\{\{nl\}\}fclose(\$handle);`} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.18988 cm} x{2.78712 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Folder system functions}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{`is\_dir('folder name')`} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{`opendir('folder name')`} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{`readdir(handle)`} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} `scandir('folder name')` & Returns array of folder content \tn % Row Count 5 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{`{\bf{{\emph{//Example with opendir}}}}\{\{nl\}\}\$dir = "/etc/php5/"; \{\{nl\}\}if (is\_dir(\$dir)) \{\{\{nl\}\}if (\$dh = opendir(\$dir)) \{\{\{nl\}\}while ((\$file = readdir(\$dh)) !== false) \{\{\{nl\}\}echo "filename: \$file : filetype: " . filetype(\$dir . \$file) . "\textbackslash{}n";\{\{nl\}\}\}\{\{nl\}\}closedir(\$dh)\{\{nl\}\}\}\{\{nl\}\}\}\{\{nl\}\}{\bf{{\emph{Example with scandir()}}}}\{\{nl\}\}\$nomDossier = 'dossier';\{\{nl\}\}\$tableContDossier = scandir(\$nomDossier);\{\{nl\}\}foreach(\$tableContDossier as \$fic) \{\{\{nl\}\}echo \$fic.'\textless{}br\textgreater{}';\{\{nl\}\}\}`} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{File transfert functions}} \tn % Row 0 \SetRowColor{LightBackground} `is\_uploaded\_file(\$\_FILES{[}'fichier'{]}{[}'tmp\_name'{]}` & verify file presence in tmp folder \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \seqsplit{`move\_uploaded\_file('filename'},'path/filename')` & Checks is file comes from tmp folder unlike fonction copy() \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{`copy('filename','path/filename')`} \tn % Row Count 7 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Database connection}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`mysqli\_connect('host', 'user', 'pass') or die ("Can't establish connecion to databse")`} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{`mysqli\_select('databsename');`}} \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`\$queryResult = mysqli\_query("SELECT * FROM table");`} \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`mysqli\_error() // boolean to return error if table doesn't exist`} \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`\$row = \seqsplit{mysql\_fetch\_array(\$result}, MYSQL\_ASSOC)`} \tn % Row Count 8 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`mysqli\_list\_db()`} \tn % Row Count 9 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`mysqli\_list\_tables()`} \tn % Row Count 10 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`mysqli\_num\_rows() //ret. nb. rows from query`} \tn % Row Count 11 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Example fetching array values: \newline while (\$row = \seqsplit{mysql\_fetch\_array(\$result}, MYSQL\_ASSOC) \{ \newline \$name = \$row{[}'name'{]}; \newline \$country = \$row{[}'country'{]}; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{PHP regular expressions}} \tn % Row 0 \SetRowColor{LightBackground} Check if {\bf{`\$string`}} matches {\bf{`\$expression`}} & \seqsplit{`preg\_match('(docx|doc|xls|pptx)'}, \$extension);` \tn % Row Count 3 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{PHP regular expressions}} \tn % Row 0 \SetRowColor{LightBackground} Check if {\bf{`\$extension`}} is either "docx", "doc", "xls" or "pptx" & \seqsplit{`preg\_match('(docx|doc|xls|pptx)'}, \$extension);` \tn % Row Count 4 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}