Grab The Title ? No ?

Discussion in 'HTML & Website Design' started by geekazoid, Jul 5, 2006.

  1. #1
    Is there any line of script i can put into a page that will change itself to the title of the page on the net ?
     
    geekazoid, Jul 5, 2006 IP
  2. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #2
    <?php
    function get_title_tag($chaine){
        $fp = fopen ($chaine, 'r');
        while (! feof ($fp)){
             $contenu .= fgets ($fp, 1024);
             if (stristr($contenu, '<title>' )){
                     break;
                    }
             }
        if (eregi("<title>(.*)</title>", $contenu, $out)) {
            return $out[1];
            }
        else{
            return false;
            }
        }
    ?> 
    PHP:
    echo get_title_tag('http://www.google.com'); 
    PHP:
     
    mad4, Jul 5, 2006 IP
  3. geekazoid

    geekazoid Peon

    Messages:
    208
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    is this a script which i can past into alll 300 of my pages and not have to worry about editing them individually because they all have individual titles allready ?
     
    geekazoid, Jul 5, 2006 IP
  4. tanfwc

    tanfwc Peon

    Messages:
    579
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You just need to call the function(get_title_tag)...You just need to edit the function if there is any code changes... :D
     
    tanfwc, Jul 5, 2006 IP
  5. geekazoid

    geekazoid Peon

    Messages:
    208
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Brilliant so i just past the 2 codes into my pages and i dont have to edit them in any way ?
     
    geekazoid, Jul 5, 2006 IP
  6. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Hang on, are you wanting a script to get the title of an external page thats not on your site or are you wanting a script to put a title onto all of your web pages?
     
    mad4, Jul 5, 2006 IP
  7. geekazoid

    geekazoid Peon

    Messages:
    208
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    it doesnt work ???
     
    geekazoid, Jul 5, 2006 IP
  8. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #8
    What are you trying to do?
     
    mad4, Jul 5, 2006 IP
  9. geekazoid

    geekazoid Peon

    Messages:
    208
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Right well i have a games website and im trying to get the line

    add this game to your website ...... So far i have

    <a href="http://www.geekazoid.co.uk<?php echo $_SERVER['REQUEST_URI']; ?>">TITLE OF THE PAGE HERE</a>

    Because the title of my 300 games pages is the name of the game on other peoples websites it would show the name of the game as a link to my page. and i just dont want to have to manually edit each page. I jsut want to paste the line into my pages and it would grab the url ( allready done ) and the title ( yet to find script ) automatically
     
    geekazoid, Jul 5, 2006 IP
  10. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Right. As I understand it you want to be able to echo the page title of the current page into a link?

    At the top of your page add the function I wrote above. Then you need to add the following where you want the title to appear.

    <a href="http://www.geekazoid.co.uk<?php echo $_SERVER['REQUEST_URI']; ?>"><?php echo get_title_tag('http://www.geekazoid.co.uk$_SERVER['REQUEST_URI']'); ?></a>
    PHP:
    I assume the titles are all hard coded into your pages rather than using a CMS? If you use a CMS there should be some kind of title variable you can use.
     
    mad4, Jul 5, 2006 IP
  11. geekazoid

    geekazoid Peon

    Messages:
    208
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Ok i think that would work brilliant, now just to make sure where do i put the first part the php function bit ? is it in the head ?
     
    geekazoid, Jul 5, 2006 IP
  12. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Somewhere at the top of the page will be fine.
     
    mad4, Jul 5, 2006 IP
  13. geekazoid

    geekazoid Peon

    Messages:
    208
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    geekazoid, Jul 5, 2006 IP
  14. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Try this:
    
    <?php
    $thispage="http://www.geekazoid.co.uk$_SERVER['REQUEST_URI']";
    ?>
    <a href="http://www.geekazoid.co.uk<?php echo $_SERVER['REQUEST_URI']; ?>"><?php echo get_title_tag('$thispage'); ?></a>
    PHP:
     
    mad4, Jul 5, 2006 IP
  15. geekazoid

    geekazoid Peon

    Messages:
    208
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15
    Ok i will try it.. gimme a sec, ....... Nope... Look at the link i gave before ^ Now it says that
     
    geekazoid, Jul 5, 2006 IP
  16. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #16
    If you post the code you have then I will try it. I'm online for a bit so I can sort it.
     
    mad4, Jul 5, 2006 IP
  17. geekazoid

    geekazoid Peon

    Messages:
    208
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #17
    if i post the code i have ? im affraid i dont know what you mean by that... all the script i have is what you gave me
     
    geekazoid, Jul 5, 2006 IP
  18. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #18
    
    <?php
    
    
    function get_title_tag(){  
    	$thesite="http://www.geekazoid.co.uk";
    	$thepage=$_SERVER['REQUEST_URI'];
    	$theurl="$thesite$thepage";  
    	$fp = fopen ("$theurl", 'r');    
    	while (! feof ($fp)){         
    		$contenu .= fgets ($fp, 1024);         
    		if (stristr($contenu, '<title>' )){                 
    			break;                
    			}         
    		}    
    		if (eregi("<title>(.*)</title>", $contenu, $out)) {        
    				return $out[1];        
    		}    
    		else{        
    			return false;        
    			}    
    }
    					?>
    <?php
    
    
    
    ?>
    <html>
    <title>This is the title</title>
    <body>
    <a href="http://www.geekazoid.co.uk<?php echo $_SERVER['REQUEST_URI']; ?>"><?php echo get_title_tag(); ?></a>
    </body>
    </html>
    
    PHP:
     
    mad4, Jul 5, 2006 IP
  19. geekazoid

    geekazoid Peon

    Messages:
    208
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #19
    what do i do with that ?
     
    geekazoid, Jul 5, 2006 IP
  20. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #20
    From your posts here and in other posts of your origin, I would say you need to establish a minimal knowledge base. We are not here to do the job for you, and that includes elementary step by step instruction. If that's what you need, you should hire the work done.

    If you wish help over a sticking point, that's another thing, but it requires that you do some work and study yourself. It also requires that you have at least some skills in html, css, php and javascript. These you must gain on your own. There are myriad tutorials on each subject just waiting for you. Google is your friend.

    cheers,

    gary
     
    kk5st, Jul 5, 2006 IP