Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Script does NOT work with PHP5

Posted on 2006-11-01
4
Medium Priority
?
341 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 1

Assisted Solution

by:Bolter99
Bolter99 earned 400 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 600 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 1000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

660 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