This works:
Code: Select all
$NewVariable='[BBCodeTag]'.$OldVariable.'[/BBCodeTag]';Code: Select all
$NewVariable="[BBCodeTag]$OldVariable[/BBCodeTag]";Thanks,
Drew
Moderator: General Moderators
Code: Select all
$NewVariable='[BBCodeTag]'.$OldVariable.'[/BBCodeTag]';Code: Select all
$NewVariable="[BBCodeTag]$OldVariable[/BBCodeTag]";Code: Select all
$NewVariable = "[BBCodeTag]{$OldVariable}[/BBCodeTag]";
Ah, that makes sense. Can't believe I didn't realize that.McInfo wrote:When the PHP parser sees the square bracket ([) after the variable, it thinks it is the beginning of a reference to an array element.
I will give that a try. I'm curious, which of the following is considered better coding practice?astions wrote:$NewVariable = "[BBCodeTag]{$OldVariable}[/BBCodeTag]";
Code: Select all
$NewVariable = "[BBCodeTag]{$OldVariable}[/BBCodeTag]";Code: Select all
$NewVariable='[BBCodeTag]'.$OldVariable.'[/BBCodeTag]';Code: Select all
<?php
header('Content-Type: text/plain');
if (isset($_GET['case']) && $_GET['case'] > 0 && $_GET['case'] < 5)
{
$case = $_GET['case'];
$str = '';
$loops = 100000;
switch ($case)
{
case 1 :
$start = microtime(true);
for ($i = 0; $i < $loops; $i++)
{
$str .= 'BEGIN-'.$i.'-END';
}
$total = microtime(true) - $start;
break;
case 2 :
$start = microtime(true);
for ($i = 0; $i < $loops; $i++)
{
$str .= "BEGIN-$i-END";
}
$total = microtime(true) - $start;
break;
case 3 :
$start = microtime(true);
for ($i = 0; $i < $loops; $i++)
{
$str .= "BEGIN-{$i}-END";
}
$total = microtime(true) - $start;
break;
case 4 :
$start = microtime(true);
for ($i = 0; $i < $loops; $i++)
{
$str .= "BEGIN-".$i."-END";
}
$total = microtime(true) - $start;
break;
}
echo 'Total time: '.$total.' seconds';
if ($fh = fopen('speed-test-log-'.$case.'.txt', 'a'))
{
fwrite($fh, $total."\n", 20);
fclose($fh);
}
}
else
echo 'Set a case. Example: speed-test.php?case=1';
?>Code: Select all
<?php
header('Content-Type: text/plain');
for ($c = 1; $c < 5; $c++)
{
$file = "speed-test-log-{$c}.txt";
if (file_exists($file))
{
$times = file($file);
echo "Case {$c} Average Time: ".(array_sum($times) / count($times))." seconds\n";
}
else
echo "No case {$c} log.\n";
}
?>Code: Select all
Case 1 Average Time: 0.112371003628 seconds
Case 2 Average Time: 0.122534871101 seconds
Case 3 Average Time: 0.123497724533 seconds
Case 4 Average Time: 0.113371384144 seconds