PHP Function in Facebook "Share" link

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
AutoRunway
Forum Newbie
Posts: 9
Joined: Wed Apr 07, 2010 2:38 pm

PHP Function in Facebook "Share" link

Post by AutoRunway »

I'm trying to put a "share this" link to facebook...

I can use this format
http://www.facebook.com/sharer.php?u=<url to share>&t=<title of content>

So my link would look something like this
<a href="http://www.facebook.com/sharer.php?u=ht ... r.org&t=My GPA is <?php echo $_POST['gpa']; ?>">Share your GPA on Facebook</a>

But I get a syntax error when I try to place the link here

Code: Select all

if ($cc>$tc) { //means all steps have been completed
	$gpa = $points / $credits;
	echo "<hr /><div align='center'><p class='results'>Your GPA is $gpa!<br /><a href="http://www.facebook.com/sharer.php?u=http://www.gpacalculator.org&t=My GPA is <?php echo $_POST['gpa']; ?>">Share your GPA on Facebook</a></p>";
	if ($gpa>=3.5) { 
		echo "<p><b>Congratulations! You've achieved the Honor Roll!</b></p>"; 
	}
Can you please help me post the link correctly
solid
Forum Commoner
Posts: 28
Joined: Wed Aug 12, 2009 11:56 am

Re: PHP Function in Facebook "Share" link

Post by solid »

You are opening a PHP tag from within a PHP tag. Try something like this...

Code: Select all

if ($cc>$tc) { //means all steps have been completed
        $gpa = $points / $credits;
        echo "<hr /><div align='center'><p class='results'>Your GPA is " . $gpa
           . "!<br /><a href="http://www.facebook.com/sharer.php?u=http://www.gpacalculator.org&t="
           . urlencode('My GPA is ' . $gpa) . ">Share your GPA on Facebook</a></p>";
        if ($gpa>=3.5) {
                echo "<p><b>Congratulations! You've achieved the Honor Roll!</b></p>";
        }
Post Reply