2014-01-24 2 views
-1

죄송합니다. 답을 찾기 위해 높거나 낮게 검색했으며 난처하게되었습니다. 본질적으로 내가하고 싶은 것은 특정 단어를 이미지로 대체하는 것이다.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>"; 

?> 
+0

죄송합니다. 블록 코드를 추가하는 것을 잊지 않았습니다. 매우 빠른 부정적인 평가에 감사드립니다. lol – randyttp

답변

1

쉽게 str_replace이 작업을 수행 할 수 있습니다.

+0

@randyttp 다음은 예제입니다. http://phpfiddle.org/main/code/cin-zzt Run을 눌러 결과를 확인하십시오. 여전히 작동하지 않는다면 작동하지 않는 부분에 대해보다 구체적으로 설명해야합니다. – Anonymous

+0

그게 아직 나에게 효과가 없었어요, 전 전체 코드로 내 원래의 질문을 업데이 트 했어 어쩌면 당신은 내가 뭘 하려는지 더 잘 볼 수 있습니다 ... CSV 파일은 내가 대체해야 할 단어가 될 것입니다. – randyttp

+0

이 경우,'$ string'을'file_get_contents ('http : //www.content.csv')'와 동일하게 설정할 수 있습니다. 그러면 코드는'smile! '는 새로운 텍스트로 그 파일을 찾고 그것을 새로운'$ string' 변수로 설정합니다. – Anonymous

관련 문제