• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 320
  • Last Modified:

PHP - compare varible

I just want to check a 3 digit number (integer) starts with a 10, the last digit can be any number.

So something like 10*
0
gvilla23
Asked:
gvilla23
  • 2
  • 2
1 Solution
 
Marco GasiFreelancerCommented:
Try this:

if (preg_match('/10\d/'), $digitNumber){
  echo 'true';
}else{
  echo 'false';
}

Cheers
0
 
gvilla23Author Commented:
Thanks, but I am getting an error on if(preg_match('/10\d/'), $id){

here is my code.
thanks

$obj = simplexml_load_file('test.xml');

// ACTIVATE THIS TO VISUALIZE THE OBJECT
// var_dump($obj);

// IF WE HAVE A GET ARGUMENT
if (!empty($_GET["id"]))
{
    // USE ONLY NUMBERS
    $id = preg_replace('#[^0-9]#', NULL, $_GET["id"]);

    // ITERATE OVER THE POPUP OBJECTS
    foreach ($obj->popup as $popup)
    {
        // FIND THE MATCHING ID(S)
        if ($popup->id == $id)
        {
                  //$id = $id->id;
                  $id = (int)$popup->id;
            $title = (string)$popup->title;
            $img_loc = (string)$popup->img_loc;
            $client = (string)$popup->client;
            $involvement = (string)$popup->involvement;
           // echo PHP_EOL . $title . ' ' . $client;
      
            
if (preg_match('/10\d/'), $id){
  echo 'true';
}else{
  echo 'false';
}            
0
 
gvilla23Author Commented:
if(preg_match('/(<a\s*'), $id)){

fixed that.. let me see if it works now
0
 
Scott MadeiraCommented:
how about:

if (is_int($number) && $number >= 100 && $number < 110) {

   // do stuff

}
0
 
Marco GasiFreelancerCommented:
What is (<a\s*')?
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now