little help in php show data

Discussion in 'PHP' started by ironmankho, Nov 24, 2010.

  1. #1
    Size: 731260928 bytes (697.38 MiB), duration: 01:49:36, avg.bitrate: 890 kb/s

    above line i want only "697.38" and "01:49:36" in php ..... i just try out but little help required me :Thanks

    like

    697.38
    01:49:36
     
    ironmankho, Nov 24, 2010 IP
  2. ZoomRumble

    ZoomRumble Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    try this

    
    <?php
    
    $src_str = 'Size: 731260928 bytes (697.38 MiB), duration: 01:49:36, avg.bitrate: 890 kb/s';
    
    $size = get_string('(', ' MiB)', $src_str);
    $duration = get_string('duration: ', ', avg', $src_str);
    
    echo $size.' | '.$duration;
    
    function get_string($start, $end, $src)
    {
        $begin = strpos($src, $start)+strlen($start);
        $last = strpos($src, $end);
        return substr($src, $begin,$last-$begin);
    }
    
    ?>
    
    PHP:
     
    ZoomRumble, Nov 24, 2010 IP
  3. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #3
    
    $src_str = 'Size: 731260928 bytes (697.38 MiB), duration: 01:49:36, avg.bitrate: 890 kb/s';
    
    preg_match('/.*bytes \(([0-9.]+) MiB.*([0-9]{2}:[0-9]{2}:[0-9]{2}),.*/',$src_str,$result);
    
    print_r($result);
    
    PHP:
    This should work nicely.
     
    ThePHPMaster, Nov 24, 2010 IP
  4. ironmankho

    ironmankho Active Member

    Messages:
    393
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #4
    thanks for this help
     
    ironmankho, Nov 24, 2010 IP
  5. samyak

    samyak Active Member

    Messages:
    280
    Likes Received:
    7
    Best Answers:
    4
    Trophy Points:
    90
    #5
    I like ThePHPMaster's soluton. Its more elegant.
     
    samyak, Nov 24, 2010 IP
  6. guardian999

    guardian999 Well-Known Member

    Messages:
    376
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #6
    Like both ZoomRumble and ThePHPMaster.

    but prefer to ZoomRumble, the code is simple.
     
    guardian999, Nov 25, 2010 IP
  7. ironmankho

    ironmankho Active Member

    Messages:
    393
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #7
    Both are ThePHPMaster. and ZoomRumble solution are good ...

    but ThePHPMaster is more professional way. For understanding this code you should have knowledge of RegEx(i am also learn this because regEx is most important and it is future )

    ZoomRumble code is very simple and shown me the importance of Function ...

    I am very thank full these two person who come in and write the code and show me the two way of solution
     
    ironmankho, Nov 25, 2010 IP