如何在PHP中从复杂字符串中提取文件名



我有一个PHP字符串,包含一个复杂的结构。这是字符串:

a:10:{s:4:"type";s:9:"image/png";s:5:"title";s:19:"1394228903_imac.png";s:10:"quote_path";s:68:"/media/custom_options/quote/1/3/2b2a7355414ba6d486a4fdd2af96809e.png";s:10:"order_path";s:68:"/media/custom_options/order/1/3/2b2a7355414ba6d486a4fdd2af96809e.png";s:8:"fullpath";s:107:"/Users/Gabriel/Documents/Projects/demo4/media/custom_options/quote/1/3/2b2a7355414ba6d486a4fdd2af96809e.png";s:4:"size";s:4:"3558";s:5:"width";i:128;s:6:"height";i:128;s:10:"secret_key";s:20:"2b2a7355414ba6d486a4";s:3:"url";a:2:{s:5:"route";s:35:"sales/download/downloadCustomOption";s:6:"params";a:2:{s:2:"id";s:2:"42";s:3:"key";s:20:"2b2a7355414ba6d486a4";}}}

字符串存储在$fullValue变量中。

如何从那里提取图像文件名?具体来说,我想提取这个:2b2a7355414ba6d486a4fdd2af96809e.png

谢谢。

您在这里显示的结构不是json字符串。它看起来像一个序列化的php字符串。

所以,你应该这样做:

$data = unserialize($input);
echo basename($data["fullpath"]);

最新更新