Okay, so I have some code that worked fine in PHP4 but since upgrading to PHP5 it does not produce the results I want.
This is some code I have that displays some news posts in a nice 3-column format. It checks where the news post shall go and adds it to the corresponding array. Then it prints out the array.
Assume $data is an array containing news post content such as title, date and content.
// Add to columns.
for($i=0; $i<sizeof($data); $i++) {
// Convert Date Format.
$old_date = $data[$i]['post_date'];
$middle = strtotime($old_date);
$new_date = date('F d, Y', $middle);
// Calculate amount of text to display.
if(strlen($nh->getContents($data[$i]['post_content'])) > 100) {
$post_content = $nh->getSnippet($data[$i]['post_content'], 500, TRUE);
$post_content .= "...<br /><br /><a href=\"showNewsPost.php?post_id={$data[$i]['post_id']}\">Read more...</a>";
} else $post_content = $nh->getContents($data[$i]['post_content']);
// Setup content variable.
$content = "
<div class=\"content post\">
<h1 class=\"title\"><a href=\"showNewsPost.php?post_id={$data[$i]['post_id']}\">{$data[$i]['post_title']}</a></h1>
<h2 class=\"subtitle\">Posted on {$new_date}</h2>
{$post_content}
</div>
";
// Add to appropriate column array.
if(in_array($i, $leftIDs)) $left[] = $content;
else if(in_array($i, $midIDs)) $mid[] = $content;
else if(in_array($i, $rightIDs)) $right[] = $content;
}
The problem is where I have the $content variable and add it to an array stack. For some reason it is not adding it. When dumping $content it displays the news contents–so the data is being fetched properly from the $data array.
Printing out the $left, $mid, and $right arrays returns empty arrays. I’ve checked if the if-statements at the bottom were returning true–and they were. So why is my data not being added?
EDIT: The entirety of my code can be found here
P.S.: The reason for the arrays xxID is to figure out in which column the current news post will go. Then I just print everything out so that everything is displayed nicely.
Old: old
New: new
UPDATE: The lines that add the closing </div> to the end of the array: $leftWrapper = sizeof($left) - 1; $left[$leftWrapper] = '</div>'; was overwriting the content that was added to array… odd because it worked in PHP4…. What a silly reason for not working. Thanks everyone for your input.
My bet is you are a victim of http://php.net/manual/en/ini.core.php#ini.register-globals being defaulted to off in PHP5, as it should be since it can be security risk leaving them on. I would verify that, if that is true the solution can be complicated or easy, depending if you want security or not. In order to verify, you will need to either post a bit more code, or test on your server.