0

I want to extract a url ending with .swf using php.

EXAMPLE

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

I want to get the url with the .swf

I used a function preg_replace()

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

but it extract the url + some words after the url

THANKS..

Mad Physicist
  • 107,652
  • 25
  • 181
  • 264

1 Answers1

0

After some clarification on what you need i think this will help you.

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);
Roey Haim
  • 73
  • 2
  • 9