String match

Posted on 2005-04-16
Medium Priority
Last Modified: 2006-11-18
I have this very long string $xmlstr

I want to test if the word "customer" is in that string, how can I do this using PHP ?

Question by:kapot
  • 2
LVL 32

Expert Comment

ID: 13796630
$xmlstr = 'This is my test string that has the customer word!';
$compareStr = 'customer';
if(substr_count($xmlstr, $compareStr) > 0){
 echo 'Substring matches';
 echo 'Does not match';

// With PHP 5, other option is to use substr_compare !

Author Comment

ID: 13798905
Is it faster than using "eregi()" ?
LVL 32

Accepted Solution

ldbkutty earned 50 total points
ID: 13798911
ofcourse, string functions are "always" faster than Regular Expressions!

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month14 days, 17 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question