Hey list, I've got a PHP script that is supposed to parse through a block of
text and converts all the web addresses in the block into clickable links. This
is for a chat page I am creating for my family to use to keep in touch. When I
try to run the file and post a new message on the page, I get:
Parse error: syntax error, unexpected T_FOREACH in ..../w.php on line 68
And here is the offending block of code on line 68 (line 44 in the attachment):
foreach ($outarr as $val) {
if(strpos($val,"http://") === 0){
$val = '<a href="' . $val . '">' . $val . '</a>';
}elseif(strpos($val,"ftp://") === 0){
$val = '<a href="' . $val . '">' . $val . '</a>';
}else{
$val = $val;
}
}
I'll attach the file to this email as a text file, maybe someone can spot the
error and clue me in.
Thanks!
-Nick
----------
<?php
// spam-keywords & block ip's
//$spam[] = "wojo.com";
//$blockip[] = "000.000.000.000";
$rightnow = date('M d, H:i:s');
$msg = $_REQUEST["m"];
if ($msg != "") {
// Spam Control Part 1
if (strlen($msg) < 2) { die(); }
if (strlen($msg) > 450){ die(); }
// Preparing the Content
$fn = "chat.txt";
$maxlines = 200;
$handle = fopen ($fn, 'r');
$chattext = fread($handle, filesize($fn)); fclose($handle);
$arr1 = explode("\n", $chattext);
if (count($arr1) > $maxlines) {
// Pruning
$arr1 = array_reverse($arr1);
for ($i=0; $i<$maxlines; $i++) { $arr2[$i] = $arr1[$i];
}
$arr2 = array_reverse($arr2);
} else {
$arr2 = $arr1;
}
$chattext = implode("\n", $arr2);
// Spam Control Part 2
if (substr_count($chattext, $msg) > 2) { die(); }
//handle hyperlinks
$outarr = explode(" ",$chattext)
foreach ($outarr as $val) {
if(strpos($val,"http://") === 0){
$val = '<a href="' . $val . '">' . $val .
'</a>';
}elseif(strpos($val,"ftp://") === 0){
$val = '<a href="' . $val . '">' . $val .
'</a>';
}else{
$val = $val;
}
}
$chattext = implode(" ",$outarr);
$out = $chattext . str_replace("*ts*",$rightnow,$msg) . "<br
/>\n";
$out = str_replace("\'", "'", $out);
$out = str_replace("\\\"", "\"", $out);
$handle = fopen ($fn, 'w'); fwrite ($handle, $out);
fclose($handle);
}
?>
[Non-text portions of this message have been removed]
Community email addresses:
Post message: [email protected]
Subscribe: [EMAIL PROTECTED]
Unsubscribe: [EMAIL PROTECTED]
List owner: [EMAIL PROTECTED]
Shortcut URL to this page:
http://groups.yahoo.com/group/php-list
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/php-list/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/php-list/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:[EMAIL PROTECTED]
mailto:[EMAIL PROTECTED]
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/