Results 1 to 8 of 8

Thread: a:1:{s:8:"uploaded";s:37:"128210178941769_1260783455_1263_q.jpg";}

  1. #1
    Join Date
    Aug 2008
    Location
    karanganyar, solo, indonesia
    Posts
    161
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Question a:1:{s:8:"uploaded";s:37:"128210178941769_1260783455_1263_q.jpg";}

    i have a string like below
    a:1:{s:8:"uploaded";s:37:"128210178941769_1260783455_1263_q.jpg";}

    i want to get 128210178941769_1260783455_1263_q.jpg only,
    can somebody here help me to do that???


    thanks so much....
    ///////////////////////////////////////////////////
    ///// http://www.mediatutorial.web.id
    ///////////////////////////////////////////////////

  2. #2
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    Could you give more examples and details, otherwise the following works:

    PHP Code:
    <?php
    $text 
    'a:1:{s:8:"uploaded";s:37:"128210178941769_1260783455_1263_q.jpg";}';
    preg_match('/^.*\"([0-9]{7,}.*?)\"/',$text,$needle);
    echo
    "$needle[1]";
    ?>
    Basically, it looks for a double quote that is followed by a number that is 7 or more digits in length and then follows that all the way to the next quote matching everything between the two quotes then assigns it to the array $needle stored at $needle[1].
    To choose the lesser of two evils is still to choose evil. My personal site

  3. #3
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    PHP Code:
    $serialized 'a:1:{s:8:"uploaded";s:37:"128210178941769_1260783455_1263_q.jpg";}'
    $array unserialize($serialized);
    print 
    $array[0];
    // 128210178941769_1260783455_1263_q.jpg 
    Edit:

    You serialize a value (any value, except a resource; and it's tricky -but possible- with an object) to make it storable (in a session or a database) and easily recoverable afterwards.

    a:1 indicates an array containing 1 item.
    :{ } shows the contents of the array.
    s:8:"uploaded"; is the key (a string with 8 characters)
    s:37:"128210178941769_1260783455_1263_q.jpg" is the value (a string with 37 characters).

    Last edited by traq; 01-27-2011 at 03:28 PM.

  4. The Following User Says Thank You to traq For This Useful Post:

    smansakra (01-27-2011)

  5. #4
    Join Date
    Aug 2008
    Location
    karanganyar, solo, indonesia
    Posts
    161
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    @james438: thanks for reply
    @trac : Thanks so much trac!!! , yes, i have seen 'serialize' and 'unserialize' but i don't know what is it and how to use it. ^_^
    and now i know it...
    thanks for explanation.......
    ///////////////////////////////////////////////////
    ///// http://www.mediatutorial.web.id
    ///////////////////////////////////////////////////

  6. #5
    Join Date
    Aug 2008
    Location
    karanganyar, solo, indonesia
    Posts
    161
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    trac, i have just tried your code
    PHP Code:
    <?php
    $serialized 
    'a:1:{s:8:"uploaded";s:37:"128210178941769_1260783455_1263_q.jpg";}'
    $array unserialize($serialized);
    print 
    $array[0];
    // 128210178941769_1260783455_1263_q.jpg  
    ?>
    and it returns Parse error: syntax error, unexpected T_VARIABLE in C:\Program Files\xampp\htdocs\abc.php on line 3

    i think it the $serialized is a:1:{i:0;s:37:"128210178941769_1260783455_1263_q.jpg";}

    but the variable above doesn't content i:0; :'(
    ///////////////////////////////////////////////////
    ///// http://www.mediatutorial.web.id
    ///////////////////////////////////////////////////

  7. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    There's a missing semicolon at the end of the first line. Just add ;
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  8. #7
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    yup, whoops - sorry about that.

    Edit:

    BTW, " $array[0] " will also return an error. You'll need to use print $array['uploaded']; instead, sorry!


  9. #8
    Join Date
    Aug 2008
    Location
    karanganyar, solo, indonesia
    Posts
    161
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    @djr33: thanks , yes i forgot 'semicolon' this morning,, hehehe ^_^
    @trac: i works thanks so much
    ///////////////////////////////////////////////////
    ///// http://www.mediatutorial.web.id
    ///////////////////////////////////////////////////

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
  •