PHP examples (example source code) Organized by topic





Form /

File Upload 5Form Action 1
Form based Email 2Form Based Query 1
Form Checkbox 5Form Data 10
Form Post 8Form Select 14
Form TextArea 1Form Validation 7
Form 10Hidden Field 3
is_uploaded_file 2Query String 5
Radio Button 3Self Call Form 2
TextBox 4urlencode 1
_GET 4_POST 7
_SERVER 9

Login Authentication /

Authentication 1Browser Password Dialog 2
Cookie based Login 1File Based Authentication 1
ID Generate 1Login Form 8
md5 3User Registration 2

HTML /

Authentication 17Content Types 1
get_html_translation_table 3get_meta_tags 1
header 15headers_sent 1
HTML Cohabitation 2HTML File 1
HTML Font 2HTML String 3
HTML Table 4HTML 10
htmlentities 6htmlspecialchars 4
html_entity_decode 1http_build_query 1
HTTP_REFERER 1HTTP_Request 1
HTTP_USER_AGENT 6Hyperlink 1
PATH_INFO 1rawurldecode 2
REMOTE_ADDR 1Table Utilities 2
tidy_clean_repair 1tidy_parse_file 4
tidy_parse_string 3Web Color 1
_FILES 2

XML /

DOM Edit 1DomDocument 20
domxml_xslt_stylesheet_file 1mcrypt_create_iv 1
mcrypt_encrypt 1RSS 1
SAX 3simplexml_load_string 16
var_dump 3var_export 1
XML Attributes 1XML Content 2
XML DOM Tree 1XML File Read 3
XML Handler 3XML Path 2
XML Transformation 2XML Validation 1
xpath 9XSLTProcessor 4
xslt_process 1

MySQL Database /

Choose Database 1Database Connection 2
Database Create 1Database Delete 2
Database Insert 3Database MetaData 6
Database Query 5Database Update 3
DBM 3MySQL Connection 4
MySQL Processes 1mysqli 14
mysqli_autocommit 1mysqli_connect 5
mysqli_error 1mysqli_fetch_array 2
mysqli_prepare 1mysql_affected_row 1
mysql_close 2mysql_connect 5
mysql_db_query 2mysql_drop_db 1
mysql_fetch_array 7mysql_fetch_assoc 1
mysql_fetch_field 1mysql_fetch_row 2
mysql_field_name 1mysql_field_table 1
mysql_field_type 1mysql_list_processes 1
mysql_list_tables 2mysql_num_fields 2
mysql_num_rows 5mysql_query 9
mysql_real_escape_string 1mysql_result 3
mysql_select_db 6mysql_stat 1
mysql_tablename 2mysql_unbuffered_query 1
odbc_close 1odbc_connect 2
odbc_exec 1odbc_execute 1
odbc_free_result 1odbc_prepare 1
odbc_result_all 1Query Result 9
SQL String 1sqlite database 4
sqlite_array_query 1sqlite_column 1
sqlite_create_function 1sqlite_current 1
sqlite_fetch_array 2sqlite_fetch_column_types 1
sqlite_fetch_single 1sqlite_field_name 1
sqlite_has_more 1sqlite_num_fields 1
sqlite_num_rows 1sqlite_popen 1
sqlite_query 3sqlite_seek 2
sql_regcase 1Table Column 2
Table Create 4Table Database 2
Table MetaData 5

Cookie Session /

Cookie 4Session Encode 1
Session ID 1Session Start 1
Session Variables Create 2Session Variables Delete 2
Session Variables Modify 1Session Variables Register 2
Session Variables Unregister 1Session Variables 10
session_decode 1session_destroy 3
session_encode 1session_id 3
session_is_registered 1session_register 1
session_set_save_handler 1session_start 6
setcookie 15_COOKIE 7
_SESSION 14

File Directory /

basename 2chgrp 1
chmod 4chown 1
copy 5CSV File 9
Directory Create Delete 3Directory 9
dirname 2Disk Drive 3
disk_free_space 1disk_total_space 1
fclose 2feof 4
fflush 1fgetc 2
fgets 10fgetss 3
File Close 1File Copy Move 2
File Delete 1File Exist 1
file function 3File Lock 1
File Open 1File Property 17
File Read 7File Seek 1
File Upload 5File Write 3
File 3fileatime 2
filectime 2filegroup 1
filemtime 3fileowner 2
fileperms 1filesize 3
file_exists 5file_get_contents 9
file_put_contents 3flock 4
fopen 22fputs 4
fread 6fscanf 3
fseek 3fsockopen 7
fwrite 7getcwd 1
getlastmod 5glob 3
is_dir 4is_executable 2
is_file 2is_link 1
is_readable 3is_writable 3
mkdir 2move_uploaded_file 1
opendir 2Path 1
pathinfo 2popen 9
readdir 3readfile 2
readlink 1realpath 2
rename 3rewind 1
rmdir 1scandir 3
stat 4Stream Context 1
Stream Filter 2stream_filter_append 1
symlink 3tempnam 1
Temporary file 3Text File Read 8
Text File Write 2Text File 1
touch 3unlink 8
virtual 1_FILE 2
__LINE 2

