从字符串末尾用.swf提取url

时间:2016-07-25 18:59:09

标签: php

我想使用php提取以.swf结尾的网址。

示例

TEST TEST TEST http://website.com/example.swf

我想通过 .swf

获取网址

我使用了函数preg_replace()

preg_replace('!http://[^?#]+\.(?:swf|SWF)!Ui','', $content);

但它会在网址

之后提取网址+一些字词

感谢..

1 个答案:

答案 0 :(得分:0)

在对您需要的内容进行一些澄清后,我认为这会对您有所帮助。

preg_match_all('#(?P<url>https?://[^\s]+\.swf) (?P<description>[^\n]+)#uiD', $content, $results);
$data = [];
foreach($results['url'] as $key => $value) {
    $data[] = [
         'url' => $value,
         'description' => $results['description'][$key]
    ];
}

// Here you can put your code for saving the data you want.
// if you need to replace the content urls with the <object> tag:
$content = preg_replace('#(https?://[^\s]+\.swf)#uiD', '<object src="$1"></object>', $content);
相关问题