How can I restrict this PHP code to crawl links that have the same base with the domain given?
<p>I am writing a code is a crawler but I want it to crawl all the links that have the same base. For example if you set a big depth and you have a link in your page that links to your twitter, it will scan twitter and give you results like twitter.com/xxxyyyzzz. </p>

<p>What I want is to restrict the code to crawl only the urls that have the same base. I don't mind if I set the domain again in a new variable.</p>

<p>Filtering the results and showing only the correct links at the end is not the appropriate way. Imagine if you find 1000 links and you just want the 10.</p>

<p>Thank you for the ideas.
(the correct code is in the answer)</p>
