Problem with a script and a dynamic <title>

Discussion in 'PHP' started by Cocacola123, Aug 22, 2010.

  1. #1
    I've sorted it out!!


    Thanks!!
     
    Last edited: Aug 22, 2010
    Cocacola123, Aug 22, 2010 IP
  2. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #2
    Not really sure if this is what you need, but to get a title from a facebook page you need to use curl, file_get_contents wont work.
    
    <?php 
    
    $url = "http://www.facebook.com/"; // this is the like url or any url
    
    function curl_get_contents($url){
    $ch = curl_init();
     	$useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";
    	curl_setopt($ch, CURLOPT_HEADER, 0);
    	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    	curl_setopt($ch, CURLOPT_URL, $url);
    	curl_setopt ($ch, CURLOPT_REFERER, 'http://www.mse360.com/about/bot.php');
     	curl_setopt ($ch, CURLOPT_USERAGENT, "MSE360 - FredBot (See: http://mse360.com/about/bot.php)");
    	curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
    	$source = curl_exec($ch);
    	curl_close($ch);
    	return $source;
    }
    $start_text = "<title>";
    $end_text = "</title>";
    $source = curl_get_contents($url);
    $start_pos = strpos($source, $start_text) + strlen($start_text);
    $end_pos = strpos($source, $end_text) - $start_pos;
    $found_text = substr($source, $start_pos, $end_pos);
    
    echo $found_text;
    
    ?>
    
    PHP:
    $found_text will represent the Title of the url given above
     
    MyVodaFone, Aug 22, 2010 IP
  3. Cocacola123

    Cocacola123 Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    MMMM No, thanks but that wasn't what I meant.

    Look, the "like" work like this:

    Somebody writes "I love chocolate" in the randomlikepage.com (not facebook)
    Then, still inside the "like page" (likepage.com) he hits "like"
    Later in his facebook profile it appears: 'Clark Kent likes "I love chocolate" in likepage.com' // Clark Kent likes "I love chocolate" (which is the curren title of the page) in likepage.com (which si obviously the name of the page)

    My problem is that
    This script displays in facebook: 'Clark Kent likes "Like page" in randomlikepage.com' not the actual title of the page beacuase the <title> tag is not dynamic.

    The current and dynamic title of a page is represented by the variable $fetch[title] so I want to have a <title> tag that corresponds exactly to the $fetch[title] variable.



    Thanks again mate!!
     
    Cocacola123, Aug 22, 2010 IP