2013-01-24 148 views
0

當試圖設置每個圖像名稱的超鏈接時,我在超鏈接中收到一個未定義的imgitem通知。我是否將<a>標籤放置在不正確的地方?試圖創建超鏈接時未定義的通知

echo '<td width="11%" class="imagetd">'; 
if (empty($arrImageFile[$key])) { 
    echo '&nbsp;'; 
} else { 
    echo '<ul class="qandaul"><li><a href="previewImage.php?imgId=[$imgitem]" target="_blank">'; 
    echo implode("</li>\n<li></a><a href='previewImage.php?imgId=[$imgitem]' target='_blank'>", array_map(function($imgitem){ 
    return htmlspecialchars($imgitem); 
}, $arrImageFile[$key])); 
    echo '</li></ul></a>'; 
} 
echo '</td>'; 

UPDATE:

未工作電流的代碼:接收

<table id="tableqanda" cellpadding="0" cellspacing="0"> 
    <thead> 
    <tr> 
     <th width="11%" class="image">Image</th> 
    </tr> 
    </thead> 
    </table> 
    <div id="tableqanda_onthefly_container"> 
    <table id="tableqanda_onthefly" cellpadding="0" cellspacing="0"> 
    <tbody> 
     <?php 

function imageName($imgitem) { 
    return htmlspecialchars($imgitem); //432 
} 


      foreach ($arrQuestionId as $key=>$question) { 
     echo '<tr class="tableqandarow">'.PHP_EOL; 
     echo '<td width="11%" class="imagetd">'; 

     if (empty($arrImageFile[$key])) { 
      echo '&nbsp;'; 
     } else { 
    echo '<ul class="qandaul"><li><a href="previewImage.php?imgId=[' . $imgitem . ']" target="_blank">'; //line 456 
    echo implode('</li>\n<li></a><a href="previewImage.php?imgId=[' . $imgitem . ']" target="_blank">', imageName($arrImageFile[$key])); //line 457 
    echo '</li></ul></a>'; 
     } 
     echo '</td>'; 
     echo '</tr>'.PHP_EOL; 
     } 
?> 
    </tbody> 
    </table> 
    </div> 

錯誤:

警告:用htmlspecialchars()預計參數1是字符串,數組給定in ...在線432

注意:未定義的變量:imgitem在...上線456

注意:未定義的變量:imgitem在...上線457

+1

你有這樣的: '?imgI d = [$ imgitem]'你複製的代碼沒有定義'$ imgitem' – datasage

回答

1

我想你的結構改變這樣的事情這將工作:

 function CreateLink($filename, $type){ 
if($type == 'image'){ 
    return '<a href="previewimage.php?filename='.$filename.'" title="Click to view in New window" target="_blank">'.htmlspecialchars($filename).'</a>'; 
} 
} 

...................... 


     $img_result = ''; 
     if(empty($arrImageFile[$key])){ 
      $img_result = '&nbsp;'; 
     }else{ 
      $img_result .= '<ul class="qandaul">'; 
      if(is_array($arrImageFile[$key])){ 
      foreach($arrImageFile[$key] as $filename){ 
      $img_result.= '<li>' . CreateLink($filename, "image") . '</li>'; 
      } 
      }else{ 
      $img_result.= CreateLink($arrImageFile[$key], "image"); 
      } 
      $img_result.= '</ul>'; 
     } 
     //end:procedure image 

     echo '<td width="11%" class="imagetd">'.$img_result.'</td>' . PHP_EOL; 
1

使用單引號將返回文本值。

echo '<ul class="qandaul"><li><a href="previewImage.php?imgId=[$imgitem]" target="_blank">'; 

更改爲:

echo '<ul class="qandaul"><li><a href="previewImage.php?imgId=[' . $imgitem . ']" target="_blank">'; 

更新

function imageName($imgitem) { 
    return htmlspecialchars($imgitem); 
} 

echo '<td width="11%" class="imagetd">'; 

if(empty($arrImageFile[$key])) { 
    echo '&nbsp;'; 
} else { 
    echo '<ul class="qandaul"><li><a href="previewImage.php?imgId=[' . $imgitem . ']" target="_blank">'; //line 443 
    echo implode('</li>\n<li></a><a href="previewImage.php?imgId=[' . $imgitem . ']" target="_blank">', imageName($arrImageFile[$key])); 
    echo '</li></ul></a>'; 
} 

echo '</td>'; 
+0

這仍然給我錯誤,我包括更新當前的代碼現在的樣子 – user1881090

+0

@ user1881090什麼錯誤? – Kermit

+0

未定義變量:imgitem in ...在行443和444行上。在更新代碼中註釋行號 – user1881090