Home › Forums › Back End › Identify a link from html using PHP regular expressions › Re: Identify a link from html using PHP regular expressions
February 17, 2010 at 12:38 am
#71044
john010117
Member
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); ?>
$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); ?>