Solved

Script does NOT work with PHP5

Posted on 2006-11-01
4
330 Views
Last Modified: 2008-01-09
Hello, the following script does NOT work on my server that is running php5.

I need it to work on BOTH php4 and PHP5....

Thanks!



<?php

$sitecontents = "Funny text, other text and other content and other stuff goes here.";

$commonwords = <<<EOF
other goes here ' - \\
EOF;

$parsearray[] = $sitecontents;
$parsestring = "z ".strtolower(join($parsearray," "))." y";
$parsestring = str_replace (",", "", $parsestring);
$parsestring = str_replace ("\n", "", $parsestring);
$parsestring = str_replace (")", "", $parsestring);
$parsestring = str_replace ("(", "", $parsestring);
$parsestring = str_replace (".", "", $parsestring);
$parsestring = str_replace ("'", "", $parsestring);
$parsestring = str_replace ('"', "", $parsestring);

$commonarray = split(" ",$commonwords);

for ($i=0; $i<count($commonarray); $i++) {
   $parsestring = str_replace (" ".$commonarray[$i]." ", " ", $parsestring);
}

$parsestring = str_replace ("  ", " ", $parsestring);
$parsestring = str_replace ("  ", " ", $parsestring);
$parsestring = str_replace ("  ", " ", $parsestring);

$wordsarray = split(" ",$parsestring);

for ($i=0; $i<count($wordsarray); $i++) {
   $word = $wordsarray[$i];
   if ($freqarray[$word]) {
       $freqarray[$word] += 1;
   } else {
       $freqarray[$word]=1;
   }
}


arsort($freqarray);

$i=0;
while (list($key, $val) = each($freqarray)) {    
   $i++;
   $freqall[$key] = $val;
   if ($i==15) {
      break;
   }
}

for ($i=0; $i<count($wordsarray)-1; $i++) {
   $j = $i+1;
   $word2 = $wordsarray[$i]." ".$wordsarray[$j];
   if ($freqarray2[$word2]) {
       $freqarray2[$word2] += 1;
   } else {
       $freqarray2[$word2]=1;
   }
}

arsort($freqarray2);

$i=0;
while (list($key, $val) = each($freqarray2)) {    
   $i++;
   $freqall[$key] = $val;
   if ($i==4) {
      break;
   }
}

for ($i=0; $i<count($wordsarray)-2; $i++) {
   $j = $i+1;
   $word3 = $wordsarray[$i]." ".$wordsarray[$j]." ".$wordsarray[$j+1];
   if ($freqarray3[$word3]) {
       $freqarray3[$word3] += 1;
   } else {
       $freqarray3[$word3]=1;
   }
}

arsort($freqarray3);

$i=0;
while (list($key, $val) = each($freqarray3)) {    
   $i++;
   $freqall[$key] = $val;
   if ($i==1) {
      break;
   }
}

arsort($freqall);

while (list($key, $val) = each($freqall)) {    
   $pagecontents .= "$key => $val<br>";
   $keys .= $key.", ";
}

chop($keys);

$pagecontents . = $keys;

echo $pagecontents;

?>
0
Comment
Question by:hankknight
4 Comments
 
LVL 1

Assisted Solution

by:Bolter99
Bolter99 earned 100 total points
ID: 17853633
Its missing variables and indexes.
0
 
LVL 16

Author Comment

by:hankknight
ID: 17853769
Thanks!

How can I fix it?
0
 
LVL 17

Assisted Solution

by:HuyBD
HuyBD earned 150 total points
ID: 17854771
I see one code error
You should define a variable before use it
$pagecontents .=???;//undefined  $pagecontents

$pagecontents="";
$pagecontents.=???;// valid

Also define from $keys variable
0
 
LVL 6

Accepted Solution

by:
neorush earned 250 total points
ID: 17855685
your copy and pasted version:

$pagecontents . = $keys;
echo $pagecontents;

should be:
$pagecontents .= $keys;
echo $pagecontents;

note the space between the '.' (period) and the '=' (equals)

other than that this runs fine on my php 5 install.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now