Welcome to dbFreaks.com!
FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Very fast php variable access in html

 
   Database Help (Home) -> PHP RSS
Next:  acheter cialis canada bon marche  
Author Message
Guenther Sohler

External


Since: May 17, 2008
Posts: 1



(Msg. 1) Posted: Sat May 17, 2008 4:37 am
Post subject: Very fast php variable access in html
Archived from groups: comp>lang>php (more info?)

Dear Group,

In the past I read something, that it is possible to print out php
variables in html very fast with a simple symtax.

Today I came back to php documentation, but I cannot find it anymore

Its something like

<?php

echo $variable ;

?>

just much shorter.

Can anybode help me ?

 >> Stay informed about: Very fast php variable access in html 
Back to top
Login to vote
Jerry Stuckle

External


Since: Aug 11, 2004
Posts: 3696



(Msg. 2) Posted: Sat May 17, 2008 9:09 am
Post subject: Re: Very fast php variable access in html [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Guenther Sohler wrote:
> Dear Group,
>
> In the past I read something, that it is possible to print out php
> variables in html very fast with a simple symtax.
>
> Today I came back to php documentation, but I cannot find it anymore
>
> Its something like
>
> <?php
>
> echo $variable ;
>
> ?>
>
> just much shorter.
>
> Can anybode help me ?
>

You may be thinking of <?= $variable; ?>

But this requires short_open_tag be enabled, which can conflict with
xml. Most hosts have it off now.

And the difference in speed printing the variable is virtually
unmeasurable. So it only really makes a difference to the programmer.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex RemoveThis @attglobal.net
==================

 >> Stay informed about: Very fast php variable access in html 
Back to top
Login to vote
Thomas Mlynarczyk

External


Since: Apr 29, 2008
Posts: 39



(Msg. 3) Posted: Sat May 17, 2008 3:04 pm
Post subject: Re: Very fast php variable access in html [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Guenther Sohler schrieb:

> Its something like
>
> <?php
> echo $variable ;
> ?>
>
> just much shorter.

<?=$variable?>

See http://de3.php.net/echo

But it works only if short open tags are enabled - and unless you have
full control over the PHP config (php.ini), you cannot rely upon this.
And even if - your code would not be portable.

Alternatives:
<?php o($variable) ?>
with function o ( $variable ) { echo $variable; } or
<?php $view->variable ?>
with function __get ( $what ) { echo $this->$what; }

Greetings,
Thomas

--
Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!
(Coluche)
 >> Stay informed about: Very fast php variable access in html 
Back to top
Login to vote
Thomas Mlynarczyk

External


Since: Apr 29, 2008
Posts: 39



(Msg. 4) Posted: Sat May 17, 2008 3:07 pm
Post subject: Re: Very fast php variable access in html [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Thomas Mlynarczyk schrieb:

> Alternatives:
> <?php o($variable) ?>
> with function o ( $variable ) { echo $variable; } or
> <?php $view->variable ?>
> with function __get ( $what ) { echo $this->$what; }

Another possible solution might be the heredoc syntax:

echo <<< EOT
<body>
<h1>$title</h1>
<p>$text</p>
</body>
EOT;

Greetings,
Thomas

--
Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!
(Coluche)
 >> Stay informed about: Very fast php variable access in html 
Back to top
Login to vote
Rik Wasmus

External


Since: Jan 10, 2008
Posts: 568



(Msg. 5) Posted: Sat May 17, 2008 11:08 pm
Post subject: Re: Very fast php variable access in html [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Sat, 17 May 2008 15:07:35 +0200, Thomas Mlynarczyk
<thomas.DeleteThis@mlynarczyk-webdesign.de> wrote:

> Thomas Mlynarczyk schrieb:
>
>> Alternatives:
>> <?php o($variable) ?>
>> with function o ( $variable ) { echo $variable; } or
>> <?php $view->variable ?>
>> with function __get ( $what ) { echo $this->$what; }
>
> Another possible solution might be the heredoc syntax:
>
> echo <<< EOT
> <body>
> <h1>$title</h1>
> <p>$text</p>
> </body>
> EOT;

That last one is something I definitly use often for smaller sites,
however, your first solution seems quite useless as a simple echo would
suffice as well. Defining obscure functions just to save typing 5
characters every coder knows and understands does not only souns useless
to me, as far as I am concerned I consider this very bad practise.
--
Rik Wasmus
....spamrun finished
 >> Stay informed about: Very fast php variable access in html 
Back to top
Login to vote
Thomas Mlynarczyk

External


Since: Apr 29, 2008
Posts: 39



(Msg. 6) Posted: Mon May 19, 2008 9:09 pm
Post subject: Re: Very fast php variable access in html [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Rik Wasmus schrieb:

>> Thomas Mlynarczyk schrieb:
>>
>>> Alternatives:
>>> <?php o($variable) ?>
>>> with function o ( $variable ) { echo $variable; } or
>>> <?php $view->variable ?>
>>> with function __get ( $what ) { echo $this->$what; }

> however, your first solution seems quite useless as a simple echo would
> suffice as well. Defining obscure functions just to save typing 5
> characters every coder knows and understands does not only souns useless
> to me, as far as I am concerned I consider this very bad practise.

True, o() is just syntactic sugar, but as the OP didn't want to use
echo... Personally, I prefer the second variant. The disadvantage of
using heredoc is that you cannot, e.g., loop over an array to produce
table rows within the heredoc.

Greetings,
Thomas

--
Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!
(Coluche)
 >> Stay informed about: Very fast php variable access in html 
Back to top
Login to vote
Display posts from previous:   
   Database Help (Home) -> PHP All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]