Array går helt galt :S
Hej jeg har koden:<h1>Vælg ordet hvor overskriften skal slutte</h1>
<?
//Insert the plain text into the database (further editing with images and like is done later)
$strSQL = mysql_query("select * from " . $site_name . "_cms_code where id = " . $_GET["theID"]);
$row = mysql_fetch_array($strSQL);
$list = explode(" ", $row["code"]);
// A list of the words that the user would not be able to align an image to
$wordList = array("<br>", "<h1>", "</h1>", "<h2>", "</h2>", "<h3>", "</h3>", "<h4>", "</h4>", "<h5>", "</h5>");
//Set a control variable for the eventually excisting images
$animg = 0;
// Do the control of the wordlist and insert the correct string.
for ($i = 0; $i<count($list); $i=$i+1) {
$word = $list[$i];
if ($word == "<img" || $animg == 1) {
$animg = 1;
if ($word == "border=\"0\">")
$animg = 0;
echo $word . " <!-- $i -->";
} else {
if (!in_array(strtolower($word), $wordList)) {
echo "<a href=\"in_index.php?p=CMS_h_func&start=" . $_GET["start"] . "&end=$i&theID=" . $_GET["theID"] . "\">" . $word . "</a> ";
} else { echo $word; }
} //end of if-tag to check if we are currently working with an image
} //end of the foreach loop
?>
Det der sker er, at når der er linie-skift med BR (har ikke prøvet med noget af de andre ord, som den kontrollerer for), så har det næste ord den samme værdi på $i-variablen, hvilket den ikke bør have. Den burde jo have en værdi der er to større, pga <br>-tagget.
Har også prøvet med foreach. Hvad går galt, og hvorfor? Og hvordan kan det være, at den skriver det rette ord, selv om dets $i-værdi er forkert?
