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

    Join Date
    Jun 1999
    Location
    Olympia, WA, USA
    Posts
    13
    Rep Power
    0
    Ok, what I'm looking for is a regular expression function (or anything that works for that matter) that will take a variable, look through the variable for URLs and covert those to links.

    $somevar = "Visit our web site at <A HREF="http://www.somedomain.com/da/index.html";" TARGET=_blank>http://www.somedomain.com/da/index.html";</A>

    Converted to...
    $somevar = "Visit our web site at <a href='http://www.somedomain.com/da/index.html'>http://www.somedomain.com/da/index.html</a>";

    It also needs to find more than one domain per variable (repeating).

    I would appreciate any help in this problem... I'm pretty sure that someone has to have done this before also.

    Thanks,
    Luke Bowerman

    P.S. I just noticed that this forum package does exactly what I want with the url parsing (unfortunately it's programmed in PERL)
    ------------------
    Luke Bowerman
    new media arts
    www.newmediaarts.org

    [This message has been edited by newmediaarts (edited August 25, 2000).]
  2. #2
  3. No Profile Picture
    Viper_SB
    Guest
    Devshed Newbie (0 - 499 posts)
    Use a search and replace.

    ------------------
    Viper_SB
  4. #3
  5. No Profile Picture
    RyanP
    Guest
    Devshed Newbie (0 - 499 posts)
    try this out
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    $vars = explode(" ", $var);

    while(list($key, $value) = each($vars))
    {
    if(preg_match("/^https?:///i", $value))
    {
    preg_match("/W*$/", $value, $matches);
    $value = preg_replace("/W*$/", "", $value);

    $value = "<a href="$value">$value</a>$matches[0]";

    $vars[$key] = $value;
    }
    elseif(preg_match("/^www./i", $value))
    {
    preg_match("/W*$/", $value, $matches);
    $value = preg_replace("/W*$/", "", $value);

    $value = "<a href="http://$value">$value</a>$matches[0]";

    $vars[$key] = $value;
    }
    }

    $var = implode(" ", $vars);
    [/code]

    this should work for the most part, let me know if you want me to add any more features, like email link auto-conversion, or fix any bugs

    [This message has been edited by RyanP (edited August 25, 2000).]
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Plano, TX, USA
    Posts
    1
    Rep Power
    0
    I've been using this PHP function and it works beautifully. Just pass a string to it, and it returns a string formatted correctly for links and mailto:'s.

    Enjoy.


    function q($str) {
    $str = ereg_replace("((f|ht){1}tp://[a-zA-Z0-9@:%_.~#-?&]+)", "<a href="1">1</a>", $str);
    $str = ereg_replace("([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+.[a-zA-Z0-9._-]+)","<a href="mailto:1">1</a>", $str);
    return $str;
    }


    Ronnie

    ------------------
    --
    Ronnie T. Moore
    http://javascriptsource.com
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    2
    Rep Power
    0
    I have got a url who look like this: http://superfredrik.cjb.net?user[]=russlndr

    This will not work in Ronnies example. I must add the [ char and I can't figure out how!

    Anyone?

    - Fredrik

Similar Threads

  1. regular expression
    By Wizard2003 in forum Python Programming
    Replies: 2
    Last Post: February 12th, 2004, 07:52 AM
  2. validating ZIP code with regular expression
    By hade in forum HTML Programming
    Replies: 3
    Last Post: February 9th, 2004, 07:05 AM
  3. UTF-8 problem in 4.1.1a
    By mehran20 in forum MySQL Help
    Replies: 1
    Last Post: February 8th, 2004, 02:21 PM
  4. Regular expression (?) in a mysql field
    By acp in forum PHP Development
    Replies: 5
    Last Post: February 6th, 2004, 10:09 AM
  5. Regular expression question
    By bonzaitrimmer in forum .Net Development
    Replies: 1
    Last Post: January 26th, 2004, 07:41 PM

IMN logo majestic logo threadwatch logo seochat tools logo