Hello! How to trim a string here so that you only get:

2a5cc72ffea060a4548ae03d6076f4bd_800.jpg

and remove everything else from this line:

 a:7:{i:800;s:40:"2a5cc72ffea060a4548ae03d6076f4bd_800.jpg";i:500;s:40:"2a5cc72ffea060a4548ae03d6076f4bd_500.jpg";i:300;s:40:"2a5cc72ffea060a4548ae03d6076f4bd_300.jpg";i:295;s:40:"2a5cc72ffea060a4548ae03d6076f4bd_295.jpg";i:75;s:39:"2a5cc72ffea060a4548ae03d6076f4bd_75.jpg";i:40;s:39:"2a5cc72ffea060a4548ae03d6076f4bd_40.jpg";i:0;s:36:"2a5cc72ffea060a4548ae03d6076f4bd.jpg";} 
  • 2
    can perform unserialize and calmly take the desired element of the array? - Mike
  • this is not an array, but a string - DronaxD
  • 2
    yes, only this string is explicitly made by the serialize function, at least in appearance. And if this is so, unserialize() will make it again the structure that was serialized - Mike
  • 2
    это не массив, а строка - Oruuu !!! - Alexey Shimanskyj
  • one
    Yes, I guessed it. ideone.com/Mflgfh - Mike

1 answer 1

You should read about the function unserialize .

The following code:

 print_r(unserialize('a:7:{i:800;s:40:"2a5cc72ffea060a4548ae03d6076f4bd_800.jpg";i:500;s:40:"2a5cc72ffea060a4548ae03d6076f4bd_500.jpg";i:300;s:40:"2a5cc72ffea060a4548ae03d6076f4bd_300.jpg";i:295;s:40:"2a5cc72ffea060a4548ae03d6076f4bd_295.jpg";i:75;s:39:"2a5cc72ffea060a4548ae03d6076f4bd_75.jpg";i:40;s:39:"2a5cc72ffea060a4548ae03d6076f4bd_40.jpg";i:0;s:36:"2a5cc72ffea060a4548ae03d6076f4bd.jpg";}')); 

Displays:

 Array ( [800] => 2a5cc72ffea060a4548ae03d6076f4bd_800.jpg [500] => 2a5cc72ffea060a4548ae03d6076f4bd_500.jpg [300] => 2a5cc72ffea060a4548ae03d6076f4bd_300.jpg [295] => 2a5cc72ffea060a4548ae03d6076f4bd_295.jpg [75] => 2a5cc72ffea060a4548ae03d6076f4bd_75.jpg [40] => 2a5cc72ffea060a4548ae03d6076f4bd_40.jpg [0] => 2a5cc72ffea060a4548ae03d6076f4bd.jpg ) 

The information you need is stored in the array under the key 800 . Save the result of the function unserialize into a variable and work with it.

For example:

 $images = unserialize('тут ваша строка'); print $images[800];