0

我在数据库中有“请求”,我需要从中提取图像的名称 - 它始终是 .jpg 但名称中的字符数可能会有所不同,所以我回避 substr()。

该值看起来像这样“Added 545_4.jpg to Photo Album, The British Open”。

“已添加”将始终存在,“到相册”将始终存在,但相册名称不同。

根据手册,我猜想 % 字符表示多个字符,所以我试图让它代表相册的变体。所以,我最终得到了这个,但似乎什么也没发生,因为它只是回显了原始字符串。

$emij = str_replace('Added','', 
        str_replace(' to Photo Album%', '', $thisTask[0]['request']));
echo $emij;

任何帮助是极大的赞赏。

4

1 回答 1

1

正则表达式最适合此:

preg_match("/Added (.*?) to Photo Album, (.*?)/",$thisTask[0]['request'],$m);
// $m[1] is now the filename
// $m[2] is the name of the album
于 2012-06-26T00:26:10.313 回答