embedded variable in HTML

This is a discussion on embedded variable in HTML within the PHP Language forums, part of the PHP Programming Forums category; On this site http://www.onlamp.com/pub/a/php/2001...undations.html I discovered that I could embed php ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-07-2008
Pakku
 
Posts: n/a
Default embedded variable in HTML

On this site http://www.onlamp.com/pub/a/php/2001...undations.html
I discovered that I could embed php variables in html using this
notation

The variable $var has a value of: <?=$var?><br />

But I think this doesn't work with php version 5 and above. I
searched and searched on the web to confirm this but it was rather
difficult (I can't, for example, search on the string "<?=")

I did see one reference which discouraged the use of this approach
because of some XML compliance issue.

Would appreciate hearing from you all about this, I found it much
easier to do this than reams of echo statements to generate html.
Reply With Quote
  #2 (permalink)  
Old 05-07-2008
Jerry Stuckle
 
Posts: n/a
Default Re: embedded variable in HTML

Pakku wrote:
> On this site http://www.onlamp.com/pub/a/php/2001...undations.html
> I discovered that I could embed php variables in html using this
> notation
>
> The variable $var has a value of: <?=$var?><br />
>
> But I think this doesn't work with php version 5 and above. I
> searched and searched on the web to confirm this but it was rather
> difficult (I can't, for example, search on the string "<?=")
>
> I did see one reference which discouraged the use of this approach
> because of some XML compliance issue.
>
> Would appreciate hearing from you all about this, I found it much
> easier to do this than reams of echo statements to generate html.
>


This hasn't changed with PHP releases. Rather, it means short_open_tag
is on in the php.ini file. It's not a good idea to have it on because
the <? tag is used for xml. Don't count on it being available - few
hosts have it, and many turn it off on upgrading.

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

Reply With Quote
  #3 (permalink)  
Old 05-07-2008
Gordon
 
Posts: n/a
Default Re: embedded variable in HTML

On May 7, 4:20 am, Pakku <pa...@soccermail.com> wrote:
> On this sitehttp://www.onlamp.com/pub/a/php/2001/05/03/php_foundations.html
> I discovered that I could embed php variables in html using this
> notation
>
> The variable $var has a value of: <?=$var?><br />
>
> But I think this doesn't work with php version 5 and above. I
> searched and searched on the web to confirm this but it was rather
> difficult (I can't, for example, search on the string "<?=")
>
> I did see one reference which discouraged the use of this approach
> because of some XML compliance issue.
>
> Would appreciate hearing from you all about this, I found it much
> easier to do this than reams of echo statements to generate html.


I don't know because I've not tried it, but have you tried <?php=$var?
> to see what you get? Just asking out of curiosity, as I tend to just

use Smarty to handle the presentation parts of a web app.
Reply With Quote
  #4 (permalink)  
Old 05-07-2008
Kim André Akerĝ
 
Posts: n/a
Default Re: embedded variable in HTML

Gordon wrote:

> On May 7, 4:20 am, Pakku <pa...@soccermail.com> wrote:
> > On this
> > sitehttp://www.onlamp.com/pub/a/php/2001/05/03/php_foundations.html
> > I discovered that I could embed php variables in html using this
> > notation
> >
> > The variable $var has a value of: <?=$var?><br />
> >
> > But I think this doesn't work with php version 5 and above. I
> > searched and searched on the web to confirm this but it was rather
> > difficult (I can't, for example, search on the string "<?=")
> >
> > I did see one reference which discouraged the use of this approach
> > because of some XML compliance issue.
> >
> > Would appreciate hearing from you all about this, I found it much
> > easier to do this than reams of echo statements to generate html.

>
> I don't know because I've not tried it, but have you tried <?php=$var?
> > to see what you get? Just asking out of curiosity, as I tend to just

> use Smarty to handle the presentation parts of a web app.


I just tested <?php=$var?> myself, and, as expected, it gave me a parse
error (unexpected '='), while doing <?=$var?> instead gave me the
contents of the variable.

As I suspected, it will only work with shorttags enabled.

Without shorttags, you need to do it like this: <?php echo $var; ?>.

--
Kim André Akerĝ
- kimandre@NOSPAMbetadome.com
(remove NOSPAM to contact me directly)
Reply With Quote
  #5 (permalink)  
Old 05-07-2008
Pakku
 
Posts: n/a
Default Re: embedded variable in HTML

On May 7, 7:19 am, Kim André Akerĝ <kiman...@NOSPAMbetadome.com>
wrote:
> Gordon wrote:
> > On May 7, 4:20 am, Pakku <pa...@soccermail.com> wrote:
> > > On this
> > > sitehttp://www.onlamp.com/pub/a/php/2001/05/03/php_foundations.html
> > > I discovered that I could embed php variables in html using this
> > > notation

>
> > > The variable $var has a value of: <?=$var?><br />

>
> > > But I think this doesn't work with php version 5 and above. I
> > > searched and searched on the web to confirm this but it was rather
> > > difficult (I can't, for example, search on the string "<?=")

>
> > > I did see one reference which discouraged the use of this approach
> > > because of some XML compliance issue.

>
> > > Would appreciate hearing from you all about this, I found it much
> > > easier to do this than reams of echo statements to generate html.

>
> > I don't know because I've not tried it, but have you tried <?php=$var?
> > > to see what you get? Just asking out of curiosity, as I tend to just

> > use Smarty to handle the presentation parts of a web app.

>
> I just tested <?php=$var?> myself, and, as expected, it gave me a parse
> error (unexpected '='), while doing <?=$var?> instead gave me the
> contents of the variable.
>
> As I suspected, it will only work with shorttags enabled.
>
> Without shorttags, you need to do it like this: <?php echo $var; ?>.
>
> --
> Kim André Akerĝ
> - kiman...@NOSPAMbetadome.com
> (remove NOSPAM to contact me directly)


Thank you Kim and Jerry! It had to do with shorttags as you pointed
out. I had it enabled at work where I also happen to have php4 and
disabled at home where I have php5. Classic example of mixing up
causality and correlation!

The way Kim recommends will also enables me to dispense with lengthy
echo statements and escaped quotes- I am going to guess it will be XML
compliant too, right?

I don't know about smarty- just halfway thru an introductory php
course at this time.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 04:24 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0