Forum Moderators: coopster

Message Too Old, No Replies

Need help with printing a variable

         

asson

12:27 am on Jun 18, 2007 (gmt 0)

10+ Year Member



Hi everyone,
I need a little help with printing a variable,
my codec looks like this,
In the head i have included a file where the variable gets fixed,

<?php include('file.inc');?>

Then i want to print it by writting this,

echo "<table cellpadding='0' cellspacing='0' width='100%'>\n<tr>
<td class='my'>some text</td>
<td align='right' class='my'>"; print $variable; echo"</td>
</tr>
</table>\n";

It shows no error and now working either. (error reporting is on)
If i remove the HTML tags and put it in a clean empty file, it works, so there must be something wrong :(
Thanks in advance.

eelixduppy

3:06 am on Jun 18, 2007 (gmt 0)



It should definitely work with what you have shown. You either are altering the variable value somewhere before this or there is something else going on that cannot be seen with the code shown. Try just echoing the variable in the script, keeping everything else there:

echo $variable;

Borgscan

3:51 am on Jun 18, 2007 (gmt 0)

10+ Year Member



I've got no explaination as to why your script doesn't work, but I have found the problem. If you remove the % symbol, it works.


echo "<table cellpadding='0' cellspacing='0' width='100'>\n<tr>
<td class='my'>some text</td>
<td align='right' class='my'>"; print $variable; echo"</td>
</tr>
</table>\n";

[edited by: Borgscan at 3:55 am (utc) on June 18, 2007]

eelixduppy

4:10 am on Jun 18, 2007 (gmt 0)



That's odd that that is the 'problem'; even odder that you thought to remove it ;)

Anyway, it doesn't make any sense. Just out of curiosity, can you try the code that doesn't work again and this time view the source of the page that it creates. If it is in there, then your formatting is incorrect. Other than that, I cannot explain what is going on with that.

Borgscan

5:01 am on Jun 18, 2007 (gmt 0)

10+ Year Member



That's odd that that is the 'problem'; even odder that you thought to remove it ;)

I just experimented with it, eliminating small bits are a time. :) I don't know what I changed, but its working now. :P

Source:

<table cellpadding='0' cellspacing='0' width='100%'>
<tr>
<td class='my'>some text</td>
<td align='right' class='my'>Hello world!</td>
</tr>
</table>

Script:

<?php

$variable = "Hello world!";

echo "<table cellpadding='0' cellspacing='0' width='100%'>\n<tr>
<td class='my'>some text</td>
<td align='right' class='my'>"; print $variable; echo"</td>
</tr>
</table>\n";

?>

Asson, if it still doesn't work for you, can you show us the code from file.inc, please.

[edited by: Borgscan at 5:08 am (utc) on June 18, 2007]

asson

8:41 am on Jun 18, 2007 (gmt 0)

10+ Year Member



