By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,967 Members | 1,684 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,967 IT Pros & Developers. It's quick & easy.

simple questions (<%=, error reporting)

P: n/a
Hi, I'm a newbie coming from JSP (and also a lifetime of C/C++/Java), and
I was wondering if someone could help me with the following questions.

1. Does PHP have a way to display an expression or variable without
using echo? I'm particularly looking for JSP's <%= %> operator
that will allow me to embed a variable right into HTML.

2. About error reporting, I've found that the default error reporting
level doesn't report undefined variables (these are occuring, for
example, when I misspell a variable name). If I set error_reporting
in php.ini to be E_ALL, undefined variables will be reported, but I
also get a lot of undefined variable errors in HTTP_POST_VARS and the like.
Surely that has to be a happy medium?

Thank you for any help.
Jul 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
* di**********@hotmail.com (Digital Puer):
1. Does PHP have a way to display an expression or variable without
using echo? I'm particularly looking for JSP's <%= %> operator that will
allow me to embed a variable right into HTML.


I think you're looking for <?=$variable?>. Example:

<b>The value is: <i><?=$value?></i></b>

You can also use this syntax for expressions, e.g.,

<b>The value is: <i><?=($foo+5)/$bar?></i><b>

HTH,
--
Benjamin D. Esham { http://bdesham.net
bd*****@iname.com } AIM: bdesham 1 2 8
"...more and more of our imports are coming from
overseas." -- George W. Bush on NPR, 09/26/2000

Jul 16 '05 #2

P: n/a

"Digital Puer" <di**********@hotmail.com> wrote in message
news:80**************************@posting.google.c om...
2. About error reporting, I've found that the default error reporting
level doesn't report undefined variables (these are occuring, for
example, when I misspell a variable name). If I set error_reporting
in php.ini to be E_ALL, undefined variables will be reported, but I
also get a lot of undefined variable errors in HTTP_POST_VARS and the like. Surely that has to be a happy medium?

Thank you for any help.


Try this:

error_reporting(E_ALL & ~E_NOTICE);
Jul 16 '05 #3

P: n/a
Benjamin Esham wrote:
* di**********@hotmail.com (Digital Puer):
1. Does PHP have a way to display an expression or variable without
using echo? I'm particularly looking for JSP's <%= %> operator that will
allow me to embed a variable right into HTML.


I think you're looking for <?=$variable?>. Example:

<b>The value is: <i><?=$value?></i></b>

You can also use this syntax for expressions, e.g.,

<b>The value is: <i><?=($foo+5)/$bar?></i><b>

HTH,


Don't forget to set

short_open_tag = On
asp_tags = On

in php.ini

With short_open_tag off you have to start every piece
of PHP code with <?php

With it on you can start PHP code with <?

If you will be using your scripts on servers you do not
control, it's better to always use <?php as it will
not fail no matter what the settings are in php.ini

The last option allows you to do start php code with
<% instead of <?. I'm not sure if you must use <%php
if you keep short_open_tag off :) Try it!
--
"Yes, I'm positive."
"Are you sure?"
"Help, somebody has stolen one of my electrons!"
Two atoms are talking:
Jul 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.