Solved

Script does NOT work with PHP5

Posted on 2006-11-01
4
336 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

831 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