PHP: extract links AND description from html

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default PHP: extract links AND description from html

    extracting just the links from a webpage is no problem for me ->
    regex /<a ([^>]*)>/i

    but now i want to extract the link and the discription that stands between
    the <a href=> and the </a> tag.

    as a result from the script that i'm searching for, i want to get the full

    <a href=http://www.blabla.com/test/d.html>DESCRIPTOIN</a>

    can anybody give me some hint, how to do this?




    Nils Jansen Guest

  2. Similar Questions and Discussions

    1. help data extract to text without html tag
      Hi Ive a page as below and it will save the record to text, but it does not save the file as what I needed. when i open up the file it didplaay...
    2. HTML in service description
      Hi I've documenten my webservice with html tags in the description. For a day ago this worked. Now suddenly all is treated as plain text and it...
    3. [PHP] Extract a little string from a Html page ?
      I tried something else but... It doesn't work too :-( . <? php $fichier=implode('',array_map('trim',readfile("http://myurl.com"))); if (eregi...
    4. extract from html
      hi, how can i extract the number between text1 and text2 in input.html only the first time it occurs ignoring the rest? preferably input.html...
    5. When we move Image Links and HTML links
      On our Local Site (hard drive), our web projects is almost complete and we have already uploaded and sync the internet site (remote site). I have...
  3. #2

    Default Re: extract links AND description from html

    Nils Jansen wrote:
    > as a result from the script that i'm searching for, i want to get the
    > full
    >
    > <a href=http://www.blabla.com/test/d.html>DESCRIPTOIN</a>
    >
    > can anybody give me some hint, how to do this?
    Try this (remark: array_combine is a PHP 5 specific function, see the manual
    entry for this function on php.net for a PHP 4 example);

    <?php

    // Fetch the content
    $file = file_get_contents("http://www.php.net/");

    // Construct the regular expression
    // (does not accept image links)
    $reg = "#<a.*href\s*=\s*(\"|')?([^\"'>]+).*>([^<>]+)</a>#i";

    // Parse $file
    if (preg_match_all($reg, $file, $matches)) {
    print "<pre>";
    print_r(array_combine($matches[2], $matches[3]));
    print "</pre>";
    }

    ?>


    HTH;
    JW



    Janwillem Borleffs Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139