[thelist] PHP - wildcard with stristr()

Shashank Tripathi sub at shanx.com
Sat Mar 23 19:54:01 CST 2002


Hi Bill

    | Say I have files named 'news020303a.ram',
    | 'news020303b.ram', etc. I want this script to find
    | everything that matches criteria 'news020303*.ram', '*'
    | being the wildcard.
    |


I guess your best bet would be to pick up some reading material on
REGULAR EXPERESSIONS. For instance,
http://www.english.uga.edu/humcomp/perl/regex2a.html

For your specific example, try the following code:


<?php

    //--------------------------------------
    // INITIALIZE TEST VARIABLES
    //--------------------------------------
    $stringToSearch = "news020303aaabbb.ram";
    $prefixToSearch = "news020303";
    $suffixToSearch = "\.ram";

    // Note that there is a dot the suffix. A dot has
    // a special meaning in REGEXP so we need to escape it
    // with a blackslash


    //--------------------------------------
    // FOLLOWING IS THE CODE
    //--------------------------------------
    if (eregi("$prefixToSearch.*$suffixToSearch", $stringToSearch))
    {
        echo "Yes!";
    }
    else
    {
        echo "No match found";
    }

?>



Hope this is useful,
Shanx





More information about the thelist mailing list