Solved

PHP - compare varible

Posted on 2011-03-04
5
308 Views
Last Modified: 2013-11-19
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
Comment
Question by:gvilla23
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 35038266
Try this:

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

Cheers
0
 

Author Comment

by:gvilla23
ID: 35038672
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
 

Author Comment

by:gvilla23
ID: 35038780
if(preg_match('/(<a\s*'), $id)){

fixed that.. let me see if it works now
0
 
LVL 14

Accepted Solution

by:
Scott Madeira earned 250 total points
ID: 35039155
how about:

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

   // do stuff

}
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 35039332
What is (<a\s*')?
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

707 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