Frame Posted July 1, 2010 Share Posted July 1, 2010 <?php $input = array("Prefix 1", "Prefix 2", "Prefix 3", "Prefix 4", "Prefix 5"); $rand_keys = array_rand($input, 2); $var = $input[$rand_keys[1]]; function tweet($username, $password, $message){ $api_url = 'http://twitter.com/statuses/update.xml'; $body = array( 'status'=>echo $var . $message ); $headers = array( 'Authorization' => 'Basic '.base64_encode("$username:$password") ); $result = fetch_url( $api_url, 'POST', $body, $headers ); return ( preg_match_all('!<error>[^<]+</error>!', $result, $matches) !== 1 ); } returns: Parse error: syntax error, unexpected T_ECHO in ... I have success with ( 'status'=>'Prefix' . $message ) were the Prefix and message are posted. Also just $var succeeds in sending message, but without the prefix. Any other syntax combo ends in an error. I don't know how to code this correctly. Any help is appreciated. Link to comment https://forums.phpfreaks.com/topic/206434-concatenate-with-var/ Share on other sites More sharing options...
kenrbnsn Posted July 1, 2010 Share Posted July 1, 2010 Why do think you need the "echo" in there? Just concatenate the values together: <?php $body = array( 'status'=> $var . $message); ?> Ken Link to comment https://forums.phpfreaks.com/topic/206434-concatenate-with-var/#findComment-1079882 Share on other sites More sharing options...
Frame Posted July 1, 2010 Author Share Posted July 1, 2010 Because it doesn't pass on the $var value. I thought it would, but it doesn't. So I added the echo. Link to comment https://forums.phpfreaks.com/topic/206434-concatenate-with-var/#findComment-1079889 Share on other sites More sharing options...
kenrbnsn Posted July 1, 2010 Share Posted July 1, 2010 Where are you setting $var. You're using it inside a function, so it either has to be passed in when the function is called or defined within the function. Ken Link to comment https://forums.phpfreaks.com/topic/206434-concatenate-with-var/#findComment-1079893 Share on other sites More sharing options...
Frame Posted July 1, 2010 Author Share Posted July 1, 2010 I love you Ken!! Link to comment https://forums.phpfreaks.com/topic/206434-concatenate-with-var/#findComment-1079895 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.