Jump to content

Recommended Posts

Hi guys, I'm new here, and I'm also new at php. I'm teaching myself really, and there are a lot of things that I don't understand yet. My current problem is the following code:

 

<html>

<head><title>Print 10 Times</title></head>

<body

<?php

$string = "Look, I'm red then I'm blue!";

 

// use FOR loop to print the value of $string 10 times

for($i = 1; $i <= 10; $i++)

echo "<h1>$string</h1>";

 

?>

 

</body>

</html>

 

The problem is the echo line (in bold). The first string printed is not the size of h1 while the rest are all in h1. However, if I change it like this echo "<h1><h1>$string</h1><h1>"; then all of them become h1. Why is this? Why do I need 2 <h1> tags? Thanks for your help on this fellas. I'll probably post some more when I hit roadblocks like this during my PHP self-teaching experience. BTW, I'm using WAMP on my PC.

Link to comment
https://forums.phpfreaks.com/topic/135449-solved-beginner-problem-with-echo/
Share on other sites

OMG lol, I lost sleep over this. Thanks for clearing that up. I guess being a programmer requires a keen eye  :D

 

It happens to everyone. Just as you get more advanced the stupider the answer is...seriously. It is always the small little stupid thing that makes a script go bad.

 

I've spent countless hours on a problem and the solution ended up being something that was soo simple I should have saw it first.

 

But yea, it still happens to me.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.