PHP examples (example source code) Organized by topic





Form /

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

Login Authentication /

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

HTML /

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

XML /

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

MySQL Database /

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

Cookie Session /

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

File Directory /

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

Email /

Email Address 1Email Validation 2mail function 5

Math /

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

String /

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

Utility Function /

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

Graphics Image /

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

Components /

Feedback Form 1Page Counter 2Registration Form 1

Chart /

Bar Chart 1Pie Chart 1

Class /

Abstract Class 5Class Constant Property 3Class Constructor 1Class Definition 14
Class Inheritance 5Class Instance 1Class Method 13Class Property 10
Class Static Properties 1clone 7const 5Constructor 15
Destructors 7extends 1final 5Getter Setter 3
Inheritance 14instance of 2Interface 7Method Override 4
Object Attribute 2object 1Objects 8private 8
Properties get 1Properties set 2protected 5public 5
Reflection Class Definition 8Reflection Class Hiearchy 2Reflection Class Methods 9Reflection Constructor 1
Reflection Existance 2Reflection Invoke 2self 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 1Factory Pattern 1Request Info 4
Singleton Pattern 2Strategy Pattern 1

Language Basics /

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

Development /

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

Data Structure /

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

Functions /

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

Statement /

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

Reflection /

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

Operator /

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

Data Type /

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

Date /

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

Network /

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

DNS /

DNS Functions 5dns_get_mx 1dns_get_record 2gethostbyaddr 2
gethostbynamel 2

Web Services SOAP WSDL /

SOAP Message 1SOAP Response 1WSDL 1

PDF /

Pdf Lib 3pdf_findfont 1pdf_new 2pdf_place_image 1