Results 1 to 5 of 5

Thread: A little issue, hard to find a title for...

  1. #1
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default A little issue, hard to find a title for...

    I'm working on a weblog of mine, and I had this cool idea...
    There's a lot of repeat code, so I decided to do this:

    PHP Code:
    $thetitle "
        <div class=\"content\">
        <div id=\""
    .$the_title."\"><h1>".$mrtitle."</h1></div>
        <div class=\"cont\">
        <div class=\"cont-container\">"
    ;

    $thetitle2 "
        <div class=\"content\">
        <div id=\""
    .$the_title2."\"><h1>".$mrtitle2."</h1></div>
        <div class=\"cont\">
        <div class=\"cont-container\">"

    Then, when it came up:

    PHP Code:
    if ($page == "about") {
    $the_title "us";
    $the_title2 "me";
    $mrtitle "About Us";
    $mrtitle2 "About Me";

    echo 
    "

    $thetitle"."

            <p>We're a branch of Flame Html Studios, a web design firm based in Cleveland, Ohio. This blog exists to
                inform the public of interesting, helpful, entertaining, and practical topics relating to such things
                as art, web design, programming, Faith, etc.</p>
                
            <p>We strongly believe in the web standards set out by the W3C, and we strive to create out sites more
                simple in every new design, idea, and line code that we spit out.</p>

    "
    ."$titlebot"."
    $thetitle2"."

            <p>My name is Alex Jewell. I'm a web designer, photographer, writer, artist, musician, and strong
                Christian. As the founder and only designer, at this point, of Flame Html Studios, I learn more in the
                realm of technology and design everyday. This blog is you learning what I do as I do.</p>
                
            <p>I'm 14. I'm rad. I'm a geek. I love music. I love life. I love writing. I love design. Enjoy this 
                little project.</p>

    "
    ."$titlebot";} 
    See, this way I was making life a million times easier by stating what $the_title and $the_title2 were equal to later when I needed to, you know?

    But this is throwing errors, saying they're undefined variables...since I state them in the document before I define them.

    Any ideas?

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Er... define $thetitle and $thetitle2 after $the_title and $the_title2. Only way.

    If you want to take this to the next level, have a "template" page that deals with your site design, and then include it from the main page, which sets all the variables echoed into the template. The ideal site model is one that separates content, logic and design.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Sep 2005
    Posts
    882
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    Not sure what's with all the quotes.Try this.
    Code:
    if ($page == 'about') {
    $the_title = 'us';
    $the_title2 = 'me';
    $mrtitle = 'About Us';
    $mrtitle2 = 'About Me';
    
    echo $thetitle.'
    
            <p>We're a branch of Flame Html Studios, a web design firm based in Cleveland, Ohio. This blog exists to
                inform the public of interesting, helpful, entertaining, and practical topics relating to such things
                as art, web design, programming, Faith, etc.</p>
                
            <p>We strongly believe in the web standards set out by the W3C, and we strive to create out sites more
                simple in every new design, idea, and line code that we spit out.</p>
    
    '.$titlebot.$thetitle2.'
    
            <p>My name is Alex Jewell. I'm a web designer, photographer, writer, artist, musician, and strong
                Christian. As the founder and only designer, at this point, of Flame Html Studios, I learn more in the
                realm of technology and design everyday. This blog is you learning what I do as I do.</p>
                
            <p>I'm 14. I'm rad. I'm a geek. I love music. I love life. I love writing. I love design. Enjoy this 
                little project.</p>
    
    '.$titlebot;
    }

  4. #4
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default

    Hey, thanks. That's what I feared, Twey!
    Haha

    [and to blm126 - I like doing using double quotes instead of single quotes. but thanks, anyway.]

    Anyway, the project is finally up and finished.

    check it out:

    http://www.flamehtmlstudios.com/longroad/

    Heck, leave some comments if you want to? Thanks.

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    alexjewell: He didn't use single quotes just for the fun of it Single quotes are significantly faster to parse than double (especially with long strings like that one), and should be used wherever possible. I know, I find it unnatural to put more than a single character in single quotes too.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •