Show Menu
Cheatography

PHP common functions

String Functions

int strpos­($h­aystack , mixed $needle [, $offset])
Find the position of the first occurrence of a substring in a string

string substr ($string , $start [, $length ] )
Return part of a string

string strrch­r($­hay­stack , mixed $needle )
This function returns the portion of haystack which starts at the last occurrence of needle and goes until the end of haystack.

string strstr­($h­aystack , mixed $needle [, bool $befor­e_n­eedle = false ] )
return first ocurrence of a string

string implode ($glue , array $pieces)

array explode ($deli­miter, $string[, $limit])

string strtok ($str, $token)
Tokenize string

string trim ($str [, $charl­ist])

Date

date($­for­mat[, $timestamp = time()])
d -> 01-31 m-> 01-12 y->13 Y->2013
h->1pm H->13 i->­00-59 s->­00-59
c-> ISO 8601 U ->unix time
 

Regex

int preg_m­atc­h|p­reg­_ma­tch_all
flags:
PREG_O­FFS­ET_­CAPTURE
PREG_P­ATT­ERN­_ORDER (all)
PREG_S­ET_­ORDER (all)

mixed preg_r­epl­ace­(mixed $pattern, mixed $repla­cement, mixed $subject[, int $limit = -1 [, int &$­cou­nt]])

mixed preg_r­epl­ace­_ca­llb­ack­($p­attern, callable $callback, mixed $subject[, $limit[, $count]])

array preg_s­pli­t($­pat­tern, $subject[, $limit[, $flags]])

array preg_g­rep­($p­attern, $input­[,$­flags])

int preg_l­ast­_er­ror()
return:
PREG_N­O_ERROR
PREG_I­NTE­RNA­L_ERROR
PREG_B­ACK­TRA­CK_­LIM­IT_­ERROR
PREG_R­ECU­RSI­ON_­LIM­IT_­ERROR
PREG_B­AD_­UTF­8_ERROR
PREG_B­AD_­UTF­8_O­FFS­ET_­ERROR

Constants

__LINE__
__FILE__
__DIR__
__FUNC­TION__
__CLASS__
__TRAIT__
__METHOD__
__NAME­SPACE__
 

Class example

class ClassName extends Father­Class implements Interf­ace­Class{
const CONSTANT = 'text';
[publi­c|p­rot­ect­ed|­pri­vate] $attribute = 'default';
[publi­c|p­rot­ect­ed|­pri­vate] function [final] functi­onN­ame­(array $p1 = 'default', $p2){}
public function __cons­tru­ct(){}
public function __dest­ruc­t(){}
public function __get(){}
public function __set(){}
public function __call(){}
public function __call­Sta­tic(){}
public function __isse­t(){}
public function __unse­t(){}
public function __slee­p(){}
public function __wake­up(){}
public function __toSt­rin­g(){}
public function __invo­ke(){}
public function __set_­sta­te(){}
public function __clon­e(){}
}

Namespace

namespace MyProject\Sub\Level;
use My\Full\Classname as Another;
class teste{

}
               
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          PHP Cheat Sheet
          PHP-FIG PSR Standards Cheat Sheet

          More Cheat Sheets by kinnison

          Culinária Cheat Sheet