Hi,
Thanks very nice help.
It didn't work by removing %.
It works with the $variable ="Hello World"; but why not mine :(
Here is the source code for file.inc (date converter)


<?
//first we define the week names in an array

$weekDays = Array("&#1740;&#1607;&#8204;&#1603;&#8204;&#1588;&#1607;&#8204;&#1605;&#1605;&#1607;", "&#1583;&#1608;&#1608;&#1588;&#1607;&#8204;&#1605;&#1605;&#1607;", "&#1587;&#1742;&#8204;&#1588;&#1607;&#8204;&#1605;&#1605;&#1607;", "&#1670;&#1608;&#1575;&#1585;&#1588;&#1607;&#8204;&#1605;&#1605;&#1607;", "&#1662;&#1742;&#1606;&#1580;&#8204;&#1588;&#1607;&#8204;&#1605;&#1605;&#1607;", "&#1607;&#1607;&#8204;&#1740;&#1606;&#1740;", "&#1588;&#1607;&#8204;&#1605;&#1605;&#1607;");


// kurdish month names in an array

$kurdmonth = Array("&#1685;&#1742;&#1576;&#1600;&#1600;&#1600;&#1607;&#8204;&#1606;&#1583;&#1575;&#1606;", "&#1685;&#1607;&#8204;&#1588;&#1600;&#1600;&#1607;&#8204;&#1605;&#1607;", "&#1582;&#1575;&#1603;&#1607;&#8204;&#1604;&#1742;&#1608;&#1607;", "&#1576;&#1575;&#1606;&#1600;&#1607;&#8204;&#1605;&#1600;&#1600;&#1600;&#1607;&#8204;&#1685;", "&#1580;&#1734;&#1586;&#1607;&#8204;&#1585;&#1583;&#1575;&#1606;555", "&#1662;&#1608;&#1608;&#1588;&#1662;&#1607;&#8204;&#1685;", "&#1711;&#1607;&#8204;&#1604;&#1575;&#1608;&#1742;&#1688;", "&#1582;&#1607;&#8204;&#1585;&#1605;&#1575;&#1606;&#1575;&#1606;", "&#1685;&#1607;&#8204;&#1586;&#1576;&#1607;&#8204;&#1585;", "&#1711;&#1607;&#8204;&#1717;&#1575;&#1685;&#1742;&#1586;&#1575;&#1606;", "&#1587;&#1607;&#8204;&#1585;&#1605;&#1575;&#1608;&#1607;&#8204;&#1586;", "&#1576;&#1607;&#8204;&#1601;&#1585;&#1575;&#1606;&#1576;&#1575;&#1585;", "&#1576;&#1607;&#8204;&#1601;&#1585;&#1575;&#1606;&#1576;&#1575;&#1585;" );

//defining date variables and $s the leapyear

$today = date("d, m, Y");
$timenow = date("d, m, Y");
$currmonth = date("n");
$curryear = date("Y");
$currday = date("d");
$s = date("L");
$totaldays = date("z")+1;
$dayintheweek = date("w");

//counting weather the previouse year was a leapyear

$leapyearplus=$curryear+$s;

if ($curryear == $leapyearplus)
{
$z=1;
}
else
{
$z=0;
}

// printing month names and days

if ($totaldays >= 21 && $totaldays <= 50 )
{
$kurdmonth= $kurdmonth[0];

if ($currday > 20-z-s)
{$kurdday = $currday - 20+$z+$s;}
else
{$kurdday = $currday + 11+$z+$s;}

}

if ($totaldays >= 51 && $totaldays <= 79 )
{
$kurdmonth= $kurdmonth[1];

if ($currday > 20-z-s)
{$kurdday = $currday - 19+$z;}
else
{$kurdday = $currday + 9+$z+$s;}

}

if ($totaldays >= 80 && $totaldays <= 110 )
{
$kurdmonth= $kurdmonth[2];
if ($currday >= 21-$s)
{$kurdday = $currday - 20+$s;}
else
{$kurdday = $currday + 11+$s;}

}

else if ($totaldays >= 111 && $totaldays <= 141)
{
$kurdmonth= $kurdmonth[3];
if ($currday > 21-$s)
{$kurdday = $currday - 20+$s;}
else
{$kurdday = $currday + 10+$s;}

}

else if ($totaldays >= 142 && $totaldays <= 172)
{
$kurdmonth= $kurdmonth[4];
if ($currday >= 22-$s)
{$kurdday = $currday - 21+$s;}
else
{$kurdday = $currday + 10+$s;}

}

else if ($totaldays >= 173 && $totaldays <= 203)
{
$kurdmonth= $kurdmonth[5];
if ($currday >= 23-$s)
{$kurdday = $currday - 21+$s;}
else
{$kurdday = $currday + 9+$s;}

}

else if ($totaldays >= 204 && $totaldays <= 234)
{
$kurdmonth= $kurdmonth[6];
if ($currday >= 23-$s)
{$kurdday = $currday - 22+$s;}
else
{$kurdday = $currday + 9+$s;}

}

else if ($totaldays >= 235 && $totaldays <= 265)
{
$kurdmonth= $kurdmonth[7];
if ($currday >= 23-$s)
{$kurdday = $currday - 22+$s;}
else
{$kurdday = $currday + 9+$s;}

}

else if ($totaldays >= 266 && $totaldays <= 295)
{
$kurdmonth= $kurdmonth[8];
if ($currday >= 23-$s)
{$kurdday = $currday - 22+$s;}
else
{$kurdday = $currday + 8+$s;}

}

else if ($totaldays >= 296 && $totaldays <= 325)
{
$kurdmonth= $kurdmonth[9];
if ($currday >= 23-$s)
{$kurdday = $currday - 22+$s;}
else
{$kurdday = $currday + 9+$s;}

}

else if ($totaldays >= 326 && $totaldays <= 355)
{
$kurdmonth= $kurdmonth[10];
if ($currday >= 22-$s)
{$kurdday = $currday - 21+$s;}
else
{$kurdday = $currday + 9+$s;}

}

else if ($totaldays >= 356)
{
$kurdmonth= $kurdmonth[11];
if ($currday >= 22-$s)
{$kurdday = $currday - 21+$s;}
else
{$kurdday = $currday + 9+$s;}

}

else if ($totaldays >= 1 && $totaldays <= 20)
{
$kurdmonth= $kurdmonth[12];
if ($currday >= 22-$s-$z)
{$kurdday = $currday - 21+$s+$z;}
else
{$kurdday = $currday + 10+$z;}

}

// a statement for Newroz

if ($currday == 21 && $currmonth == 3)
{
$h = " <a href='&#104;&#116;&#116;&#112;&#58;&#47;&#47;&#119;&#119;&#119;&#46;&#107;&#117;&#114;
&#100;&#105;&#116;&#103;&#114;&#111;&#117;&#112;&#46;&#111;&#114;&#103;'>
&#1606;&#1607;&#8204;&#1608;&#1585;&#1734;&#1586;&#1578;&#1575;&#1606;&#32;&#1662;&#1740;&#1585;&#1734;&#1586;&#32;</a> ";}

else
{$h = "";}

// year calculation

if ($currmonth <= 1)
{
$kurdyear = $curryear + 699;
}

if ($currmonth == 2 && $currday <= 20-$s )
{
$kurdyear = $curryear + 699;
}

if ($currmonth == 2 && $currday >= 21-$s )
{
$kurdyear = $curryear + 700;
}

if ($currmonth >= 3 )
{
$kurdyear = $curryear + 700;
}

// day of the week names
$wd = $weekDays[$dayintheweek ];

// dump all variables in one string
$kurddate= "$wd $kurdday $kurdmonth $kurdyear $h";

?>

Thanks

eelixduppy

2:13 am on Jun 19, 2007 (gmt 0)



What is the name of the variable that you are actually trying to echo? If it's not $variable, what is it?

asson

6:42 am on Jun 19, 2007 (gmt 0)

10+ Year Member



$kurddate

eelixduppy

9:52 pm on Jun 19, 2007 (gmt 0)



Try turning up error_reporting [php.net] to see if you are getting any errors from the script. It is obviously not populating the values correctly. You may also want to echo out each individual variable to see which one is misbehaving.