Email /

Email Address 1Email Validation 2
mail function 5

Math /

abs 3acos 1
asin 1atan 1
base_convert 3BCMath 2
ceil 1cos 1
decbin 2dechex 1
decoct 1define 3
deg2rad 2exp 1
floor 1getrandmax 1
hexdec 1log 3
Math Functions 8Math 5
max 1min 1
mt_getrandmax 1mt_rand 10
pow 3rad2deg 1
rand 5Random 2
round 3Scientific Notation 1
sin 1sqrt 1
tan 1

String /

addslashes 1chdir 1
chop 1chr 1
count_chars 2curl_init 2
Email Format 3ereg 6
eregi 4ereg_replace 6
gmp_strval 1here document 5
is_string 1levenshtein 1
ltrim 3metaphone 1
New Line 1ord 1
preg_grep 4preg_match 33
preg_match_all 15preg_quote 1
preg_replace 23preg_replace_callback 3
preg_split 10Quotation 8
Regular Expressions 38Replace 2
rtrim 2similar_text 2
soundex 3split 4
sprintf 9strcasecmp 4
strcmp 5strcspn 4
String Case 5String Compare 5
String Concatenation 6String Contains 1
String Count 2String Escape 4
String Find 2String Interpolation 5
String Length 2String Matches 8
String Operators 2String Pad 2
String Repeat 1String Replace 7
String Split 2String Token 5
String Trim Chop 6String 17
stripslashes 1strip_tags 8
stristr 2strlen 6
strpos 2strrev 4
strrpos 12strspn 4
strstr 6strtok 4
strtolower 5strtotime 12
strtoupper 7strval 2
str_ireplace 2str_pad 9
str_replace 11str_split 1
str_word_count 3Sub string 9
substr 23substr_count 4
substr_replace 7trim 4
ucfirst 4ucwords 7
wordwrap 7

Utility Function /

apache_note 2argv 2
base64_decode 1connection_status 1
curl_setopt 1dl 1
echo 11escapeshellarg 1
escapeshellcmd 4eval 1
exec 3exit 2
getenv 1get_browser 1
get_extension_funcs 1get_loaded_extensions 1
hash 1ignore_user_abort 1
include 6include_once 3
ini_get 2ini_get_all 3
ini_set 1list 4
mail 14mcrypt_encrypt 2
mcrypt_enc_get_iv_size 1mcrypt_enc_get_key_size 1
md5 8mhash 2
nl2br 5ob_start 2
output_add_rewrite_var 1output_reset_rewrite_vars 1
pack 2parse_ini_file 1
parse_str 2passthru 4
PEAR 3phpinfo 1
print 9printf 28
print_r 2putenv 2
range 5register_shutdown_function 2
require 2require_once 1
serialize 4setlocale 11
set_time_limit 1sha1 3
shell_exec 2shmop Functions 2
sleep 1SWFMovie 2
system 4umask 1
uniqid 3unserialize 3
usleep 1WDDX 2
_ENV 4

Graphics Image /

Arc 1Circle 2
Draw String 5Ellipse 3
Font 1Image Color 3
Image Create 1Image Font 2
Image Paint 1imagearc 2
imagecolorallocate 3imagecolorallocatealpha 1
imagecolorexact 1imagecolortransparent 3
imagecopymerge 1imagecopyresized 1
imagecreatefromgif 1imagecreatefromjpeg 2
imagecreatefrompng 3imagecreatetruecolor 1
imagedeallocate 1imageellipse 1
imagefill 1imagefilledarc 3
imagefilledellipse 2imagefilledpolygon 2
imagefilledrectangle 4imagefilltoborder 1
imagefilter 7imagegif 1
imageinterlace 1imagejpeg 3
imageline 1imagepng 2
imagepolygon 1imageRectangle 1
imagesetbrush 2imagesetpixel 1
imagesetstyle 1imagesettile 1
imagestring 1imagettfbbox 3
imagettftext 4imagetypes 1
image_type_to_mime_type 1JPG Image 2
Line 3Paint String 1
Rectangle 2Round Rectangle 1
Text Align 1Transparent 1
Triangler 1TrueType Fonts 2
Water Mark 1

Components /

Feedback Form 1Page Counter 2
Registration Form 1

Chart /

Bar Chart 1Pie Chart 1

Class /

