SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru
    Join Date
    Aug 2001
    Location
    Amsterdam
    Posts
    788
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    adding target value to a link

    Hi all..

    It's been a while since I used the sitepointforum I really like what you did with it!!

    A question..

    I want to change links on my site to have a target=_new if the link is not to my site..

    So for instance if a user adds a link (with my content management system) I want php to change this link to open a new window if the link goes to an other site ..

    I hope you understand and you know how to do this....

    Thanks in advance ....

    Peanuts
    the neigbours (free) WIFI makes it just a little more fun

  2. #2
    SitePoint Zealot Overgrow's Avatar
    Join Date
    Jan 2001
    Location
    Your basement
    Posts
    192
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    if (!preg_match("/mydomain.com/i",$userslink)) { // not your domain
    $userslink='<a href="link.com" target="_blank">';
    } else {
    $userslink='<a href="link.com">';

    Overgrow the Government: The Edge Forums
    presented by Overgrow Marijuana Magazine

    *warning: adult content

  3. #3
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    if (preg_match("/mydomain.com/i",$userslink)) { // is your domain
    $userslink='<a href="link.com">';
    } else {
    $userslink='<a href="link.com" target="_blank">';

    or that.. heh, saves one bit.
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  4. #4
    SitePoint Guru
    Join Date
    Aug 2001
    Location
    Amsterdam
    Posts
    788
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    thanks but I have some more problems

    Quote Originally Posted by cyborg from dh
    PHP Code:
    if (preg_match("/mydomain.com/i",$userslink)) { // is your domain
    $userslink='<a href="link.com">';
    } else {
    $userslink='<a href="link.com" target="_blank">';

    or that.. heh, saves one bit.
    Thanks guys ...

    But in your examples the link is in a seperate variable...

    my content management system provides one variable with all the text en links and make-up..

    I want to find links and then do the check on domain..

    Greets,

    Peanuts
    the neigbours (free) WIFI makes it just a little more fun


Bookmarks

Posting Permissions

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