I am trying to write code that sends a file path to the server, uses php to parse out each line into an array and returns the array to the client to have stuff done to it.
When I run my program it doesn't look like it is processing the php file as the echo that i put in for testing purposes is never called.
I know absolutely nothing about PHP so help is greatly appreciated!
Jquery:
$("#codelines").load('ParsePHPForDisplay.php?filename=DBManager.php');
console.log($('#codelines'));
pieces = $("#codelines").html().split("\n");
PHP:
<?php
class Parsing
{
function ParseStuff()
{
echo('hi');
$parsedFile = file($_REQUEST['filename']);
echo($_REQUEST['filename']);
// foreach ($parsedFile as $parsedFile_num => $parsedFile) {
// echo"Line #<b>{$parsedFile_num}</b> : " .htmlspecialchars($parsedFile) . "<br/>\n";
// }
return $parsedFile;
}
}
?>
A piece of my HTML:
<section id="codestuff">
<h2>Code Lines</h2>
<pre id="codelines">
</pre>
</section>
EDIT:
Here is my PHP now:
<?php
echo('hi');
$parsedFile = file($_REQUEST['filename']);
echo('test');
echo($_REQUEST['filename']);
// foreach ($parsedFile as $parsedFile_num => $parsedFile) {
// echo"Line #<b>{$parsedFile_num}</b> : " .htmlspecialchars($parsedFile) . "<br/>\n";
// }
return $parsedFile;
?>
I get this error:
Parse error: syntax error, unexpected T_STRING, expecting T_FUNCTION in ParsePHPForDisplay.php on line 5
.
$myParse = new Parsing(); $myParse->ParseStuff();Though for your purpose, you really don't need to make it in a class. Seems like you came from a java background. However, if you are only going to have one function, you may as well put it outside of a class scope so it runs when the page is loaded without the need to call it.