Solved

PHP - compare varible

Posted on 2011-03-04
5
296 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
  • 2
  • 2
5 Comments
 
LVL 30

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 30

Expert Comment

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

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now