Quick PHP Functions : preg_match_count, starts_with


Here are a couple more quick php functions for you, something you can throw in your common.php file and be used in the future if ever need be.

Click the function names which link to the code stored at Smipple.net

preg_match_count, takes a pattern, an input string, and returns the amount of times your pattern appears in the string.


preg_match_count("<[^>]*>", "<p><span>test</span></p>"); //Returns 4

starts_with, returns true or false if your input string starts with your needle.


starts_with("testing", "test"); //Returns true
starts_with("testing", "ing"); //Returns false

That’s all I got for now, hopefully I have something more to post then just small bits of simple code in the future.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s