Need Help with random text scrip

Need Help with this old script. Thanks in advance.I’m getting this error: :" Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; MPRandomText has a deprecated constructor in GetRandomText.php on line 9.

<?php

//-------------------------------------------------------------------------------------------------
//  MAIN TEXT IMPORT AND RANDOMIZER CLASS
//-------------------------------------------------------------------------------------------------

class MPRandomText
	{
	var $filepath;
	var $sepstring;
	var $fixchar;
	var $textfix;
	var $contents;
	var $random;
	var $errors;
	// initiate object and start functions
	function MPRandomText($filepath, $sepstring, $textfix)
		{
		$this->filepath = $filepath;
		$this->textfix = $textfix;
		$this->sepstring = $sepstring;
		$this->errors = "";
		$this->contents = "";
		$this->FileToString();
		}
	// read file contents into string variable
	function FileToString()
		{
		if (!$this->filepath || !file_exists($this->filepath))
			$this->errors = "Could not find text file at ".$this->filepath;
			else {
			@$filePointer = fopen($this->filepath, "r");
			if (!$filePointer) $this->errors = "Text file could not be opened.";
			if ($this->errors == "")
				{
				$this->contents = fread($filePointer, filesize($this->filepath));
				fclose($filePointer);
				if (!$this->textfix) $this->HTMLContent();
				$this->MakeArray();
				}
			}
		}
	// if importing an HTML page, drop everything outside of (and including) the <body> tags
	function HTMLContent()
		{
		$test = stristr($this->contents, "<body");
		if ($test !== false)
			{
			$test = stristr($test, ">");
			if ($test !== false)
				{
				$test = str_replace("</BODY>", "</body>", $test);
				$test = explode("</body>", substr($test, 1));
				if (count($test) > 1) $this->contents = $test[0];
				}
			}
		}
	// convert the file text into a list using separation character
	function MakeArray()
		{
		$array = explode($this->sepstring, $this->contents);
		if (count($array) > 0)
			{
			$this->contents = $array;
			$this->CleanTextList();
			} else $this->errors = "Text file contents are empty or could not be read.";
		}
	// clean up the list of empty values and extra white space
	function CleanTextList()
		{
		$result = array();
		if (is_array($this->contents))
			{
			for ($n=0; $n<count($this->contents); $n++)
				{
				$string = trim($this->contents[$n]);
				$test = trim($string."test");
				if (!empty($string) AND $test != "test") $result[] = $string;
				}
			if (count($result) > 0)
				{
				$this->contents = $result;
				$this->RandomString();
				}
			}
		}
	// get random text string from list
	function RandomString()
		{
		reset($this->contents);
		srand((double) microtime() * 1000000);
		shuffle($this->contents);
		$this->random = $this->contents[0];
		}
	// send finished results to be printed into HTML page
	function GetResults()
		{
		if ($this->errors != "") return $this->errors;
			else
			{
			if ($this->textfix == true) $this->random = htmlentities($this->random);
			return $this->random;
			}
		}
	}

//-------------------------------------------------------------------------------------------------
//  FUNCTION AND VARIABLE TO CREATE RANDOM TEXT INSTANCE
//-------------------------------------------------------------------------------------------------

// create variable to store instance references
$MPRandomTextHandles = array();

// function to create new handle and import random text
function MPPrintRandomText($MPTextFile = "random.txt", $MPSepString = "*divider*", $MPTextToHTML = false)
	{
	global $MPRandomTextHandles;
	for ($n=0; $n<250; $n++)
		{
		if (!isset($MPRandomTextHandles[$n]))
			{
			$MPRandomTextHandles[$n] = new MPRandomText($MPTextFile, $MPSepString, $MPTextToHTML);
			break;
			}
		}
	print($MPRandomTextHandles[$n]->GetResults());
	return $MPRandomTextHandles[$n];
	}

?>

If you read the php.net documentation for classes and objects, you will find a ‘Constructors and Destructors’ section that tells you how to name the constructor - http://php.net/manual/en/language.oop5.decon.php

Sponsor our Newsletter | Privacy Policy | Terms of Service