Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Funky PHP Behavior

Funky PHP Behavior
Thread Tools
Posting Junkie
Join Date: Jun 2001
Location: Washington DC
Status: Offline
Reply With Quote
Feb 11, 2005, 07:45 PM
 
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):

Code:
<br /><a href="http://www.lewispr.com">http://www.foo.com</a>
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?
     
Registered User
Join Date: Apr 2003
Location: The Internets
Status: Offline
Reply With Quote
Feb 11, 2005, 08:31 PM
 
make sure its within

<?php ?>

make sure you add <?php in case your server does not understand short tags.


try echo instead of print.

make sure the code is in a page that ends with .php

???
     
Posting Junkie
Join Date: Jun 2001
Location: Washington DC
Status: Offline
Reply With Quote
Feb 11, 2005, 09:25 PM
 
Originally posted by osxisfun:
make sure its within

<?php ?>

make sure you add <?php in case your server does not understand short tags.


try echo instead of print.

make sure the code is in a page that ends with .php

???
It works fine on the server, it's when I'm running it locally in the terminal with the command php *filename* that it doesn't work properly.
     
cla
Mac Enthusiast
Join Date: Mar 2000
Status: Offline
Reply With Quote
Feb 12, 2005, 08:15 AM
 
I have no clue, but if you put a little time into it you could isolate the problem further.
Anyway (what I really wanted to say), try http://www.phpmac.com. It's a site dedicated to php development on Macintosh - that's where I'd look IF your problem is specific to Mac.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:09 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2