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..

4

1 Answer 1

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); 
Sign up to request clarification or add additional context in comments.

13 Comments

it get the seems thing
Please post an example text you use, what happens after the preg_replace. the \b should do the job and not touch anything other then the url
I think that the problem is not from your function i need another function in php not preg_replace like explod or something else , THANKS
What exactly you try to do?
what want to do is geting the content of post wordpress and extract the url that end with .swf and put it in <object> and get other text and put it in description under the object
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.