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....
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
///////////////////////////////////////////////////
Could you give more examples and details, otherwise the following works:
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].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]";
?>
To choose the lesser of two evils is still to choose evil. My personal site
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.
smansakra (01-27-2011)
@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
///////////////////////////////////////////////////
trac, i have just tried your code
and it returns Parse error: syntax error, unexpected T_VARIABLE in C:\Program Files\xampp\htdocs\abc.php on line 3PHP 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
?>
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
///////////////////////////////////////////////////
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
yup, whoops - sorry about that.
Edit:
BTW, " $array[0] " will also return an error. You'll need to useprint $array['uploaded'];instead, sorry!
@djr33: thanks , yes i forgot 'semicolon' this morning,, hehehe ^_^
@trac: i works thanks so much
///////////////////////////////////////////////////
///// http://www.mediatutorial.web.id
///////////////////////////////////////////////////
Bookmarks