2

Ive looked around quite a bit for a regex to help me find a anchor tag with an mp3 as the href. I would like first to get a regex which will locate this pattern so i can replace those links with a player and next i need to extract the link out of the href.

I hardly understand how to create or use a regex so any help to accomplish this will be useful.

Thanks, Jesse

skaffman
  • 398,947
  • 96
  • 818
  • 769
Jesse
  • 21
  • 1

3 Answers3

1

Supposing you already got the links —e.g. get_elements_by_tagname('a')— all you need to do is:

if( substr($href, -4)=='.mp3' ){
    // Is an MP3 link
}
Álvaro González
  • 142,137
  • 41
  • 261
  • 360
0

This will do the trick

~<a.*?href="(?P<url>.*?\.mp3(?:\?.*?)?)".*?>~is

however, it's hardly to be considered optimal.

Mikulas Dite
  • 7,790
  • 9
  • 59
  • 99
0

at first this didnt quite work for me. I made a couple of changes and now I got it. i needed to change the ~ to a / and i had to replace all the way to the closing anchor tag so heres what im using.

/<a.*?href="(?P<url>.*?\.mp3(?:\?.*?)?)">.*?<\/a>/is

Thanks for getting me in the right direction

Jesse
  • 21
  • 1