Matching a string

I just posted on splitting a string, might as well add my match as they can often come hand in hand. preg_match("your search item", "your_string") Boom, done Bookmark on Delicious Digg this post Recommend on Facebook share via Reddit Share with Stumblers Tweet about it Subscribe to the comments on this post

Splitting a string

I’ve just spent 15 minutes looking for this darn function, never again! Here is how to split a string to get the information you require: Edit: A wise PHP guru just gave me an alternative option as well. $chars = explode(‘-’, "your-string-here"); Is the same as: $chars = preg_split(‘/-/’, "your-string-here", -1, PREG_SPLIT_NO_EMPTY); $your = $chars[0]; $string = $chars[1]; $here = $chars[2]; Works just peachy Bookmark on Delicious Digg this post

PHP shorthand IF statements

Easy to forget the correct syntax but darn it’s useful, a recap on shorthand php if statements. Basic True / False Declaration $is_admin = ($user['permissions'] == ‘admin’ ? true : false); Conditional Welcome Message echo ‘Welcome ‘.($user['is_logged_in'] ? $user['first_name'] : ‘Guest’).’!'; Conditional Items Message echo ‘Your cart contains ‘.$num_items.’ item’.($num_items != 1 ? ‘s’ : ”).’.'; Conditional Error Reporting Level error_reporting($WEBSITE_IS_LIVE ? 0 : E_STRICT); Conditional Basepath echo ‘<base href="http’.($PAGE_IS_SECURE

Switch to our mobile site