URL and Title

Discussion in 'PHP' started by interval, Jan 14, 2008.

  1. #1
    Hi,

    Say we have a page
    http://www.mypage.php
    and its title is: important notice

    How could I find url and title using php?

    Thanks
    Interval
     
    interval, Jan 14, 2008 IP
  2. gsv13

    gsv13 Well-Known Member

    Messages:
    2,773
    Likes Received:
    114
    Best Answers:
    0
    Trophy Points:
    130
    #2
    lol :rolleyes: what kind of address is that ? What question!!!
     
    gsv13, Jan 14, 2008 IP
  3. interval

    interval Peon

    Messages:
    53
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    interval, Jan 14, 2008 IP
  4. rkquest

    rkquest Well-Known Member

    Messages:
    828
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    140
    #4
    I'm not sure what you're trying to do. But if what you're looking for is a script that will get a page's title, try this one that I made. Just replace the URL at the end of the script.

    
    <?php
    
    function get_title($url) {
    	$handle = fopen($url, 'r');
    	$contents = '';
    	while (!feof($handle)) {
    		$content .= fread($handle, 1024*8);
    	}
    	fclose($handle);
    	preg_match('/\<title\>(.*?)\<\/title\>/', $content, $temp);
    	return $temp[1];
    }
    
    echo get_title('http://forums.digitalpoint.com/showthread.php?t=653888'); // replace the URL
    	
    ?>
    
    PHP:
     
    rkquest, Jan 14, 2008 IP
  5. interval

    interval Peon

    Messages:
    53
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thank you rkquest, your script is great

    Now another question:

    I have http://www.mydom.com
    and pages
    http://www.mydom.com/page1.php
    http://www.mydom.com/page1.php
    http://www.mydom.com/page1.php

    I want to offer my visitors the opportunity to bookmark every page to del.icio, digg, furl etc.

    The simpliest, but hardest, solution is to write a code for every page, like that (considering only del.icio.us)
    <a
    href="http://del.icio.us/post?url=http://www.mydom.com&amp;title=titlepage1" title="del.icio.us" ><img src="http://www.mydom.com/bm/delicious.png"
    alt="del.icio.us" height="15" width="15" hspace="1" border=0></a>
    That way, visitors will press an icon to access del.icio.us

    My desire is to build a code available for all pages, to put it on special file and to include on every page I need:
    Question: How should I change this link? Should I replace ???? with what ?

    <a
    href="http://del.icio.us/post?url=????;title=????" title="del.icio.us" >

    Advanced thanks
    Interval
     
    interval, Jan 15, 2008 IP
  6. woods

    woods Peon

    Messages:
    228
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #6
    (I assume the delicious bookmarks will be on the same site as you are, and you are getting the title from the same page as you're on)

    First of all change the code in your pageX.php files and save the title in a variable and echo it in the title. Trust me, it will suck up a lot if you load the page again just to get the title. (Imagine getting #1 on digg/google news/whatever and you are requesting 2 pages instead of one. 1000 visits = 2k pages requested on your server)

    So then you have the title in for example $title. All you have to do then is get the current URL using the $_SERVER['..'] variables

    Just put it in a separate file along with the example code below and include it on every page, include('file.inc');

    http://php.net/reserved.variables

    Example:
    <a 
    href="http://del.icio.us/post?url=<?php echo $current_url; ?>;title=<?php echo $title; ?>" title="del.icio.us" >
    Code (markup):
     
    woods, Jan 15, 2008 IP