I'm new to PHP and trying to write a PHP script to output some text in boldface. I've tried every combination of echo / print, < b> / < strong> but no matter what, the output is always like this: <strong>Text</strong>
<?php
print "<strong>Text</strong>";
?>
Why is this happening? I'm using PhpStorm, could there be a setting I have to fix?
Make sure your are opening your php file in your localhost. For example your filename is index.php you should run it at localhost/index.php. PHP scripts do not run when u just open it in your browser like HTMLs.
Can you add the current URL you are working with?
check that which content-type it is. Make sure the text/html is correct. And also you should put some screenshots of your web server configuration.
Maybe you dont have the correct settings in the project for the HTML to be loaded properly, e.g. not the correct meta settings Try this:
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>
<?php
print "Text\n";
print "<b>Text</b>";
?>
</body>
</html>
If it doesn't work, try this meta tag instead:
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
UPDATE:
The reason this could happen, is because you have a PHP file, but you are using HTML within your PHP file - which is okay, but you have to render/return the php within html tags. For this to be rendered, you have to render the HTML within an HTML tag, or the HTML tags wont be rendered. Right now you are rendering HTML without having referenced the HTML anywhere.
What you could do is in the php tag in the html file, within body, specify a function:
<b><?php outputtext(); ?></b>
In your PHP file you specify the function as
function outputtext() {
return "hello world";
}