简体   繁体   中英

PHP echo printing additional characters

I can class myself as a mid level PHP user, I have recently installed XAMPP on a new PC and noticed a strange behaviour while trying to run a simple php script. This is my script:

<?    
    $data_to = "<b>Line Print</b>";       
?>
<? echo($data_to); ?>

And this is what I am getting on the browser

Line Print"; ?>

Can some one please explain why?

Short opening tags ( <? ) are disabled in php.ini. Either edit PHP configuration or use <?php .

http://www.php.net/manual/en/ini.core.php#ini.short-open-tag

SOLUTION 1:

short_open_tag=On

in php.ini and restart your Apache server.

SOLUTION 2:

Use the <?php tags completely because <? is not recommended.

If you ever have to move your code to a server where it's not supported (and you can't enable it), then you're doomed. It's better to use the full syntax.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM