SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Jun 2008
    Posts
    205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Match the string

    Code:
    <?php
    $file = array('2009/01/04/b3justin04cmmv,.nzsfoiwauf','2009/01/11/ymtestdrive11bnk,hhukt7yufgv','2009/01/13/a2correx13, bvj,hgho');
    
    foreach($file as $f){
       print "The input is : $f";
       preg_match("/(\d{4}\/\d{2}\/\d{2}\/[^ ]*)/","$f",$match);
       print "The output is : $match[0]\n";
    }
    How to extract only "2009/01/04/b3justin04cmmv","2009/01/11/ymtestdrive11bnk","2009/01/13/a2correx13".

    How to remove "," comma at the end. and find the last string before ","

  2. #2
    SitePoint Evangelist Waffles's Avatar
    Join Date
    Nov 2005
    Posts
    435
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php
    $file 
    = array('2009/01/04/b3justin04cmmv,.nzsfoiwauf','2009/01/11/ymtestdrive11bnk,hhukt7yufgv','2009/01/13/a2correx13, bvj,hgho');

    foreach(
    $file as $f){
       print 
    "The input is : $f<br />";
       
    preg_match("/(\d{4}\/\d{2}\/\d{2}\/[^ ]*)/","$f",$match);

    ####

       
    $foo=explode(',',$f);
       echo 
    '<p>'.$foo[0].'</p>';

    ####

       
    print "The output is : $match[0]\n<br />";
    }
    ?>


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
  •