Is there a PHP code that can make all the links in a page to nofollow?

Discussion in 'PHP' started by Andy_ameed, Jan 16, 2010.

  1. #1
    It seems in Javascript its impossible. Is it possible in PHP. does anyone have any idea for it?
     
    Andy_ameed, Jan 16, 2010 IP
  2. tenev

    tenev Active Member

    Messages:
    322
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    95
    #2
    well this is possible, but to do it you just have to edit the PHP code (if its php) or the HTML code.

    now, if there is too much code that u don't really understand where links come from, you can use the php buffer and str_replace for all links to add nofollow
     
    tenev, Jan 16, 2010 IP
  3. Andy_ameed

    Andy_ameed Active Member

    Messages:
    129
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #3
    <?php
    $olderror_reporting =error_reporting(0);
    include ("http://rssfeedreader.com/rss3/rss.php?url=http%3A%2F%2Ffeeds.reuters.com%2Freuters%2FUSVideoTopNews&newpage=1&chead=&atl=&desc=&owncss=1&eleminate=&auth=&dts=&width=300&max=10&tlen=0&rnd=1&bt=3&bs=Double&nmb=&ntb=&naf=&nst=&nwd=0&nht=0&dlen=0&lstyle=-1&lc=Blue&bg=White&bc=Gray&spc=&ims=&tc=&ts=11&tfont=Verdana,+Arial,+Sans-serif&rf=".$HTTP_SERVER_VARS['SERVER_NAME'].$HTTP_SERVER_VARS['PHP_SELF']."&phpout=1");
    error_reporting($olderror_reporting);
    ?>
    Code (markup):
    here is the code that generates the links. and the page these code is a .php extention

    can you work out a way for this?
     
    Andy_ameed, Jan 16, 2010 IP
  4. astkboy2008

    astkboy2008 Peon

    Messages:
    211
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    look here
    the function there make any link nofollow
     
    astkboy2008, Jan 17, 2010 IP
  5. Andy_ameed

    Andy_ameed Active Member

    Messages:
    129
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #5
    1 $file = file_get_contents("url here");
    2 $file = nofollow($file);
    3 echo $file;

    Actually, its not a file.. it a dynamic rss content that is being called.

    that code is not working
     
    Andy_ameed, Jan 17, 2010 IP
  6. astkboy2008

    astkboy2008 Peon

    Messages:
    211
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
  7. CodedCaffeine

    CodedCaffeine Peon

    Messages:
    130
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Including code remotely via another source? I'll pass on that. (G'day server exploit! How's the weather?)

    If you're wanting to do it for them all, you can use a meta field to do it with one line of code:
    <meta name="robots" content="index,nofollow" />
    Code (markup):
    You can also do it with php by something like..
    
    #Start the output buffer.
    ob_start();
    
    # [..]code here[..] #
    
    # Dump all the data that is suppose to be rendered in the browser into a var.
    $contents = ob_get_contents();
    
    #Remove the old buffer contents.
    ob_end_clean();
    
    # Go through the var and change all anchor tags to have rel="nofollow".
    preg_replace( SEARCH_REGEX, REPLACE_REGEX, $contents);
    
    # Then give to the browser.
    print $contents;
    PHP:
    Unfortunately, I cannot help with the REGEX statements as I cannot make sense of them. >_<
     
    Last edited: Jan 17, 2010
    CodedCaffeine, Jan 17, 2010 IP