Skip to content Skip to sidebar Skip to footer

Search Block Of Text, Return Mp3 Links Using Php

I've just run into a little bit of trouble with some PHP on my latest project. Basically I have a block of text ($text) and I would like to search through that text and return all

Solution 1:

Once again, regex is extremely poor at parsing HTML. Use a proper HTML parser to scrape information out of a web page.

For example, use DOMDocument::loadHTML() to parse the HTML content, then getElementsByTagName('a') to get a list of links in the page. For each link, getAttribute('href') to see where it points.

Note however that there is absolutely no guarantee that MP3 files will always and only be stored under filenames ending in .mp3. On the web, the type of a resource does not have to come from a file extension. The only way to find out for sure what type of file a URL points to is to go ahead and fetch it (with an HTTP GET or HEAD request).

Post a Comment for "Search Block Of Text, Return Mp3 Links Using Php"