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
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:
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&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
(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):