Reputation: 97
I suddenly have this strange behavior in PHP. I looked around here but cannot find a reasonable explanation
I have an extremely simple example:
<?php
$test = 'hello123';
print $test;
?>
This shows: hello123null in the webbrowser. When I echo instead of print the result, its the same. When I put the string in double quotes also the same.
No matter what I do, it always appends the string 'null' to it.
What is happening here?
Upvotes: 2
Views: 92
Reputation: 846
When serving web pages and mixing HTML and PHP there are scenarios where you can flush hidden characters.
How to troubleshoot:
Put another print line after your print hello123, is it still after hello123 or your last command?
("hello123");
print("test");
Try obflush ()
to pin point issue:
see https://www.php.net/manual/en/function.ob-flush.php
print("hello123");
ob_flush();
flush();
print("test");
Lastly, try setting your header.
header( 'Content-type: text/html; charset=utf-8' );
Upvotes: 1