php causes trash hex 3f

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
estarapapax
Forum Newbie
Posts: 7
Joined: Fri Feb 20, 2009 12:03 am

php causes trash hex 3f

Post by estarapapax »

if for example i have this code:

Code: Select all

<?php
$a = 1;
require('something.php');
require('something2.php');
?>
<html>
<body>
<p>aaaaaa
<?php echo '<br/>'.$a;  ?>
<br/>
<p>aaaaaa
</body>
</html>
Assuming there is only one '<?php' per included (require) php file, then the output HTML will have produce three hex 3F before the <html> tag and one hex 3F before the first <br/> tag. I googled and fund out that each call to '<?php' causes a single hex 3F. And the problem now is that, even though most of these trash characters are outside the <html> tag, they are still displayed in web browsers. Is there a solution to avoid this. I'm using PHP 5.2.8 and I'm running it in my laptop using xampp.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: php causes trash hex 3f

Post by Benjamin »

What in the world are you talking about? Opening PHP tags do not send any output to the browser.
estarapapax
Forum Newbie
Posts: 7
Joined: Fri Feb 20, 2009 12:03 am

Re: php causes trash hex 3f

Post by estarapapax »

Ok.. I made a simple example

This is the content of test.php

Code: Select all

<?php
 
$a = 'aaaaaa';
$b = 'bbbbbb';
 
    for($i = 0; $i < 100; $i ++)
        require('test2.php');
 
?>
<html>
<body>
<?php
    echo $a.$b;
?>
</body>
</html>
and this is the content of test2.php

Code: Select all

<?php
    $justanything = 'justanything';
?>
Here is the link you can click
http://yonips.110mb.com/aaaa/test.php

press ctrl+a once the page finished loading. copy it and paste it in notepad. you'll see 100 square trash characters. if you paste that to a hex editor, those are 3f.

Also, you can view the source of the page and you'll see the same if you paste that source to notepad.

Don't say that it doesn't affect the page. It does. Just observe the linked page carefully. The text is offset a little from the left side. On the website I'm creating, those trash characters makes there own block, not allowing me to create a div block with the contents I want at the very top of the page.

EDIT: I just found out what's casing it. I encoded the my PHP files using utf-8. If they're in ANSI, there won't be any problem. Oh well.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: php causes trash hex 3f

Post by Chris Corbyn »

Sounds like your UTF-8 files include the BOM.
Post Reply