-4

Possible Duplicate:
extract all <a> tags from content

i am fetching website contents using curl (PHP) and then perform a check if it contains a string. I would like to check if this string is a hyperlink or not. Does anybody know the correct regex/code to perform this?

Many Thanks,

J

Community
  • 1
  • 1

1 Answers1

4

You want to use PHP's filter_var function. For example: filter_var('http://example.com', FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED)

Daan
  • 3,403
  • 23
  • 19
  • Thanks for the reply. How can i use the filter_var to find if the url is a hyperlink i.e it contains – Jibril Salad Apr 23 '12 at 13:19
  • In that case you probably want to combine filter_var with http://stackoverflow.com/questions/6568917/extract-all-a-tags-from-content as suggested by @Quentin above – Daan Apr 23 '12 at 21:33
  • Thanks for the reply. When i try as advised in http://stackoverflow.com/questions/6568917/extract-all-a-tags-from-content i get the following error: DOMDocument::loadHTML() [domdocument.loadhtml]: ID top already defined in Entity, line: 41 I am passing a string directly from curl_exec into loadHTML, do i have to do any conversion before that? – Jibril Salad Apr 25 '12 at 13:35
  • That means you're trying to parse invalid HTML. See http://stackoverflow.com/questions/2702799/php-parsing-invalid-html for some code that shows how you can fix this error – Daan Apr 25 '12 at 22:07