On Thu, Dec 15, 2011 at 5:46 PM, Ross McKay <ro...@zeta.org.au> wrote:
> Jim Lucas wrote:
>>I second this example, with one minor change, I would add '{' and '}' around
>>echo <<<HTML
>><a style="text-align:left;size:14;font-weight:bold"
>>   href="/mypage.php/{$page_id}">{$page_name}</a><br>
>>This works for $variables, $objects, and variable functions calls.  But 
>>work if you try to call functions directly (bummer).
> In fact, we are in agreement here :) I was just simplifying for the
> example at hand. And as for calling functions directly, also add
> constants :(
> However, it's easy enough to assign a constant to a variable and embed
> it in a HEREDOC, and also easy to wrap a function in a method,
> especially when your HEREDOC is within a method itself:
> define('MSG', 'My name is');
> class X {
>  function html($text) {
>    return htmlspecialchars($text);
>  }
>  function output($name) {
>    $msg = MSG;
>    echo <<<HTML
> <p>$msg {$this->html($name)}</p>
>  }
> }
> $x = new X();
> $x->output('silly "rockstar" name like <&>');
>>This is why I like heredoc syntax over pretty much everything else.
> Concur!
> --
> Ross McKay, Toronto, NSW Australia
> "Pay no attention to that man behind the curtain" - Wizard of Oz
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

To all the people who responded to this thread:
It is 2011 - please stop writing code like this.

To the OP:
I'm glad you're asking questions and realizing you're not happy with
your current abilities and suspect there's a better way.  I've read
the replies in this thread and feel a bit let down.  Use a templating
language - yes, I understand that is what php is for - but I won't go
into it.  You should not be echoing, printing, or any other method of
concatenating html dealing with escaping quotes inside your php logic
code.  Please separate your concerns.

Not sure what that means?  That's OK!  If you want to move forward,
look up how modern frameworks deal with this issue using their views
or template views.  You don't have to use a framework if you do not
want to, that's perfectly fine.  If it works, it works.  But in the
end, it the separation of logic and html is essential to code

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to