SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,190
    Mentioned
    71 Post(s)
    Tagged
    3 Thread(s)

    Get a string position with exec

    I have been going around in cicles and not getting any where. I need the LIB_VERSION_NUMBER in a variable ( I also need it padding to 8 numbers - in this case 06030401 but if the number was 6,3,4,11 it would need to be 06030411 but thats another problem ! )

    If I use :
    PHP Code:
    <?php 
    echo "<pre>";
    $test system("convert -list configure "); 
    echo 
    "</pre>";
    ?>
    I get the details below displayed ( I do not want it displayed ) it will also not be saved as a variable.
    Path: C:\Program Files\ImageMagick-6.3.4-Q16\config\configure.xml

    Name Value
    -------------------------------------------------------------------------------
    COPYRIGHT Copyright (C) 1999-2007 ImageMagick Studio LLC
    HOST Windows
    LIB_VERSION 0x634
    LIB_VERSION_NUMBER 6,3,4,1
    NAME ImageMagick
    RELEASE_DATE 05/15/07
    VERSION 6.3.4
    WEBSITE http://www.imagemagick.org

    Path: configure.xml

    Name Value
    -------------------------------------------------------------------------------
    COPYRIGHT Copyright (C) 1999-2007 ImageMagick Studio LLC
    HOST Windows
    LIB_VERSION 0x634
    LIB_VERSION_NUMBER 6,3,4,1
    NAME ImageMagick
    RELEASE_DATE 05/15/07
    VERSION 6.3.4
    WEBSITE http://www.imagemagick.org
    If I use :
    PHP Code:
    echo "<pre>";
    $test exec("convert -list configure "); 
    echo 
    "</pre>";
    echo 
    $test
    The value is input into the variable but the contents of the variable are just :
    Not the whole thing.

    I can not seem to get this to work; can somebody give me a pointer ?

  2. #2
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Rubble View Post
    can somebody give me a pointer ?
    Sure.

    exec

  3. #3
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    can somebody give me a pointer ?
    Lol - you don't know how right you are.

    Server() has a second, optional, parameter. This is a pointer (get it?) variable which will then store the return value.

    e.g.
    PHP Code:
    <?
    Server
    ("convert -list configure "$output);
    echo 
    "<pre>".$output."</pre>";
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  4. #4
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    preg_match('/^LIB_VERSION_NUMBER ([0-9,]+)$/m'shell_exec("convert -list configure "), $ver);
    $ver $ver[1]; 
    $ver will contain only those numbers and the commas

  5. #5
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,190
    Mentioned
    71 Post(s)
    Tagged
    3 Thread(s)
    I thought I had already tried something similar arkinstall; this found the information I wanted:
    PHP Code:
    exec("convert -list configure "$output);
    echo 
    $output[8]; 
    Your method worked well longneck; better if I didn't know the location of my information in the array. It should always be in the same position but I will use your method in case it does change !!!

    Thanks for the help.

  6. #6
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,190
    Mentioned
    71 Post(s)
    Tagged
    3 Thread(s)
    Finished code:
    PHP Code:
    // Select the version number from the configeration file
    preg_match('/^LIB_VERSION_NUMBER ([0-9,]+)$/m'shell_exec("convert -list configure "), $ver);

    $ver $ver[1];

    $number explode","$ver );

    // Format the version from 6,3,4,1 format to 06030401
    $version "";

    for(
    $i=0;$i<4;$i++)
    {
    $version .= str_pad$number[$i], 2'0'STR_PAD_LEFT );


    // Depending on the version number either use font or type to display the available fonts
    if ( $version "06030507" ){
    $font_list "font";
    }

    else {
    $font_list "type";
    }

    echo 
    "<pre>"
    system("convert -list $font_list"); 
    echo 
    "</pre>"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •