-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

2
  • do you mean "contains an URL" or "contains an html hyperlink <a src="....">xxxx</a>" ? Commented Apr 19, 2012 at 8:39
  • Don't do that Commented Apr 19, 2012 at 8:40

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for the reply. How can i use the filter_var to find if the url is a hyperlink i.e it contains <a href. So the first thing is to check whether the url is in the content/string then if the url is a hyperlink.
In that case you probably want to combine filter_var with stackoverflow.com/questions/6568917/… as suggested by @Quentin above
Thanks for the reply. When i try as advised in stackoverflow.com/questions/6568917/… 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?
That means you're trying to parse invalid HTML. See stackoverflow.com/questions/2702799/php-parsing-invalid-html for some code that shows how you can fix this error

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.