죄송합니다. 답을 찾기 위해 높거나 낮게 검색했으며 난처하게되었습니다. 본질적으로 내가하고 싶은 것은 특정 단어를 이미지로 대체하는 것이다.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"으로 전환하는 것이 더 쉬울 까?
여기 익명 제안을 사용하여이 코드를 전체 코드로 작성했지만 여전히 작동하지 않습니다. 어떤 제안? 그것은 다른 텍스트로 교체하려면, 단지 다른 뭔가 <img src="<?php bloginfo(\'template_directory\'); ?>/images/smile.jpg" />
교체
$string = /*FULL TEXT HERE*/;
$string = str_replace('smile!','<img src="<?php bloginfo(\'template_directory\'); ?>/images/smile.jpg" />',$string);
및 smile!
코드가 찾고있는 것을 나타냅니다
$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>";
?>
죄송합니다. 블록 코드를 추가하는 것을 잊지 않았습니다. 매우 빠른 부정적인 평가에 감사드립니다. lol – randyttp