Helt umuligt, Tilføje et nummer for hver linje
Endnu en gang har jeg sat og prøvet mig frem i snart 3 dage, men jeg kan simpelthen ikke få det til at virke.I mit tidligere spm: http://www.eksperten.dk/spm/673756 fik jeg følgende kode:
$line = 1;
function AddLineNumber(){
return $GLOBALS['line']++ . ". ";
}
$str = preg_replace("#^#em", "AddLineNumber()", $str);
men jeg kan simpelthen ikke finde ud af få smidt nogle numre på når $inline er aktiveret.
Håber nogen kan hjælpe, for her kommer hele scriptet (inkl rigtig dårlig kodning) ;)
<div style="text-align: left;">
<?
$inline = $_GET['inline'];
$highlight = $_GET['highlight'];
$id = $_GET['id'];
$fucker = date(Y);
function f($a){
static $count = 0;
if($a == '{') $count++;
elseif($a == '}') $count--;
elseif($count == 0) $a = "<br>";
return $a;
}
if ($inline){
$conn = mysql_connect("xxx","xxx","xxx");
mysql_select_db("4804",$conn);
$que = mysql_query("SELECT id, version, sigs FROM signatures where id = '$id' LIMIT 0,1");
while ($row = mysql_fetch_array($que)) {
$antal = count(explode(", ",$row[sigs]));
$subantal = count(explode("( ",$row[sigs]));
$str = $row[sigs];
if ($highlight){
echo "<i>$highlight</i> was found in this signature update<br>";
$str = eregi_replace("$highlight", "<b>$highlight</b>", $str);
}
echo "<big><b>NOD32 - $row[version]</b></big><br>Contains $antal signatures<br><a href=\"http://xxxx\">Search</a> | ";
$next = mysql_query("SELECT * FROM signatures WHERE id>$id ORDER BY id ASC LIMIT 0,1");
$prev = mysql_query("SELECT * FROM signatures WHERE id<$id ORDER BY id DESC LIMIT 0,1");
while ($page2 = mysql_fetch_array($prev)) {
echo "<a href=\"view.php?id=$page2[id]&inline=1\">< Prev</a> ";
}
while ($page = mysql_fetch_array($next)) {
echo "<a href=\"view.php?id=$page[id]&inline=1\">Next ></a>";
}
echo " | <a href=\"view.php?id=$row[id]&highlight=$highlight\">Regular sorting</a><br><img style=\"width: 350px; height: 20px;\" alt=\"\" src=\"images/tweak_spacer.gif\"><br>";
echo preg_replace("/,|{|}/e", "f('$0')", $str);
}
}else{
$conn = mysql_connect("xxx","xxx","xxx");
mysql_select_db("4804",$conn);
$que = mysql_query("SELECT id, version, sigs, special FROM signatures where id = '$id' LIMIT 0,1");
while ($row = mysql_fetch_array($que)) {
$antal = count(explode(", ",$row[sigs]));
if ($highlight){
echo "<i>$highlight</i> was found in this signature update<br>";
$row[sigs] = eregi_replace("$highlight", "<b style=\"background-color: rgb(51, 102, 102); color: rgb(255, 255, 255);\">$highlight</b>", $row[sigs]);
echo "<big><b>NOD32 - $row[version]</b></big><br>Contains $antal signatures<br><a href=\"http://xxxx\">Search</a> | ";
$next = mysql_query("SELECT * FROM signatures WHERE id>$id ORDER BY id ASC LIMIT 0,1");
$prev = mysql_query("SELECT * FROM signatures WHERE id<$id ORDER BY id DESC LIMIT 0,1");
while ($page2 = mysql_fetch_array($prev)) {
echo "<a href=\"view.php?id=$page2[id]\">< Prev</a> ";
}
while ($page = mysql_fetch_array($next)) {
echo "<a href=\"view.php?id=$page[id]\">Next ></a>";
}
echo " | <a href=\"view.php?id=$row[id]&highlight=$highlight&inline=1\">Line sorting</a><br><img style=\"width: 350px; height: 20px;\" alt=\"\" src=\"images/tweak_spacer.gif\"><br>$row[sigs]";
}
if (!$highlight && !$inline){
echo "<big><b>NOD32 - $row[version]</b></big><br>Contains $antal signatures<br><a href=\"http://xxxx\">Search</a> | ";
$next = mysql_query("SELECT * FROM signatures WHERE id>$id ORDER BY id ASC LIMIT 0,1");
$prev = mysql_query("SELECT * FROM signatures WHERE id<$id ORDER BY id DESC LIMIT 0,1");
while ($page2 = mysql_fetch_array($prev)) {
echo "<a href=\"view.php?id=$page2[id]\">< Prev</a> ";
}
while ($page = mysql_fetch_array($next)) {
echo "<a href=\"view.php?id=$page[id]\">Next ></a>";
}
echo " | <a href=\"view.php?id=$row[id]&inline=1\">Line sorting</a><br><img style=\"width: 350px; height: 20px;\" alt=\"\" src=\"images/tweak_spacer.gif\"><br>$row[sigs]";
}
}
}
?>
<?
$conn = mysql_connect("xxx","xxx","xxx");
mysql_select_db("4804",$conn);
$que = mysql_query("SELECT id, version, sigs, special FROM signatures where id = '$id' LIMIT 0,1");
while ($row = mysql_fetch_array($que)) {
$antal = count(explode(", ",$row[sigs]));
if ($row[special]){
echo "<br><img style=\"width: 350px; height: 20px;\" alt=\"\" src=\"images/tweak_spacer.gif\"><br><img style=\"width: 12px; height: 13px;\" alt=\"Contains a writeup about a certain malware\" title=\"Contains a writeup about a certain malware\" src=\"images/writeup.gif\"> $row[special]";
}
}
?>
</div>
