1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Php shell_exec problem

Discussion in 'PHP' started by baris22, Apr 15, 2011.

  1. #1
    hello all,

    I do not know what i am doing wrong. When i run this if statement i get "Wrong!" all the time.

    Regards.

    
        if(trim(shell_exec('wmic diskdrive get model')) != "Model Maxtor 6Y080L0")
        {
        echo "Wrong!";
        }else{
        echo shell_exec('wmic diskdrive get model'); // Model Maxtor 6Y080L0
        }
    
    PHP:




    i tried this way but still not working.




    
    $output = shell_exec('wmic diskdrive get model');
    $newoutput = trim($output);
    $pieces = explode(" ", $newoutput, 2);
    echo $pieces[1]; // Maxtor 6Y080L0
    
    if ($pieces[1] != "Maxtor 6Y080L0"){
    echo "wrong";
    
    PHP:
     
    baris22, Apr 15, 2011 IP
  2. baris22

    baris22 Active Member

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #2
    ok. the problem was the line break which you can not see on browser. but if you run the code on windows i got this:


    Model
    Maxtor 6Y080L0


    but when i echo with php i had this output:

    Model Maxtor 6Y080L0


    
    $output = shell_exec('wmic diskdrive get model');
    $pieces = explode("\r\n", $output, 2);
    
    if (trim($pieces[1]) != "Maxtor 6Y080L0"){
    echo "Wrong";
    }else{
    echo "OK.";
    }
    
    PHP:
     
    baris22, Apr 15, 2011 IP
  3. EitanXOR

    EitanXOR Greenhorn

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #3
    For the next time, if you don't want this happening again, always make sure to view the page source, or put <pre> tags around your output so you'll see it as-is in the brwoser.
     
    EitanXOR, Apr 16, 2011 IP