Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Searching for partilcular numbers in PHP

Tags:

php

I have been working on a requirement (in PHP), where I had stuck with the below.

I need to search for the numbers between 6800 to 6899. How can I search starts with the string ‘68’. So that I will get all the numbers in that range.

Now, I have an idea like:

if ($Model== 'Jazz6800i') return true;
if ($Model== 'Jazz6801i') return true;
......
if ($Model== 'Jazz6899i') return true;

Do we have any alternate in PHP instead of writing hell lot of code, to search starting with 68?

like image 777
jagadish0911 Avatar asked Jan 28 '26 22:01

jagadish0911


1 Answers

Use regexp:

function isInCorrectRange($item) 
{
    return preg_match('/Jazz68[0-9][0-9]i/', $item);
}

$result = isInCorrectRange('Jazz6801i');
like image 61
Piotr Olaszewski Avatar answered Feb 03 '26 07:02

Piotr Olaszewski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!