Abstract Class 5Class Constant Property 3
Class Constructor 1Class Definition 14
Class Inheritance 5Class Instance 1
Class Method 13Class Property 10
Class Static Properties 1clone 7
const 5Constructor 15
Destructors 7extends 1
final 5Getter Setter 3
Inheritance 14instance of 2
Interface 7Method Override 4
Object Attribute 2object 1
Objects 8private 8
Properties get 1Properties set 2
protected 5public 5
Reflection Class Definition 8Reflection Class Hiearchy 2
Reflection Class Methods 9Reflection Constructor 1
Reflection Existance 2Reflection Invoke 2
self 1static properties 5
this 4toString 1
__autoload 5__call 3
__clone 2__get 3
__set 1__sleep 2
__toString 3__wakeup 2

Design Patterns /

Composite Pattern 1Decorator Pattern 1
Factory Pattern 1Request Info 4
Singleton Pattern 2Strategy Pattern 1

Language Basics /

Assertion 2Comments 11
Constant 1Define Constant 1
Exit 1Global 3
GLOBALS 8Include 4
instanceof 2Modulus 1
Php Functions 5Php Script 15
Php Tag 5phpcredits 1
PNG 2Polygon 1
Pre Defined Constant 2Reference 4
static variables 5Static 2
Variable Reference 6Variable Scope 11
Variable Set Unset 5Variable Type 3
Variables 11

Development /

Apache 1Client Info 5
CSV 4date function 2
Date Time 9Debug 1
Echo 7Error Obtrusive Messages 1
Error Report 1Exceptions 2
Explode implode 5GET POST 1
getdate 12HTTP_POST_VARS 1
I18N Locale 2include path 1
list 2max_execution_time 1
mktime 1Number Format 3
Php Environment 4Print 6
Printf 20print_r 3
Query String 3Server Info 3
sprintf 5System Command 9
System Log 1Your own Exceptions 1

Data Structure /

Array Element 17Array Function 33
Array Index 5Array List 1
Array Loop 11Array range 3
Array sort 30array 15
array_chunk 1array_combine 2
array_count_values 3array_diff 3
array_diff_assoc 1array_filter 5
array_flip 5array_insert 2
array_intersect 5array_keys 4
array_key_exists 4array_map 3
array_merge 9array_merge_recursive 1
array_multisort 2array_pad 9
array_pop 3array_push 6
array_rand 3array_remove 2
array_reverse 5array_search 1
array_shift 4array_slice 3
array_splice 9array_sum 2
array_unique 3array_unshift 4
array_values 4array_walk 3
arsort 4asort 6
Associate Array 30compact 1
count 4each 2
explode 10extract 8
implode 9in_array 5
is_array 1krsort 2
kshuffle 1Multidimensional Array 14
Nested Array 1reset 1
rsort 2shuffle 3
sizeof 1Stack 4
unpack 2usort 2

Functions /

call_user_func 1create_function 2
Definition 19Dynamic Function 11
Function Recursion 6function_exists 2
func_get_args 1func_num_args 3
is_callable 1Nested Functions 1
Override 2Parameters 24
Return Value 18

Statement /

break statement 9continue 6
do while 8Exception 4
for loop 24foreach 10
If statement 24switch statement 13
throw 1While loop 11

Reflection /

class_exists 2class_implements 1
class_parents 1gettype 2
get_class 1get_class_methods 2
get_class_vars 1get_declared_classes 2
get_declared_interfaces 2get_object_vars 2
get_parent_class 1interface_exists 1
is_a 2is_float 1
is_int 1is_numeric 2
is_string 2method_exists 1
ReflectionClass 1

Operator /

Arithmetic Operators 18Assignment Operators 4
Bitwise Operators 3Boolean Operators 1
Comparison Operators 10Conditional Operator 4
Logical Operators 15Operator Precedence 5

Data Type /

Binary Number 2boolean 4
Casting 16Char 2
ctype_digit 1Data Type 9
empty 1Float 19
floatval 1Hexadecimal Number 2
Integer 21intval 3
isset 5money_format 2
number_format 8Octal Number 2
settype 2unset 6
var_dump 1

Date /

cal_from_jd 1cal_to_jd 3
checkdate 2date 26
date_default_timezone_set 2getdate 6
getservbyname 2getservbyport 2
gettimeofday 1gmmktime 3
gmstrftime 2localtime 5
microtime 2mktime 10
strftime 19time 4

Network /

checkdnsrr 2DNS Validation 1
DNS 4dns_get_record 2
Domain Name 1FTP Functions 7
getmxrr 1getprotobyname 1
getprotobynumber 1IP Address 1
openssl_public_encrypt 1Port 1
SOAP Client 2SOAP Server 3
Socket 4socket_create 4
socket_create_listen 1stream_get_line 1
stream_socket_server 1URL Encoding 1
URL Redirect 2URL Validation 1
wddx_deserialize 1wddx_packet_start 1
wddx_serialize_value 1

DNS /

DNS Functions 5dns_get_mx 1
dns_get_record 2gethostbyaddr 2
gethostbynamel 2

Web Services SOAP WSDL /

SOAP Message 1SOAP Response 1
WSDL 1

PDF /

Pdf Lib 3pdf_findfont 1
pdf_new 2pdf_place_image 1