General Question

Newboston's avatar

What's wrong with this simple PHP script?

Asked by Newboston (2points) March 9th, 2011
4 responses
“Great Question” (0points)

I’m trying to make a simple page that uses the TinyURL API to generate a short URL, but something is going wrong. No matter what I do, I’m getting the same error every time. I’m suspecting it may be a host-related issue, or maybe even an error on TinyURL’s side? The error is “Unexpected T_VARIABLE at line 6.” I’m hosting with GoDaddy. Is there something I need to configure? I’m not sure what the deal is, but please take a look, here’s the code:

<?php

$long = $_POST[‘long_url’];

function shorten($the_long_url) {
    $short = file_get_contents(‘http://tinyurl.com/api-create.php?url=’.$the_long_url);
    return $short;
}

echo (shorten($long));

?>

Topic:
Observing members: 0
Composing members: 0

Answers

6rant6's avatar

Do you need a concatenation operator (.) between your string and the variable name ($the_long_url)? But like this:
’”.$var.”’

http://www.gidforums.com/t-965.html

Newboston's avatar

I don’t understand what you’re saying. I need to concatenate the two strings so I can send the $the_long_url to TinyURL for shortening. I tried putting apostraphes around the variable, but I’m still getting “Parse error: syntax error, unexpected T_VARIABLE in Line 6.”

nicobanks's avatar

I suggest you go to a web development website – you’ll get more answers and it’s more likely the answers you get will be good. I really like WDG.

Vincentt's avatar

I’ve got a feeling this should be really simple but unfortunately I can’t see it right away, and I’m not on a development machine to test it. The only thing I can see is that you aren’t using the right quotes, but that’s probably Fluther’s issue, right? To make sure that’s not the problem, here’s the code with correct quotes: http://pastebin.com/bK0QyJc6

Apart from that though, I would like to note that echo doesn’t need brackets around its arguments (and is recommended against as it’s not actually a function). And also, though I’m not sure of that since it’s been a while, that I believe you could only use file_get_contents() for local files, not files on another host.

You might want to use the Zend_Http_Client() class from the Zend Framework, which will also allow you to check response headers and the like to check whether the URL shortening request was successful.

Answer this question

Login

or

Join

to answer.

Mobile | Desktop


Send Feedback   

`