Josh Tam World

Frequently-Used PHP Functions

 
It is quite a pain to browse through documentation and previous stuff to refer back through php codes, when I need them. So I will be using this page to list all the php functions that I frequently use. You guys can also bookmark this page for reference if you want.

Frequently-Used PHP Functions

Strings
string strtolower ( string $str )
Converts string to lowercase.

string strtoupper ( string $str )
Converts string to uppercase.

str_replace(array of matches, replace with what, string to work on)
$vowels = array("a", "e", "i", "o", "u", "A", "E", "I", "O", "U");
$only_consonants = str_replace($vowels, "", "Hello World");
$only_consonants will become Hll Wrld

strip_tags($text, '<p><a>');
PHP Will remove all html tags from $text except <p> and <a>

Date and Time
$timetoday = getdate();
$timetoday will hold this data:
Array
(
[seconds] => 40
[minutes] => 58
[hours] => 21
[mday] => 17
[wday] => 2
[mon] => 6
[year] => 2003
[yday] => 167
[weekday] => Tuesday
[month] => June
[0] => 1055901520
)

date(format,timestamp)
timestamp is optional
For format, refer to this php date format list on w3schools

Conversions
floor(string)
This baby can convert strings to integer!

SQL Section

Decided to add SQL stuff here too...

Data Types
SQL Datatypes

Randomizing Stuff
RAND() to randomize stuff
SELECT FLOOR(7 + (RAND() * 5)); to randomize an integer from 7 to 12

Referers

Info

Views : 233
Date Created : 2009-11-15 04:17:41
Date Modified : 2010-03-09 17:32:26


 
 
 

[Recent Events] I finally got it to work... Watch FIFA World Cup 2010 South Africa Online!