PHP - Searching a string for a matching set of characters
Posted on Monday, April 2nd
Using Code Igniter, there are many helper functions built-in that cause me to sometimes forget about the raw PHP alternatives. One such function is STRPOS.
Its job is to return an integer that marks the string position of the first character match you feed into the function.
I discovered and implemented this function for the first time while setting up a Trulia Property feed for a client. I noticed while setting up the feed that their current CMS was not saving zip code information which I knew had to be hurting them. Rather than jump in and alter their CMS I simply went into the PHP code I wrote to generate the feed and added in the following:
if ( strpos($my_string, $characters) === FALSE ) {
echo ' ';
} else {
echo '08243 ';
}
What this code does is check the string for the match and return false if no match is found. I'm not interested in the numeric position of the string I'm searching for, only if its there or not. Easy enough!
Keep it Clean, Simple & Elegant
The web is confusing enough already.
Designing thoughtful websites that deliver information quickly and easily while providing a pleasant web experience to all visitors. That's the Sites by Joe way.
View the Website Portfolio
The proof IS in the pudding. Beautiful, hand-crafted websites that are lovingly created from scratch. See for yourself some of the custom websites that I've designed and developed for my clients in Southern New Jersey and many points around the globe. View the website portfolio.
Want to work with Sites by Joe?
I'm passionate about the web. I love creating websites and it shows in the results. I'd enjoy hearing about your project and discussing ways we can bring your ideas to fruition.
This dedication to service and results brings many new referrals and inquiries. At the same time I try to only focus on a couple projects at a time. That said, it would be wise to get in touch ahead of time to start the dialog for your new website. Work with me





