470,855 Members | 1,248 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,855 developers. It's quick & easy.

Using variables deinfed later

pat
Is it possible in anyway to use a variable that is initialied *after*
its
use.

What I am trying to achieve is the following, i.e. ,using a PHP
variable that is initialised later to display a HTML Title, code
snippet below. As it
stands at present nothing is echoed!

<html>
<head>
<title><?php echo ($strTitle);?></title>
</head>
<body>
......
<?php
....
$strTitle= getTitle();
...
?>
Jul 17 '05 #1
6 1711
On Fri, 30 Jul 2004 08:50:30 -0700, pat wrote:
Is it possible in anyway to use a variable that is initialied *after*
its
use.

What I am trying to achieve is the following, i.e. ,using a PHP
variable that is initialised later to display a HTML Title, code
snippet below. As it
stands at present nothing is echoed!

Wow that's some task! Like asking to be buried before you're born ;)

Silly question time, what results to you expect?

In short, your example below _will_ work with in PHP4 (not 5 though AFAIK)
but $strTitle will be empty in the first instance. You should still define
the variable as below, but I suspect this isn't strictly the answer you're
looking for or rather, hoping for.
<?php
$strTitle = '';
?> <html>
<head>
<title><?php echo ($strTitle);?></title>
</head>
<body>
......
<?php
....
$strTitle= getTitle();
...
?>


--
Ian.H
digiServ Network
London, UK
http://digiserv.net/

Jul 17 '05 #2
On Fri, 30 Jul 2004 16:16:07 +0000, Ian.H wrote:
In short, your example below _will_ work with in PHP4 (not 5 though AFAIK)
but $strTitle will be empty in the first instance. You should still define
the variable as below, but I suspect this isn't strictly the answer you're
looking for or rather, hoping for.
<?php
$strTitle = '';
?>
<html>
<head>
<title><?php echo ($strTitle);?></title>
</head>
<body>
......
<?php
....
$strTitle= getTitle();
...
?>

Oops, should have added:

If I understand you correctly, you want the title to display but you're
actualy getting the title half way through the script. You maybe able to
do this with output buffering (see ob_start() and other relative functions
on php.net for more info) but it's something I don't use very often at
all, so can't really point you in a better direction than the manual
unfortunately.

Hope this sort of helps though.

Regards,

Ian
--
Ian.H
digiServ Network
London, UK
http://digiserv.net/

Jul 17 '05 #3
On 30 Jul 2004 08:50:30 -0700, wm**********@spammotel.com (pat) wrote:
Is it possible in anyway to use a variable that is initialied *after*
its
use.

What I am trying to achieve is the following, i.e. ,using a PHP
variable that is initialised later to display a HTML Title, code
snippet below. As it
stands at present nothing is echoed!

<html>
<head>
<title><?php echo ($strTitle);?></title>
</head>
<body>
......
<?php
....
$strTitle= getTitle();
...
?>


Hm, time travel variables - sounds like this could work nicely with the
mythical COME FROM command (opposite of GOTO) to write truly evil programs.

http://foldoc.doc.ic.ac.uk/foldoc/fo...&action=Search

But seriously - no.

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Jul 17 '05 #4
On Fri, 30 Jul 2004 08:50:30 -0700, pat wrote:
Is it possible in anyway to use a variable that is initialied *after*
its
use.


Try the output buffer functions:

http://us2.php.net/manual/en/ref.outcontrol.php

1) Turn on output buffering.

2) Do stuff.

3) Flush buffer.

--
Jeffrey Silverman
je**********@jhu.edu
** Drop "PANTS" to reply by email
Jul 17 '05 #5
"pat" <wm**********@spammotel.com> wrote in message
news:92**************************@posting.google.c om...
Is it possible in anyway to use a variable that is initialied *after*
its
use.

What I am trying to achieve is the following, i.e. ,using a PHP
variable that is initialised later to display a HTML Title, code
snippet below. As it
stands at present nothing is echoed!

<html>
<head>
<title><?php echo ($strTitle);?></title>
</head>
<body>
......
<?php
....
$strTitle= getTitle();
...
?>


A syndrome of the lame-o single-entry pointer architecture.... Ahhh! Ahhhh!
Ahhhhhhh!
Jul 17 '05 #6
pat wrote:
Is it possible in anyway to use a variable that is initialied *after*
its
use.

What I am trying to achieve is the following, i.e. ,using a PHP
variable that is initialised later to display a HTML Title, code
snippet below. As it
stands at present nothing is echoed!

<html>
<head>
<title><?php echo ($strTitle);?></title>
</head>
<body>
......
<?php
....
$strTitle= getTitle();
...


Yes you can -as explained by others- using output-buffering. But it's not
exactly desirable programming style. Try to avoid constructions like this.
Jul 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by G-Factor | last post: by
16 posts views Thread by Martin Jørgensen | last post: by
18 posts views Thread by Ronald Bruck | last post: by
20 posts views Thread by tshad | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.