
08-24-2007, 01:31 AM
|
| D-Web Trainee | | Join Date: Aug 2007
Posts: 15
| |
form processing please help correct the last 12 lines of this script. Hope the comments are adequate to inform what I want to achieve. Thanks. Quote:
<?php
//================================================== ===========================
// read_contents(): function to read content of a page.conf-File and parse it
// into the proper data structure.
//================================================== ===========================
function read_contents($strFilename )
{
//List for storing the parsed lines
$arParsedLines = array();
//read file
$nFileHandle = fopen($strFilename, "r+");
while (!feof($nFileHandle))
{
//echo "--------------------------------------------------------------------<br>\n";
$strCurrentLine = fgets ( $nFileHandle, 4096 );
if (strlen($strCurrentLine) < 7)
{
continue;
}//end if (strlen($strCurrentLine) < 7)
//echo "strCurrentLine enthält: ->".$strCurrentLine."<-<br>\n";
//echo "Datenstruktur wird angelegt: <br>\n";
$arThisLine = array("url" => "", "email" => "", "size" => "", "command" => "", "active" => true);
//echo "Datenstruktur arThisLine: <br>\n";
//print_r($arThisLine);
//echo "\n<br>suche nach hash<br>\n";
$nPosOfHash = strpos($strCurrentLine, "#");
if (!($nPosOfHash === false))
{
//echo "HASH gefunden: Position: ".$nPosOfHash."<br>\n";
$arThisLine["active"] = false;
$strCurrentLine = substr ( $strCurrentLine, 1);
}//end if (!($nPosOfHash === false))
else
{
//echo "Kein HASH in der aktuellen Logzeile gefunden<br>\n";
}//end else (!($nPosOfHash === false))
//echo "strCurrentLine ist jetzt: ->".$strCurrentLine."<-<br>\n";
$arTemp = explode("\t", $strCurrentLine);
//echo "Ergebnis von Explode: <br>\n";
//print_r($arTemp);
//echo "\n<br>ende<br>\n";
$arThisLine["url"] = $arTemp[0];
$arThisLine["email"] = $arTemp[1];
$arThisLine["size"] = $arTemp[2];
$arThisLine["command"] = $arTemp[3];
//echo "Datenstruktur arThisLine: <br>\n";
//print_r($arThisLine);
//echo "\n<br>ende<br>\n";
array_push($arParsedLines,$arThisLine);
}//end while (!feof($nFileHandle))
return $arParsedLines;
}//end read_contents()
//================================================== ===========================
?>
<html>
<head>
<title>Display</title>
<body>
<p>Display Active Checkboxes<p>
<pre>
Content of Array $_GET:
<?php
//================================================== ===========================
//get available Keys out of array
$arOurKeys = array_keys($_GET);
//for each key that matches "active_<number>"
//we want to do something
/*
$active = $_GET['active_.$key.'];
if($arLine["active"]==true)
{
echo $active.": ".$_GET[$active]."<br>\n";
}
*/
print_r($_GET);
echo "our keys:\n";
print_r($arOurKeys);
/*
$nArrayLength = count($arOurKeys);
for ($i=0; $i<$nArrayLength; $i++)
{
echo "Loop Variable i is: ".$i."\n";
echo $arOurKeys[$i];
echo "\n";
}//end for ($i=0; $i<$nArrayLength; $i++)
*/
$arLineNumbers = array();
foreach($arOurKeys as $strArrayElement)
{
echo "Value of strArrayElement is: ".$strArrayElement." ";
if (strncmp($strArrayElement, "active_", 7 ) == 0)
{
echo "we have a match ";
$strNumber = str_replace ( "active_", "", $strArrayElement);
echo "extracted Line-Number: ".$strNumber."\n";
array_push($arLineNumbers, $strNumber);
}//end if (strncmp($strArrayElement, "active_", 7 ) == 0)
}//end foreach($arOurKeys as $strKey)
print_r ($arLineNumbers, true);
//read the page.conf here into Array $arParsedLines
$arParsedLines = read_contents("page.conf");
print_r($arParsedLines);
//read the page.conf here into Array $arParsedLines
foreach ($arParsedLines as $nValue)
{
echo "$nValue["active"] = false";
}
print_r($nValue);
//mark all lines inside $arParsedLines with active=false
array_walk($arLineNumbers);
echo "$arParsedLines["active"] = true";
print_r($arLineNumbers);
//walk through the Array $arLineNumbers
//for each Line-Number in that array:
//set active=true for the corrosponding line the Array $arParsedLines
?>
</pre>
</body>
</html>
| |