If number have inside number string [closed]

Well, you could perform a regular expression search on those strings, however doing so in a database with a large data set may prove rather costly.

$subjects = ["1568940","545198650", "15580", "5551000", "015", "1805"];

foreach ($subjects as $subject) {
    if (preg_match("/(1)\d*(5)\d*(0)\d*/", $subject, $match) && count($match) == 4) {
        echo "$subject contains string 150\n";
    } else {
        echo "$subject does not contain string 150\n";
    }
}

This should give you the following output…

1568940 contains string 150

545198650 contains string 150

15580 contains string 150

5551000 does not contain string 150

015 does not contain string 150

1805 does not contain string 150

In MySQL…

SELECT fieldname FROM table WHERE fieldname REGEXP "(1)*(5)*(0)*";

It might help if you explained in more detail how you’re getting this data and why it is you need to identify if it contains these characters.

Leave a Comment