Jump to content


Photo

Parse Error, unexpected $ - very fustrating. Please help.


  • Please log in to reply
9 replies to this topic

#1 digi duck

digi duck
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 04 September 2006 - 04:37 PM

I am getting an this error message:

Parse error: parse error, unexpected $ in /home/www/gamesigs.co.uk/_sig_created.php on line 124

line 124 is the last line of the code.

here is the 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);
?>

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

#2 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 04 September 2006 - 04:52 PM

that means that you are missing a
}
somewhere. You need to close the
switch
. Your code is hard to follow. The better/cleaner way would be like this.

<?php
function testfuntion() {
    if ($someting == $somethingelse) {
       //do something
    }
    //do something else
    if ($something2 == somethingelse2) {
    //do something else
    }
}

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 04 September 2006 - 04:58 PM

Also there is no need to use the swtich statement either. Just use an if statement:
if(is_numeric($_GET['color']) && $_GET['color'] >= '1' && $_GET['color'] <= '27')
{
    $bgpic = 'images/sig_maker/' . $_GET['color'] . '.jpeg';
}

Also this:
for(;;)
Is not valid. You cant have an emtpy for loop.

#4 digi duck

digi duck
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 04 September 2006 - 05:06 PM

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.

#5 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 04 September 2006 - 05:13 PM

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:
<?php
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){
///
}

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);
}
?>
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.

#6 digi duck

digi duck
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 05 September 2006 - 08:49 AM

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?

#7 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 05 September 2006 - 12:20 PM

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 -
for(;;)
- Where's the variables/conditions. You cant have a blank for loop.

#8 digi duck

digi duck
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 05 September 2006 - 03:26 PM

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
header("Content-type: image/jpeg");
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?

#9 digi duck

digi duck
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 06 September 2006 - 09:29 AM

*bunp*


#10 digi duck

digi duck
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 07 September 2006 - 02:53 PM

come on someone, PLEASE HELP




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users