How to add <h1> tag into php code

hey all,

i am having problems trying to add the <h1> tag to my php code here is the code with out

echo $hackname = $result['hackname'] ;

basicly what that dose is pull that hacks name from the data base and shows it at the top of the page now when i add my <h1> tags to make that hack look like a title

echo "<h1>" $hackname = $result['hackname'] "</h1>";

i get an error is it becuase php dose not allow html tags?, and how would i add that h1 tag to that statement?

There are two main methods. I’ll demonstrate both.

#1: The first method is putting the php between html. This is demonstrated below.


<html>
<head>
<title>h1 tags</title>
</head>
<body>
<h1><?php echo $hackname = $result['hackname']; ?></h1>
<p>My little description goes here</p>
</body>
</html>

#2: The second method is to put the html in the php like so…


<html>
<head>
<title>h1 tags</title>
</head>
<body>
<?php echo '<h1>' . $hackname = $result['hackname'] . '</h1>'; ?>
<p>My little description goes here</p>
</body>
</html>

By the way, you can’t scrap the whole '$hackname = ’ part and just echo $result[‘hackname’]. Defining a variable in an echo statement will work, but doesn’t make much sense, especially in your case. Here’s the above method without the '$hackname = '.


<html>
<head>
<title>h1 tags</title>
</head>
<body>
<?php echo '<h1>' . $result['hackname'] . '</h1>'; ?>
<p>My little description goes here</p>
</body>
</html>

This makes little sense:

You’ll either do:


$hackname = $result['hackname'];
echo $hackname;

Or:


echo $result['hackname'];

This is syntactically illegal, which is why you’re getting an error:

You can do this:


$hackname = "<h1>" . $result['hackname'] . "</h1>";
echo $hackname;

Or

echo "<h1>" . $result['hackname'] . "</h1>";