Hi,
I'm just starting with PHP and this is my first page. Here is the code:
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<script language="php">
$need = 'apples'
$linkbook = 'links.txt'
$lines = file($linkbook,FILE_IGNORE_NEW_LINES);
foreach ($lines as $line_num => $line) {
$fields = explode('|', $line);
if ($fields[0]=$need) {
$links=count($fields)
if ($links>0) {
//piece has links - print them sequentially
for ($l=1; $l <= $links; $l++) {
echo $fields[$l];
}
}
}
}
</script>
</body>
</html>
The goal is for it to read all the lines from a file (in the same directory) into an array. Each line is a set of words delimited by the | symbol. The function should examine each line to see if the first word in it is the needed word - in this test, "apples". If it is, and the line has other words after "apples", it should do something with each of those other words.
I know it's quite a complex task for my first page, but it's really a small number of functions used several times.
The trouble is I keep getting this parsing error:
"Unexpected T_variable at line 9"
Can anyone spot the problem, cos it's driving me nuts. 😉
Thanks for reading,
Seymour.
PS. Please forgive any unbelievable errors or gross bad practice in the code, I'm learning as I go.