對不起,我搜索了高和低的答案,我很難過。基本上我想要做的是用圖像替換某個單詞。用PHP輸出CSV文件到HTML talbe - 如何用圖像替換單詞?
我有一個CSV文件,我使用PHP代碼將數據輸出到HTML表格中。有沒有辦法讓php找到「微笑」這個詞的所有實例?並用這樣的東西代替它
<img src="<?php bloginfo('template_directory'); ?>/images/smile.jpg" />
這樣,HTML將輸出圖形而不是單詞「smile!」?
還有一個想法,我不知道我是否可以將PHP切換到類似template_directory的東西......也許將它切換到「http://website.com/images/smile.jpg」更容易?
確定在這裏使用匿名建議我寫這是我的完整代碼,但它仍然無法正常工作。有什麼建議麼?
$path_to_file = "http://....conquer.csv";
$smile = file_get_contents($path_to_file);
$smile = str_replace("smile!","<img src=\"http://.........../images/smile.png\" />",$smile);
file_put_contents($path_to_file,$smile);
echo "<table id=\"conquer-table\">\n";
$row = 0;
$handle = fopen("http://.........oad/conquer.csv", "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
if ($row == 0) {
// this is the first line of the csv file
// it usually contains titles of columns
$num = count($data);
echo "<thead>\n<tr>";
$row++;
for ($c=0; $c < $num; $c++) {
echo "<th>" . $data[$c] . "</th>";
}
echo "</tr>\n</thead>\n\n<tbody>";
} else {
// this handles the rest of the lines of the csv file
$num = count($data);
echo "<tr>";
$row++;
for ($c=0; $c < $num; $c++) {
echo "<td>" . $data[$c] . "</td>";
}
echo "</tr>\n";
}
}
fclose($handle);
echo "</tbody>\n</table>";
?>
對不起,我忘了添加塊代碼,感謝非常快的負面評價!大聲笑 – randyttp