Solved

PHP - compare varible

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to count occurrences of each item in an array.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

738 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