I am trying to include variables from a seperate php page like this:
<?
$title1=new;
$title2=old;
?>
then on my main page I have this within a while loop
<?
require (theFileAbove.php);
fileRender++;
echo "<html>$title$fileRender</html>";
?>
essentially the file above that include is echoed within the html through the concatenated new variable- how in theory it works?
I tried .- the period concatenator and all it does is print the period.
never had a result like this?
any insight is helpful!!
Terence
concatenating variables
Moderator: General Moderators
- scorphus
- Forum Regular
- Posts: 589
- Joined: Fri May 09, 2003 11:53 pm
- Location: Belo Horizonte, Brazil
- Contact:
I'm not sure if I got exacly what you mean. Please take a look to the following code and it's output:output:
I hope this illustrative example helps you.
Regards,
Scorphus.
Code: Select all
<?
$title1 = "new";
$title2 = "old";
?>
<?
//Above is the included file:
//require ("theFileAbove.php");
//Now lets set the loop:
$fileRender = 0;
while ($fileRender < 5) {
echo "<b>$title1$title2$fileRender</b>\n";
$fileRender++;
}
?>Code: Select all
<b>newold0</b>
<b>newold1</b>
<b>newold2</b>
<b>newold3</b>
<b>newold4</b>Regards,
Scorphus.
hope this is clearer???
In your echo you are manually inserting the number.
My goal is to have the fileRender loop concatneates itself on the end of the $title variable.
In return this creates a variable named $title1
then the$title1 variable when echoed prints "new" to the browser.
I do this all the time in actionscript.
creating variables on the fly as the script executes.
hope that makes it clearer???
My goal is to have the fileRender loop concatneates itself on the end of the $title variable.
In return this creates a variable named $title1
then the$title1 variable when echoed prints "new" to the browser.
I do this all the time in actionscript.
creating variables on the fly as the script executes.
hope that makes it clearer???
might be easier to use an array
but if you insist on having a couple of string-variables you might try
either way you shouldn't rely on knowing how many strings there are and I suggest using the array, keeps things together a bit better.
see also: http://www.php.net/manual/en/language.v ... riable.php
Code: Select all
<?php
$titles = array(
'new',
'old',
'even older',
'prehistoric'
);
foreach($titles as $title)
echo '<p>', $title, '</p>';
?>Code: Select all
<?php
$title1 = 'new';
$title2 = 'old';
$title3 = 'even older';
$title4 = 'prehistoric';
$fileRender = 1;
while(isset(${'title'.$fileRender}))
echo '<p>', ${'title'.$fileRender++}, '</p>';
?>see also: http://www.php.net/manual/en/language.v ... riable.php
volka- Thank you very very much
I appreciat it greatly-!!!!