String match

Posted on 2005-04-16
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
    LVL 32

    Expert Comment

    $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

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

    Accepted Solution

    ofcourse, string functions are "always" faster than Regular Expressions!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    This is a general how to create your own custom plugin system for your PHP application that you designed (or wish to extend a third party program to have plugin functionality that doesn't have it yet).  This is not how to make plugins for existing s…
    Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    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.

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now