SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    gimme the uuuuuuuuuuu duuudie's Avatar
    Join Date
    Feb 2004
    Location
    Switzerland
    Posts
    2,253
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    'switching': bad practice? Maybe but it does have some good points...

    Hi

    When I first started learning PHP and posting on SPF something like one month ago, I have been told a few times that escaping PHP to display HTML code was not a good coding practice. I must agree that using echo would probably be more 'php oriented' in terms of designing your code. After using the echo technique, I realized the following thing: what if I work on project, working on the clientside/serverside of the website and that I later have to team with someone else, let's say a 'CSS expert'. Heh. Poor guy/gal if he/she doesn't know the little echo syntax tricks. I know, it's not that hard to learn but it might be pain for this person isn't it? So I decided that I would keep things 'separated': HTML as HTML and PHP as PHP. Therefore I escape PHP everytime I have some HTML to print out.

    Now debate, discuss, tell me why it is good, not good etc...

    I am listening to you.

  2. #2
    SitePoint Zealot
    Join Date
    Apr 2002
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's a pain in the *** because you have to type more every time you want to insert a variable. heredoc string syntax is better.

    $output = <<<EOF
    <font size="+2">unescaped html</font>
    $var <!-- that will print -->
    EOF;

    It's also easier to work with output gathered into an output variable then capture it from echo's. If you put your output compression with the same code which renders the page and stops your page build timer it makes all your code easier to find and modify.

  3. #3
    ********* wombat firepages's Avatar
    Join Date
    Jul 2000
    Location
    Perth Australia
    Posts
    1,717
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    not quite with you ... but if someone told you that jumping in and out of HTML/PHP is not bad practice then they were misguided , seperating PHP logic from presentational HTML/CSS is something to aim for but a different issue altogether.

    PHP Code:
    e.g.
    <br />
    <b>If they said there was anything wrong with this</b>
    <br />
    <?echo $they_were_wrong;?>
    .. they were wrong , I mean its subjective of course but there is nothing that irks me more than seeing pages of

    echo '<li>blah</li>';
    echo '<li>blah blah</li>';
    echo "<li>$blah</li>';

    etc ... pointless IMO and a waste of parsing time.

  4. #4
    gimme the uuuuuuuuuuu duuudie's Avatar
    Join Date
    Feb 2004
    Location
    Switzerland
    Posts
    2,253
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot firepages So you're saying that my pchoice is ok?

    By the way, I'd like to take this opportunity to thank your for phpdev

  5. #5
    ********* wombat firepages's Avatar
    Join Date
    Jul 2000
    Location
    Perth Australia
    Posts
    1,717
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well like I said its subjective , in my opinion its far more efficient and definately more readable than lines of echo .. ( [ex]perl heads always seem to use print())

    again ideally your designer should be able to design for you without ever sniffing PHP/$whatever , though that ideal is not always practical and depends on the scope of your work, + simply telling them to ignore the stuff in <? ?> is easier !

    as for phpdev cheers ! , the next version is (as it has been for a year or so ) a couple of weeks away

  6. #6
    gimme the uuuuuuuuuuu duuudie's Avatar
    Join Date
    Feb 2004
    Location
    Switzerland
    Posts
    2,253
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Heh.. I don't even talk about print

    I started to learn client side at the same time, one month ago. So that's pretty much why I was talking about this switch choice. You can guess that learning CSS and PHP and HTML inside lines of echo is not a cool thing. I'm happy that someone as knowledgeable as you 'allows' this practice.

    heh, I can't wait for the next phpdev version. I would probably still struginlg with installation if you weren't releasing such an excellent tool.


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
  •