Jump to content

php4.1 to php5.2 broke code why?


bad_gui

Recommended Posts

I am trying to learn php with the Welling & Thompson book.  I am updating and customizing

a package that will search an archive of documents on my hard drive- no remote access.

 

This works with php4 but when I upgraded my distro it came with php5.2 and now the index.php

has problems.  The first problem is an echo statement that has the second quote escaped (by the percent?).

 

I haven't found why php5 treats this code differently than php4.  I would like to make the code work

for both versions.

<?
session_start();

include 'data.php';

$reload_to_install = str_replace("index", "install", $_SERVER['PHP_SELF']);
if (!isset($database_host)) header("Location: http://$_SERVER[HTTP_HOST]$reload_to_install");

if (!isset($_GET["from"])) {
$from = '0';
} else {
$from = $_GET["from"];
}

if (!empty($_SESSION["user"])) $username = explode ('@', strtoupper($_SESSION["user"]));

/////////////start define functions//////////////////////

function show_results($result,$select,$from,$show) {

include 'data.php';
$i = $from;

    $link = mysql_connect($database_host, $database_user, $database_password);
    mysql_select_db ($database_name);

echo '
<TABLE BORDER="0" CELLPADDING="5" CELLSPACING="5" WIDTH="100%">';

while ($paper = mysql_fetch_array($result)){
$i = $i + 1;

 

Here is what I see in my browser:

; while ($paper = mysql_fetch_array($result)){ $i = $i + 1; echo " $i. $paper[authors]

$paper[title]

$paper[journal] $paper[date1]

"; if ($show == 'abstract') { print "Brief"; } else { print "Abstract"; } if (isset($_SESSION["auth"])) { echo " |

Link to comment
Share on other sites

O.K.  so now when I change the starting <? to <?php the index.php script is

ignored and the browser loads another one, intsall.php, from the same directory

Why?

 

While poking around my php.ini file I found this.  Where can I read more about code

differences between php4 and php5 since my book covers php5?

 

;;;;;;;;;;;;;;;;;;;;

; Language Options ;

;;;;;;;;;;;;;;;;;;;;

 

; Enable the PHP scripting language engine under Apache.

engine = On

 

; Enable compatibility mode with Zend Engine 1 (PHP 4.x)

zend.ze1_compatibility_mode = Off

 

; Allow the <? tag.  Otherwise, only <?php and <script> tags are recognized.

; NOTE: Using short tags should be avoided when developing applications or

; libraries that are meant for redistribution, or deployment on PHP

; servers which are not under your control, because short tags may not

; be supported on the target server. For portable, redistributable code,

; be sure not to use short tags.

short_open_tag = Off

 

; Allow ASP-style <% %> tags.

asp_tags = Off

 

Link to comment
Share on other sites

The short open tag is a configuration option. It has nothing to do with php4 vs php5.

 

The short open tag was a lazy-way short cut that results in non-portable code and simply should not be used by anyone. Short open tags created two ways of accomplishing the same thing. However all other php configuration options are detectable at runtime by the code and the code can take an appropriate action if something is not available, but because code won't even run if it is using short open tags and the option is not turned on, your code will fail. To produce code that will always be parsed, only use full <?php tags.

 

There are sections in the php manual that lists the differences between php4 and php5 -

 

http://www.php.net/manual/en/faq.migration5.php

 

http://www.php.net/manual/en/migration5.php

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.