473,405 Members | 2,287 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,405 software developers and data experts.

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 1788
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: G-Factor | last post by:
Hi all Been learning C++ for about 5 weeks. I find that I create quite a lot of variables. Generally, is it better to create a new variable for every different thing that needs to be stored in...
1
by: John | last post by:
Hi I've got a base class with some protected variables in it, for use by any sub-classes. This all works fine, but I have just run the assembly through FxCop and it suggests making the...
8
by: Sergio Otoya | last post by:
Hi all, I need to add an input hidden field to an existing form (post). I have tried a couple things like adding the '<INPUT type=hidden name=idSelectedURL value=http://server/documents>' to...
12
by: knocte | last post by:
Hello. I have always thought that the eval() function was very flexible and useful. If I use it, I can define functions at runtime!! However, I have found a case where eval() does not work...
15
by: CR | last post by:
I've noticed that the trend these days is to declare variables in the middle of code instead of at the top. What is the advantage of this? It seems like it makes it hard to reuse variables. Here...
2
by: John Regan | last post by:
Hello All I am trying to find the owner of a file or folder on our network (Windows 2000 Server) using VB.Net and/or API. so I can search for Folders that don't follow our company's specified...
16
by: Martin Jørgensen | last post by:
Hi, I've made a program from numerical recipes. Looks like I'm not allowed to distribute the source code from numerical recipes but it shouldn't even be necessary to do that. My problem is...
18
by: Ronald Bruck | last post by:
I have several routines which are used millions of times in my programs, using the Gnu multi-precision software's floating-point reals (see <http://www.swox.se/gmp>). These are of type mpf_t, and...
20
by: tshad | last post by:
Using VS 2003, I am trying to take a class that I created to create new variable types to handle nulls and track changes to standard variable types. This is for use with database variables. This...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.