Solved

PHP - compare varible

Posted on 2011-03-04
5
304 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 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…

829 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