digi duck Posted September 4, 2006 Share Posted September 4, 2006 I am getting an this error message:Parse error: parse error, unexpected $ in /home/www/gamesigs.co.uk/_sig_created.php on line 124line 124 is the last line of the code.here is the code. [code]<?header("Content-type: image/jpeg");$name = stripslashes($_GET['name']);$size = stripslashes($_GET['size']);$font = 'images/sig_maker/fonts/'.stripslashes($_GET['font']).'.ttf';$fontcolor['r'] = stripslashes($_GET['color_r']); // font color - RED$fontcolor['g'] = stripslashes($_GET['color_g']); // font color - GREEN$fontcolor['b'] = stripslashes($_GET['color_b']); // font color - BLUE$shadow = stripslashes($_GET['shadow']);$lines = stripslashes($_GET['lines']);function arrow($im, $x1, $y1, $x2, $y2, $alength, $awidth, $color){///}switch ($_GET['color']) {case '1':$bgpic = 'images/sig_maker/1.jpeg';break;case '2':$bgpic = 'images/sig_maker/2.jpeg';break;case '3':$bgpic = 'images/sig_maker/3.jpeg';break;case '4':$bgpic = 'images/sig_maker/4.jpeg';break;case '5':$bgpic = 'images/sig_maker/5.jpeg';break;case '6':$bgpic = 'images/sig_maker/6.jpeg';break;case '7':$bgpic = 'images/sig_maker/7.jpeg';break;case '8':$bgpic = 'images/sig_maker/8.jpeg';break;case '9':$bgpic = 'images/sig_maker/9.jpeg';break;case '10':$bgpic = 'images/sig_maker/10.jpeg';break;case '11':$bgpic = 'images/sig_maker/11.jpeg';break;case '12':$bgpic = 'images/sig_maker/12.jpeg';break;case '13':$bgpic = 'images/sig_maker/13.jpeg';break;case '14':$bgpic = 'images/sig_maker/14.jpeg';break;case '15':$bgpic = 'images/sig_maker/15.jpeg';break;case '16':$bgpic = 'images/sig_maker/16.jpeg';break;case '17':$bgpic = 'images/sig_maker/17.jpeg';break;case '18':$bgpic = 'images/sig_maker/18.jpeg';break;case '19':$bgpic = 'images/sig_maker/19.jpeg';break;case '20':$bgpic = 'images/sig_maker/20.jpeg';break;case '21':$bgpic = 'images/sig_maker/21.jpeg';break;case '22':$bgpic = 'images/sig_maker/22.jpeg';break;case '23':$bgpic = 'images/sig_maker/23.jpeg';break;case '24':$bgpic = 'images/sig_maker/24.jpeg';break;case '25':$bgpic = 'images/sig_maker/25.jpeg';break;case '26':$bgpic = 'images/sig_maker/26.jpeg';break;case '27':$bgpic = 'images/sig_maker/27.jpeg';break;}$im = imagecreatefromjpeg($bgpic);//Calculate, the centre:for(;;){list($image_width, $image_height) = getimagesize($bgpic);list($left_x, , $right_x) = imagettfbbox($size, 0, $font, $name);$text_width = $right_x - $left_x;if($image_width > $text_width+5){break;}$size = $size - .5;if($size == 1){die('Script not responding to decreasing font size, in other words: try using less letters.');}}$padding = ($image_width - $text_width)/2;$textcolor = imagecolorresolve($im, $fontcolor['r'], $fontcolor['g'], $fontcolor['b']);$grey = imagecolorallocate($im, 128, 128, 128);if($shadow == 'y'){imagettftext($im, $size, 0, $padding+1, 77, $grey, $font, $name);}if($lines == 'y'){//imagettftext($im, $size, 0, $padding+1, 77, $grey, $font, $name);}imagettftext($im, $size, 0, $padding, 75, $textcolor, $font, $name);if($_GET['dl']){imagegif($im);?>[/code]i want to put this on a html page but it keeps on coming up with this error. I thought it was supposed to be because of white space before the start of php or brackets that don't pair up but it looks like these are all ok. PLEASE HELP Quote Link to comment https://forums.phpfreaks.com/topic/19685-parse-error-unexpected-very-fustrating-please-help/ Share on other sites More sharing options...
tomfmason Posted September 4, 2006 Share Posted September 4, 2006 that means that you are missing a [code=php:0]}[/code] somewhere. You need to close the [code=php:0]switch[/code]. Your code is hard to follow. The better/cleaner way would be like this.[code]<?phpfunction testfuntion() { if ($someting == $somethingelse) { //do something } //do something else if ($something2 == somethingelse2) { //do something else }}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/19685-parse-error-unexpected-very-fustrating-please-help/#findComment-85857 Share on other sites More sharing options...
wildteen88 Posted September 4, 2006 Share Posted September 4, 2006 Also there is no need to use the swtich statement either. Just use an if statement:[code=php:0]if(is_numeric($_GET['color']) && $_GET['color'] >= '1' && $_GET['color'] <= '27'){ $bgpic = 'images/sig_maker/' . $_GET['color'] . '.jpeg';}[/code]Also this:[code]for(;;)[/code]Is not valid. You cant have an emtpy for loop. Quote Link to comment https://forums.phpfreaks.com/topic/19685-parse-error-unexpected-very-fustrating-please-help/#findComment-85861 Share on other sites More sharing options...
digi duck Posted September 4, 2006 Author Share Posted September 4, 2006 can you tell me where im missing the { as im a novice and have no idea where they are supposed to go. And thanks for the cleaner code ill implement that in when i have this working. Quote Link to comment https://forums.phpfreaks.com/topic/19685-parse-error-unexpected-very-fustrating-please-help/#findComment-85866 Share on other sites More sharing options...
wildteen88 Posted September 4, 2006 Share Posted September 4, 2006 Well you can start by indenting your code. This will help you working out where your { and } are supposed to go. But I have done it for you:[code]<?phpheader("Content-type: image/jpeg");$name = stripslashes($_GET['name']);$size = stripslashes($_GET['size']);$font = 'images/sig_maker/fonts/'.stripslashes($_GET['font']).'.ttf';$fontcolor['r'] = stripslashes($_GET['color_r']); // font color - RED$fontcolor['g'] = stripslashes($_GET['color_g']); // font color - GREEN$fontcolor['b'] = stripslashes($_GET['color_b']); // font color - BLUE$shadow = stripslashes($_GET['shadow']);$lines = stripslashes($_GET['lines']);function arrow($im, $x1, $y1, $x2, $y2, $alength, $awidth, $color){///}if(is_numeric($_GET['color']) && $_GET['color'] >= '1' && $_GET['color'] <= '27'){ $bgpic = 'images/sig_maker/' . $_GET['color'] . '.jpeg';}$im = imagecreatefromjpeg($bgpic);//Calculate, the centre:for(;;){ list($image_width, $image_height) = getimagesize($bgpic); list($left_x, , $right_x) = imagettfbbox($size, 0, $font, $name); $text_width = $right_x - $left_x; if($image_width > $text_width + 5) { break; } $size = $size - .5; if($size == 1) { die('Script not responding to decreasing font size, in other words: try using less letters.'); }}$padding = ($image_width - $text_width)/2;$textcolor = imagecolorresolve($im, $fontcolor['r'], $fontcolor['g'], $fontcolor['b']);$grey = imagecolorallocate($im, 128, 128, 128);if($shadow == 'y'){ imagettftext($im, $size, 0, $padding+1, 77, $grey, $font, $name);}if($lines == 'y'){ //imagettftext($im, $size, 0, $padding+1, 77, $grey, $font, $name);}imagettftext($im, $size, 0, $padding, 75, $textcolor, $font, $name);if($_GET['dl']){ imagegif($im);}?>[/code]Notice how the code is indented. It make the code alot more readable and you can see how the code flows. Rather than having all the code in one big block. You wouldnt want to read a book that has no paragraps in it would, as it'll just be a huge block of text and you wont know here the paragaraphs start or end. The same applies to php coding, indent your code that way you know here your code blocks start and end. Quote Link to comment https://forums.phpfreaks.com/topic/19685-parse-error-unexpected-very-fustrating-please-help/#findComment-85871 Share on other sites More sharing options...
digi duck Posted September 5, 2006 Author Share Posted September 5, 2006 wow thanks so much that's a lot easier to read. Anyway i pasted this in and uploaded it and it just comes up with a missing link image. The image's are in the right place though. At first i thought it could be the code that replaced the switch so i swapped it back to the original long method but it still did it. I am completely confused now. Do i need to change the code you posted at all? Quote Link to comment https://forums.phpfreaks.com/topic/19685-parse-error-unexpected-very-fustrating-please-help/#findComment-86226 Share on other sites More sharing options...
wildteen88 Posted September 5, 2006 Share Posted September 5, 2006 I think you do as when I was formatting the code I was a little confused. Go througb the code and check that everythink is whetre it should be.One Thing I was a little confused with was when I found this - [code=php:0]for(;;)[/code] - Where's the variables/conditions. You cant have a blank for loop. Quote Link to comment https://forums.phpfreaks.com/topic/19685-parse-error-unexpected-very-fustrating-please-help/#findComment-86294 Share on other sites More sharing options...
digi duck Posted September 5, 2006 Author Share Posted September 5, 2006 ok thanks i managed to sort that problem by refering to a previous script and implementing your code into that instead. I'm afraid i have another problem however. I want the image that is created to not just appear on its own on a blank page i want it as part of a html page. I keep on getting an error though. where the image should be comes up a stream of nonsense letters that are obviously supposed to be the image but it's still reading it as text/html (look at site to see this www.gamesigs.co.uk). I know i have to put [code]header("Content-type: image/jpeg"); [/code] in somewhere but not sure where. I've tried putting it before the <html> tags and at the start and end of the php code but none worked.i think i have to change the output at the start of the php code to jpeg and remove the html header and then reverse this at the end again so it deletes jpeg and starts text/html again.Any ideas how to do this? Quote Link to comment https://forums.phpfreaks.com/topic/19685-parse-error-unexpected-very-fustrating-please-help/#findComment-86456 Share on other sites More sharing options...
digi duck Posted September 6, 2006 Author Share Posted September 6, 2006 *bunp* Quote Link to comment https://forums.phpfreaks.com/topic/19685-parse-error-unexpected-very-fustrating-please-help/#findComment-86968 Share on other sites More sharing options...
digi duck Posted September 7, 2006 Author Share Posted September 7, 2006 come on someone, PLEASE HELP Quote Link to comment https://forums.phpfreaks.com/topic/19685-parse-error-unexpected-very-fustrating-please-help/#findComment-87785 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.