Common PHP Questions by Function
Below is a list of common functions used in the PHP and mySQL examples on this site. If you want to know about a particular function and see an example of that function in use rather than having a specific question, you will find this index a useful tool in quickly finding out a function. The majority have a clear and simple example of how to use a function so that you can get to grips and start using a function quickly whatever your knowledge of PHP.addslashes
How do I escape a string with slashes?
How do I escape data that is going into a database?
array_count_values
How do I count the number of times a value appears in an array?
array_flip
I want to invert my array, can I do this?
array_keys
I am not interested in the values in the arrays, how can I discard them?
array_pop
How do I remove and view the last element of an array?
array_push
How do I add to the end of an array and know how large the array is?
array_rand
How do I pick a random value from an array?
array_reverse
How do I reverse the order of the elements in an array?
array_shift
How do I remove the first element from an array?
array_unique
How do you remove duplicate values from an array?
array_unshift
How do I add to the beginning of an array and find the number of elements in it?
array_values
How do I return all the values in an array?
arsort
How can I reverse sort an array keeping the correlation between the index and value?
asort
How can I sort an array keeping the correlation between the index and value?
ceil
How do I round up a number?
checkdate
How do I check if a date entered exists?
chop
How can I remove trailing space from a string?
count and sizeof
How do I find the size of an array?
ctype_alpha
How can I check that a data value is alphanumeric?
CURDATE
How do I insert the date into my table?
date
How do I display todays date on my website?
echo
How do I print text to the screen?
empty
How do I check for an empty field in a form?
ereg
How do I check that a valid email address is entered?
explode
How do I turn a string into an array?
How do I count the number of words in my text?
floor
How do I round down a number?
fopen
How do I open a file to write content to?
foreach
How can I loop through the members of an array?
How can I display values in a two dimensional array?
getdate
How do you get an array of the date and time?
GetHostByName
How to find a domain name for an IP address?
get_magic_quotes_gpc
How do I know if magic quotes is switched on?
global
How do I make a variable from outside a function work in that function?
header
How do I send HTTP headers with PHP?
How do I perform a 301 redirect with PHP?
Htmlentities
How do I convert relevant characters in a string to HTML entities?
imagecolorat
How can I find the colour of a pixel of an image?
imagerotate
How can I rotate an image?
imagesx and imagesy
How can I find the width and height of an image resource?
imagettftext
How can I add text to an image?
implode
How do I turn an array into a string?
include
How do I keep my site menu in one file?
int
How do I force a value to be treated as a number?
in_array
How can I check if a value is already in an array?
How do I find out if a value is already in an array?
isset
How do you check if a variable is set or not in PHP?
is_array
How do I check if a variable is of array type?
is_numeric
How can I check a value entered in a field on my form is a number?
krsort
How do I reverse sort an array by key?
ksort
How do I sort an array by key?
LENGTH
How do I find the longest value in my mysql table?
How do I email the contents of a form to me?
metaphone
How do I calculate the metaphone of a string?
mktime
How do I find the timestamp for a particular date?
mysql_affected_rows
How do I find the number of rows affected by a query?
mysql_insert_id
How do I find the ID of a new row added to a table?
mysql_num_rows
How do I find the number of rows in a result set?
mysql_result
How do I find second highest value from a table?
natsort
How do I sort alphanumeric array data correctly?
nl2br
How do I display newline characters on a webpage?
How do I convert newlines to HTML line break tags?
number_format
How do I format a number with commas like a monetary value?
ord
How do I find the ASCII value of a string character?
parse_str
How do I extract the values of variables from a string?
phpinfo
How do I find out about my PHP installation?
print and echo
What is the difference between print and echo?
printf
How do I format the output of a string?
print_r and var_dump
How can I easily view all members of an array?
rand
How do I generate a random number?
range
How can I create an array of the letters of the alphabet?
How can I create an array of numbers easily?
require
How do I make sure an include file exists before loading the page?
reset
How can I reset an array in PHP?
return
How do I return a value from a function?
rsort
How do I reverse sort the members of an array?
rtrim
How do I remove trailing whitespace from a string?
set_time_limit
How can I stop my PHP script timing out?
shuffle
How can I mix up the order of values in an array?
sort
How do I sort the members of an array by value?
static
How do I get a variable in a function to retain its value between calls?
stripslashes
How do I remove escape characters from data?
strip_tags
How do I check if a string contains HTML?
How do I remove HTML tags from a string?
strlen
How do I find the length of a string in PHP?
strpos
How do I find the position of a letter in a string in PHP?
strrev
How do I reverse a string in PHP?
strrpos
How do I find the last occurrence of a character in a string?
strtolower
How do I make the contents of a string lower case?
strtoupper
How do I make the contents of a string upper case?
str_pad
How do I make sure a string is a certain length?
str_repeat
How can I repeat a string variable several times?
str_replace
How do I replace a word in a string in PHP?
trim
How can I remove spaces from around a string value?
ucfirst
How do I make the first letter of a string uppercase?
ucwords
How do I make the first letter of each word upper case?
unset
How do I remove an element from an array without changing the index values for the rest of the array?
usort
How do I write my own sort function?