The subject line describes what I'm trying to do, (and after thinking about it for a day or so and trying different things; searching around for similar questions on the board,) but I still haven't found a proper regular expression.
I am trying to use preg_match_all to locate HTML Anchor link BUT only if the link is a .pdf file within text from a database table. It actually was working just fine until I recently made a change regarding new lines (\n) and (<br />) in the text that is to be searched. But after making changes regarding the new lines and things, my previous regexp doesn't work correctly. Here is the regexp I am trying to use:
preg_match_all('/<a href="(.*)">(.*)<\/a>/U', $entry->Record['e_entry'], $res_output, PREG_PATTERN_ORDER);
That regexp does find each occurance of an <a href="">something here</a> link... but I need it to only find occurances of an anchor link if it is a PDF file link (ex: <a href="../something.pdf">something</a>). So I tried changing the regexp to something like this:
preg_match_all('/<a href="(.*)\.pdf">(.*)<\/a>/U', $entry->Record['e_entry'], $res_output, PREG_PATTERN_ORDER);
But in the preg_match_all results array ($res_output) a regular <a href="">something here</a> link is ALSO found as well as the .pdf links... I am trying to only find links that contain .pdf at the end of the file name. Sorry that this is written kind of strangely, if you need more info let me know. Does anyone know what I need to change in the regexp to ONLY find HTML anchor links that contain .pdf at the end of the HREF?
Thanks,
Andy