Jump to content

PHP Parse error: syntax error, unexpected ';' in test.php on line 3


shams

Recommended Posts

Hi,

When i run this code in ubuntu get the error:

PHP Parse error:  syntax error, unexpected ';' in /var/www/html/test.php on line 3

This is the php code:

<?php
ob_start();
eval('?>' . file_get_contents('/home/user/message', TRUE) . '<?php ')';
$string = ob_get_contents();
ob_end_clean();
echo $sring;
?>

Link to comment
Share on other sites

Thanks for reply, that code now works fine, now i want to add some array, this is the code:

<?php
ob_start();
eval('?>' . $filestring = file_get_contents('/home/user/message', TRUE) . $filearray = explode("\n", $filestring) . while(list ($key, $val) = each ($filearray) ) . '<?php');
$string = ob_get_contents();
ob_end_clean();
echo $string;
?>

When i run the above get the blank page with this error in the log:

PHP Parse error:  syntax error, unexpected 'while' (T_WHILE) in /var/www/html/test.php on line 3

Link to comment
Share on other sites

No, no, no, no, no.

 

For the love of god, stop it. I have no idea what you're trying to do there, but this is fucked up even for PHP standards.

 

There's a handful of PHP experts who know when and how to use eval(), but you aren't one of them. Whenever you think eval() is the right solution, you're horribly, horribly mistaken. Strike this function from your memory. For a newbie, it's like playing Russian Roulette with a fully loaded gun.

 

Once again: Tell us what you want to achieve, not how you think it can be achieved.

Link to comment
Share on other sites

Sorry for inconvenience, I want to write text on image this is the original code, it writes the whole text in one line, i want to write the text in new lines as it's original text:

<?php

require __DIR__.'/../vendor/autoload.php';

use GDText\Box;
use GDText\Color;

include('../src/FarsiGD.php');
$im = imagecreatetruecolor(500, 500);
$backgroundColor = imagecolorallocate($im, 0, 18, 64);
imagefill($im, 0, 0, $backgroundColor);

$box = new Box($im);
$box->setFontFace(__DIR__.'/fonts/BahijRegular.ttf');
$box->setFontColor(new Color(255, 75, 140));
$box->setTextShadow(new Color(0, 0, 0, 50), 2, 2);
$box->setFontSize(23);
$box->setLineHeight(1.5);
$box->enableDebug();
$box->setBox(20, 20, 460, 460);
$box->setTextAlign('right', 'top');

$gd = new FarsiGD();

$text = file_get_contents('/home/user/message');

$text = $gd->persianText($text, 'fa', 'normal');

$box->draw($text);

header("Content-type: image/png;");
imagepng($im, null, 9, PNG_ALL_FILTERS);

The file_get_contents() output the whole text in one line how to output in new lines within this code?

Link to comment
Share on other sites

Thanks for all finally i realized  that the class FarsiGD() didn't support to write the text in multiple lines, i removed the line:


$text = file_get_contents('/home/user/message');

and inserted this code:

$lines = file("/home/user/message");
foreach($lines as $line)
$text = ($line . "\n");

but the code writes only the last line on the image and ignoring the other previous lines.

Link to comment
Share on other sites

That's because the code makes no sense, just like all the other code in this thread. You seem to have no idea what the code you're writing down even means – which is pretty surprising for somebody with 10 years of experience.

 

Programming doesn't work like this. Before you write code, you need an actual understanding of the problem and a solution. So you claim that the library (this one?) doesn't support multiple lines. But the README explicitly says that it does, and there's code to handle lines. Have you verified your assumption? Have you tried different variations like a bigger box or smaller text? Because it would be fairly stupid to look for a solution when the problem doesn't even exist.

Link to comment
Share on other sites

  • 3 weeks later...

I am sorry for if i am wrong for my post, we appreciate all php developers as well cys0der for farsi class, here is the original text in i wrote in gedit

;حدیث مسلم :کتاب البروالصله والاداب: رقم الحدیث ۲۵۷۷:
ازابوذر رضی الله عنه روایت است که نبی صلی الله وعلیه وصلم 
 از قول الله سبحانه وتعالی چنین فرمود:
 ای بندگانم ! من ظلم را بر خود  حرام کردم  ومیان شما حرام 
 گردانیده ام پس بر هم دیگر ظلم مکنید.
ای بندگان !  همه شما گمراهید مگر کسی که من هدایتش
 کنم  پس طلب هدایتم کنید تا هدایتتان کنم.
ای بندگانم ! همه شما گشنه اید مگر کسی که من طعامش 
دهم پس از من طلب طعام کنید تا شما را خوراک دهم.
ای بندگانم ! همه شما بدون پوششید مگر کسی که من
 پوشش دهم از من پوشش بخواهید تا شما را بپوشانم.
ای بندگانم! شما شب و روز گناه می کنید ومنم که تمام گناهان
  را می بخشم پس از من طلب بخشش کنید تا شما را ببخشم.
ای بندگانم !  شما توان زیان‌رساندن به من را ندارید،
 تا زیانم  رسانید و  توان سودرساندن به من را نیز  ندارید،
 تا به من سودی رسانید.

i use the above code with the:

$text = file_get_contents('/home/user/message');

This is the image ouput:

https://ibb.co/fd1QWk

 

The above original text is written in 8 lines but on image it is written in one line and the other problem is the text is written in bizarre order the last line is in the beginning.

I am writing each line once and then the other one to write the all above text.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.