I'm working on some PHP code that will be running on a web page. To make the coding/testing process faster I'm running the code locally through the terminal. For some reason the same code provides different results when running on my web server than when running on my G5. The code is this:
Code:
$text = "category\r\n\r\nheading\r\n\r\nbodytext\r\nhttp://www.foo.com";
$text = split("\n", $text);
$heads = 0;
$isfirst = 1;
$issecond = 0;
$sub = "";
for ($i = 0; $i < count($text); $i++) {
if ($isfirst) {
$sub .= "<p>";
print $sub . "\n";
$isfirst = 0;
if ($text[$i+1] == "\r") {
$sub .= "<strong>";
print $sub . "\n";
$issecond = 1;
$heads++;
}
}
if (substr($text[$i], 0, 4) == "http") {
$link = "<br /><a href=\"" . $text[$i] . "\">$text[$i]</a>";
$text[$i] = $link;
$heads--;
}
$sub .= $text[$i];
print $sub . "\n";
if ($issecond) {
$sub .= "</strong>";
print $sub . "\n";
$issecond = 0;
}
if ($text[$i] == "\r") {
$sub .= "</p>";
print $sub . "\n";
$isfirst = 1;
}
}
//print $sub;
print "\n";
On the webserver it returns the following output (with the mid-function prints gone and only the last commented-out print working):
Code:
<p><strong>category</strong></p><p><strong>heading</strong></p><p>bodytext<a href="http://www.foo.com">http://www.foo.com</a></p>
But when I run it through the terminal on my G5 it gives this output (under the same print conditions):
Running the code exactly as it's displayed above gives this output:
Code:
<p>
<p><strong>
<p><strong>category
</strong>g>category
</strong>g>category
</p>rong>g>category
</p><p>g>g>category
</p><p><strong>gory
</p><p><strong>heading
</strong>trong>heading
</strong>trong>heading
</p>rong>trong>heading
</p><p>g>trong>heading
</p><p>bodytextheading
<br /><a href="http://www.foo.com">http://www.foo.com</a>
I can't for the life of me figure out why it's doing this. It looks like some sort of memory address error, but I don't see how my code could possibly be responsible for that.
Any ideas?