Php function

Discussion in 'PHP' started by iatbm, Feb 10, 2006.

  1. #1
    Is there php function i can implement in my website that all links that are clicked are opened in new window....

    thank you
     
    iatbm, Feb 10, 2006 IP
  2. Bob_

    Bob_ Peon

    Messages:
    31
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can do it with the "<a>" command.

    <a target="_blank" href="link">Title</a>
    Code (markup):
    The {target="_blank"} is the important bit. It makes the link open in a new window.

    You also have _parent, _self and _top but never used them so don't know exactly what they do.
     
    Bob_, Feb 10, 2006 IP
  3. iatbm

    iatbm Prominent Member

    Messages:
    5,151
    Likes Received:
    352
    Best Answers:
    0
    Trophy Points:
    360
    #3
    I knew that, but thank you anyway.....

    I am looking for php function or javascript example of this.

    If there is a chance that new link openes no matter which link you click
     
    iatbm, Feb 10, 2006 IP
  4. iatbm

    iatbm Prominent Member

    Messages:
    5,151
    Likes Received:
    352
    Best Answers:
    0
    Trophy Points:
    360
    #4
    I want all my links to open in new window except adsense ofcourse :)

    Anyone ?
     
    iatbm, Feb 10, 2006 IP
  5. mdvaldosta

    mdvaldosta Peon

    Messages:
    4,079
    Likes Received:
    362
    Best Answers:
    0
    Trophy Points:
    0
    #5
    As far as I know your going to have to change them manually.
     
    mdvaldosta, Feb 10, 2006 IP
  6. iatbm

    iatbm Prominent Member

    Messages:
    5,151
    Likes Received:
    352
    Best Answers:
    0
    Trophy Points:
    360
    #6
    to be exact i need links from rss feeds to open in new window :)

    I want to keep visitors on my site also
     
    iatbm, Feb 10, 2006 IP
  7. onlyican.com

    onlyican.com Peon

    Messages:
    206
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    If you used a function, you would have to tell the link to visit the function.

    There is a way, I think it was using CSS
    Can't remember tho

    BRAINWAVE

    Build a little script that grabs the feed, and do a str_replace

    Replcae <a href with <a target='_blank' href

    Worth a try.
     
    onlyican.com, Feb 10, 2006 IP
  8. iatbm

    iatbm Prominent Member

    Messages:
    5,151
    Likes Received:
    352
    Best Answers:
    0
    Trophy Points:
    360
    #8
    Here is the code ...

    how can i implement links from feeds to open in new window ?


    <?
    /*
    crispy_RSS®
    http://jamesr.net/rss
    -----------------------------------------------------
    Compiled by James Roberts (http://jamesr.net/)
    Stolen from various sources on and around the web.

    * Modified for use with Movable Type and LiveJournal
    generated RSS feeds.
    */


    error_reporting(0);
    function startElement($parser, $tagName, $attrs) {
    global $insideitem, $tag;
    if ($insideitem) {
    $tag = $tagName;
    } elseif (($tagName == "ITEM") || ($tagName == "IMAGE")) {
    $insideitem = true;
    }
    }
    function endElement($parser, $tagName) {
    global $insideitem, $tag, $title, $description, $link, $iurl, $i, $n;
    if ($i >= $n) {
    return;
    }
    // Display Image elements [Edit markup below to customise output]
    if ($tagName == "IMAGE") {
    printf("<div class=\"rss_img\"><a href='%s'>", trim($link));
    printf("<img src='%s' border='0' />", $iurl);
    printf("</a></div>");
    $title = "";
    $description = "";
    $link = "";
    $iurl = "";
    $insideitem = false;
    }
    // Display text CDATA [Edit markup below to customise output]
    if ($tagName == "ITEM") {
    printf("<div class=\"rss_title\"><a href=\"$link\">");
    printf(htmlspecialchars(trim($title)));
    printf("</a></div>\n");
    printf("<div class=\"rss_desc\">");
    if (strlen ($description) > 0) {
    printf(trim($description));
    }
    printf("</div>\n");
    $title = "";
    $description = "";
    $link = "";
    $iurl = "";
    $insideitem = false;
    $i += 1;
    }
    }
    function characterData($parser, $data) {
    global $insideitem, $tag, $title, $description, $link, $iurl;
    if ($insideitem) {
    switch ($tag) {
    case "TITLE":
    $title .= $data;
    break;
    case "DESCRIPTION":
    $description .= $data;
    break;
    case "LINK":
    $link .= $data;
    break;
    case "URL":
    $iurl .= $data;
    break;
    }
    }
    }
    function parse_feed ($url, $num) {
    global $insideitem, $tag, $title, $description, $link, $iurl, $i, $n;

    $insideitem = false;
    $tag = "";
    $title = "";
    $description = "";
    $link = "";
    $iurl = "";
    $i = 0;
    $n = $num;

    // Prepare and create the expat parser.
    $xml_parser = xml_parser_create();
    xml_set_element_handler($xml_parser, "startElement", "endElement");
    xml_set_character_data_handler($xml_parser, "characterData");
    $fp = fopen($url,"r")
    or die("Error reading RSS data.");
    while ($data = fread($fp, 4096)) {
    xml_parse($xml_parser, $data, feof($fp))
    or die(sprintf("XML error: %s at line %d",
    xml_error_string(xml_get_error_code($xml_parser)),
    xml_get_current_line_number($xml_parser)));
    }
    fclose($fp);
    xml_parser_free($xml_parser);
    $i = 0;
    }
    ?>
     
    iatbm, Feb 10, 2006 IP
  9. onlyican.com

    onlyican.com Peon

    Messages:
    206
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Have you tried to edit the code,
    where is says <a href
    to say <a target='_blank' href
     
    onlyican.com, Feb 10, 2006 IP
  10. iatbm

    iatbm Prominent Member

    Messages:
    5,151
    Likes Received:
    352
    Best Answers:
    0
    Trophy Points:
    360
    #10
    Simple :) .... thank you ... i did something wrong earlier :)

    Thank you again i can not stop lol ....
     
    iatbm, Feb 10, 2006 IP