title: PHP Get all Urls from string
body: <p>So I'm trying to get all the urls from a string with a script that looks like this:</p>
  
  <pre><code>$file = file_get_contents('something.txt');
  
  function getUrls($string) {
      preg_match_all('~href=("|\')(.*?)\1~', $string, $out);
      print_r($out);
  }
  
  getUrls($file);
  </code></pre>
  
  <p>The urls contained in this document may be imperfect - i.e. "/blah/blah.asp?2". The problem is that when I run this script, I get an array that looks something like this:</p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [0] =&gt; href="#A"
              [1] =&gt; href="#B"
              [2] =&gt; href="#C"
          )
  
      [1] =&gt; Array
          (
              [0] =&gt; "
              [1] =&gt; "
              [2] =&gt; "
          )
  
      [2] =&gt; Array
          (
              [0] =&gt; #A
              [1] =&gt; #B
              [2] =&gt; #C
  
          )
  
  )
  </code></pre>
  
  <p>Any idea what could be going on here? I have no idea why it is returning alphabetical lists with hash signs instead of the desired urls. How can I go about just returning the urls? </p>