HELP Parse error: syntax error, unexpected T_STRING

Discussion in 'PHP' started by rahu_l_, Jun 4, 2012.

  1. #1
    i am trying to use an api of url shorter to shorten my wp urls..but i am getting
    "Parse error: syntax error, unexpected T_STRING" and this is my code..if someone can help me :)

    
    function isup()
    {
    	//login information
    	$url = get_permalink();  //for wordpress permalink
    	$format = 'json';	//choose between json or xml
    	//generate the URL
    	$isup = 'http://isup.in/api/new.json?url='.urlencode($url).';
    
    	//fetch url
    	$response = file_get_contents($isup);
    //for json formating
    	if(strtolower($format) == 'json')
    	{
    		$json = @json_decode($response,true);
    		echo $json['results'][$url]['shortUrl'];
    	}
    	else //for xml formatting
    	{
    		$xml = simplexml_load_string($response);
    		echo 'http://isup.in/'.$xml->results->nodeKeyVal->hash;
    	}
    }
    
    
    PHP:

     
    rahu_l_, Jun 4, 2012 IP
  2. Dablue

    Dablue Active Member

    Messages:
    132
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #2
    What line does it say the error is,

    my guess is this should work:

    
    function isup()
    {
        //login information
        $url = get_permalink();  //for  permalink
        $format = 'json';   //choose between json or xml
        //generate the URL
        $isup = 'http://isup.in/api/new.json?url='.urlencode($url);
    
        //fetch url
        $response = file_get_contents($isup);
    //for json formating
        if(strtolower($format) == 'json')
        {
            $json = @json_decode($response,true);
            echo $json['results'][$url]['shortUrl'];
        }
        else //for xml formatting
        {
            $xml = simplexml_load_string($response);
            echo 'http://isup.in/'.$xml->results->nodeKeyVal->hash;
        }
    }
    
    PHP:
     
    Dablue, Jun 4, 2012 IP
  3. rahu_l_

    rahu_l_ Well-Known Member

    Messages:
    535
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    175
    #3
    Hey thanks! it worked!
     
    rahu_l_, Jun 4, 2012 IP
  4. DaySeven

    DaySeven Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    2
    Trophy Points:
    0
    #4
    Yea, the problem was this line:

    
    $isup = 'http://isup.in/api/new.json?url='.urlencode($url).';
    
    Code (markup):
    at the end of the line you append an open quote to the string, but then never close it. As you aren't appending any content, the period and single tick quote can both be removed, leaving:

    
    $isup = 'http://isup.in/api/new.json?url='.urlencode($url);
    
    Code (markup):
     
    DaySeven, Jun 4, 2012 IP