Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Identify a link from html using PHP regular expressions Re: Identify a link from html using PHP regular expressions

#71044
john010117
Member

http://php.net/preg_match

The regular expression should be something like:

Code:
/^(([A-Za-z0-9-_]+).(mp3))+/

Try experimenting with the regex to get what you want (this would be a very helpful tool).

Code:
<?php
$mystring 
= ‘<p> Hello this is a WP post. <a href=”somefile.mp3″>Here is a link to mp3</a></p>’;

preg_match(‘/^(([A-Za-z0-9-_]+).(mp3))+/’, $mystring, $matches);

var_dump($matches); ?>