#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 1999
    Posts
    5
    Rep Power
    0
    Hi.


    Can someone help me with a regexp that I need?
    $html="<b><a href="url">somthing</a><br><a href="url">somthing here</a>";

    What I need to do is collect all the html links inside a string (<a href="url">somthing</a> ) and add them to an array.

    If anyone can help me, that would be very appretiated.

    Thanks.

    [This message has been edited by Dass (edited January 30, 2000).]
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 1999
    Location
    Annapolis, Maryland US
    Posts
    113
    Rep Power
    15
    This is kind of a kludge, but it should point you in the right direction

    <?

    $html="<HTML><BODY><P><A HREF="url1">first link</A><P><A HREF="url2">second
    link</A></BODY></HTML>";

    $firstlist=split("<[/]?a|A[>]?", $html);

    // find out which indexes contain "HREF" or "href"
    // if it does, prepend "<A " and append "</A>" to it and put in new array

    for($i=0; $i<count($firstlist); $i++)
    {
    if(eregi("HREF", $firstlist[$i]))
    $secondlist[]="<A ".$firstlist[$i]."</A>";
    }


    // $secondlist array should contain all the links

    for($i=0; $i<count($secondlist); $i++)
    print"$secondlist[$i]<br>";


    ?>
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 1999
    Posts
    5
    Rep Power
    0
    I played around and got did the following:

    if( eregi('<a href="<[^>]*>">"<[^>]*></a>', $input, $links));
    {
    $customlinks .= "<a href="$links[1]">$links[2]</a><br>";
    }

    But It is giving me errors:
    Warning: No such index in string in /home/rob/www/customlinks.php3 on line 67

    Warning: No such index in string in /home/rob/www/customlinks.php3 on line 67

    Which I guess means that $links[1] and [2] don't exist?

    Is there somthing wrong with my code?
    Thanks.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 1999
    Location
    Annapolis, Maryland US
    Posts
    113
    Rep Power
    15
    I'm having difficulty understanding the pattern in your eregi() function. Anyhow, I believe you have to escape any quotes -> " in the pattern string to match a literal quote -> " in the target string

Similar Threads

  1. Back-references to groups with regexp or rlike
    By fmhoyt in forum MySQL Help
    Replies: 1
    Last Post: October 6th, 2003, 06:21 AM
  2. MySQL REGEXP [[.anything.]] won't work ?
    By Kore in forum PHP Development
    Replies: 9
    Last Post: March 25th, 2003, 03:12 PM
  3. MySQL REGEXP (non-greedy)??
    By chovy in forum MySQL Help
    Replies: 1
    Last Post: August 12th, 2002, 04:27 PM
  4. External javascript files and AOL??
    By true2u1 in forum JavaScript Development
    Replies: 7
    Last Post: December 6th, 2001, 08:56 AM
  5. Faster Searching?
    By derrickatdev in forum MySQL Help
    Replies: 4
    Last Post: April 29th, 2001, 12:14 PM

IMN logo majestic logo threadwatch logo seochat tools logo