473,320 Members | 2,122 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Very fast php variable access in html

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 ?
Jun 2 '08 #1
5 1822
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)
Jun 2 '08 #2
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.
js*******@attglobal.net
==================

Jun 2 '08 #3
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)
Jun 2 '08 #4
On Sat, 17 May 2008 15:07:35 +0200, Thomas Mlynarczyk
<th****@mlynarczyk-webdesign.dewrote:
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
Jun 2 '08 #5
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)
Jun 2 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: DJJ | last post by:
I am using the MySQL ODBC 3.51 driver to link three relatively small MySQL tables to a Microsoft Access 2003 database. I am finding that the data from the MySQL tables takes a hell of a long time...
1
by: Avi | last post by:
Hi All. This code works very fine in Firefox but not in I.E. Can anybody help me out? it gives ... "Unknown Runtime Error" in I.E. This code ... Stores N*2 Matrix at Client Side & provide the...
6
by: Rafi Kfir | last post by:
HI, I use vb6 to access database. I can select between "local" data base and "remote" data base. Both connection calls the same Access 2000 Mdb. The Mdb contains local tables (on the hard...
10
by: Jason Curl | last post by:
Greetings, I have an array of 32 values. This makes it extremely fast to access elements in this array based on an index provided by a separate enum. This array is defined of type "unsigned long...
20
by: GS | last post by:
The stdint.h header definition mentions five integer categories, 1) exact width, eg., int32_t 2) at least as wide as, eg., int_least32_t 3) as fast as possible but at least as wide as, eg.,...
14
by: Steve | last post by:
Sorry in advance for my ignorance. Any help would sure be appreciated. I'm writing a fairly simple application with VB.Net and am obviously a bit of a newbie. This application will be used by 1,...
4
by: Volker Jobst | last post by:
Hi, Is there a really fast way to read a text file which contains lines of variable length? I'm using the StreamReader to read the file, but this is not as fast as I need it. thanks a lot...
13
by: Arno R | last post by:
Hi all, I am deploying an A2k app to users with different versions of Access. Using Access 2000 the relinking on startup (on deploying a new frontend or when backend has changed) is very fast....
11
by: John Sheppard | last post by:
Hello there, I am running a webservice on IIS6, sometimes it runs at a reasonable speed, sometimes it runs painfully slow and sometimes inbetween. The application that consumes the service is...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.