1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Having a problem - following a online book

Discussion in 'PHP' started by Worldwid, Jul 21, 2005.

  1. #1
    Hey all,

    Tonight is my first venture into learning PHP. I was about to post looking for someon to make a custom script for me, but I figured when will there be a better time to start learning this interesting part of web-design.

    Up until now I have only used HTML (and not the best at that but I can get stuff done in dreamweaver and edit decently).

    First question : Do you think it is needed to have an extensive knowledge of HTML before starting PHP? I cant code tabels or stuff like that from memory but I can pretty much do anything in dreamweaver.

    Secondly : here is the problem I am running into.
    SEMrush
    I am following this online book/tutorial.

    http://www.hudzilla.org/phpbook/

    I am up to the part where we first start learning about the code. He is explaining the \n command, and then some other \ commands. The problem I am having is \n is not making a new line for me like it is supposed to. Is this book out of date or something? I tried copying the code exactly as how he has it and its not working for me, it is printing both text on the same line. Here is the code I am using.

     <?php
        $food = "grapefruit";
        print "These " . $food . "s aren't ripe yet.\n";
        print "These " . $food . "s aren't ripe at all.\n";
    ?> 
    PHP:
    The output I am getting is

    "These grapefruits aren't ripe yet. These grapefruits aren't ripe at all."

    Real simple question im sure since its the first thing they are trying to teach me in this online book, although im very hesitant to keep trying learn from it though. If the first thing is wrong (or well just not working for me right now) never know how much else is too.

    Looking forward to your replies :cool:
     
    Worldwid, Jul 21, 2005 IP
    SEMrush
  2. frankm

    frankm Active Member

    Messages:
    915
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    83
    #2
    your first question: you dont need to know HTML to learn PHP. but if you want to use php to generate HTML, it can come in handy to know at least the basics :)

    second Q: if you do 'view source' on the output of your grapefruits thing, you will see there are TWO lines, so the \n worked. If you want this to be seen in HTML aswell, you will need to add a <BR> tag.

    
    echo "line1\n";
    echo "line2<br>\n";
    echo "line3\n";
    
    PHP:
    check this code and you'll seewhat i mean.
     
    frankm, Jul 21, 2005 IP
  3. frankm

    frankm Active Member

    Messages:
    915
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    83
    #3
    PS: Good luck learning php :) and HTML on the fly
     
    frankm, Jul 21, 2005 IP
  4. rickbkis

    rickbkis Peon

    Messages:
    45
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You'll want to get a better background in HTML. You can code HTML pages up either by hand (or Dreamweaver) and then "php-ize" them, but you need to know how the HTML is structured, and the PHP code will need to output HTML tags - you need to know how those work.

    rickb
     
    rickbkis, Jul 29, 2005 IP