2010-02-12 8 views
1

메모에 추가 정적 웹 페이지의 html 본문에 다음 코드를 붙여 넣어야합니다. 붙여 넣기가 필요없고 많은 코드가 필요합니다. 하나만 갖고 싶습니다. 뜨거운 <?php getgooglepub(); ?>출력 코드는 그대로


내가 HMTL 페이지에 구글 analitic 코드 또는 애드 센스를 OUPUT하는 PHP 함수를 만들기 위해 좋아 ....이 같은 코드의 작성에 전화 라인 (3 회) <> "" ''를 사용하여 코드를 출력하십시오.

여기에 샘플 코드가 있습니다. 출력 E :

<script type="text/javascript"><!-- 
google_ad_client = "pub-0743213818925076"; 
/* 728x90, date de création 11/02/10 */ 
google_ad_slot = "9774402576"; 
google_ad_width = 870; 
google_ad_height = 90; 
//--> 
</script> 
<script type="text/javascript" 
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> 
</script> 

주, 창조적 인 대답에도 불구하고, 나는 나의 fautl가 .... 내가 코드를 복사하여 붙여 넣습니다 myselft 지금 확실히 ... 그것이 작동되도록 할 수 beeing는 발견 , 확실히, 당신은 플래그 문제, 내가 단서가 없기 때문에! .. 그 HTML 코드에서 호출

<?php getgooglepub(); ?> 

에게이 후

function getgooglepub() 
{$google_code = <<<EOT 

<script type="text/javascript"><!-- 
google_ad_client = "pub-0743213818925076"; 
/* 728x90, date de création 11/02/10 */ 
google_ad_slot = "9774402576"; 
google_ad_width = 870; 
google_ad_height = 90; 
//--> 
</script> 
<script type="text/javascript" 
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> 
</script> 

EOT; 

echo htmlspecialchars($google_code);} 

abviousely에

&lt;script type=&quot;text/javascript&quot;&gt;&lt;!-- 
google_ad_client = &quot;pub-0743213818925076&quot;; 
/* 728x90, date de création 11/02/10 */ 
google_ad_slot = &quot;9774402576&quot;; 
google_ad_width = 870; 
google_ad_height = 90; 
//--&gt; 
&lt;/script&gt; 
&lt;script type=&quot;text/javascript&quot; 
src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt; 

&lt;/script&gt; 

내가 [자료] 태그에 대해 어딘가에 읽고? .... 그것은 어쩌면 방법을 작동하지

이 ... 페이지에서 소스 코드는 파이어 폭스의 렌더링 그렇게 ?

+1

html을 그대로 표시하려면 페이지 소스가 어떻게 보이는지를 확인하십시오. – GZipp

답변

0

대답이 옳고 "있는 그대로"코드를 인쇄하면 원하는 방식대로 수행되지 않습니다. 어쩌면 나는 그것을 옳은 방법으로 설명하지 못했을 것이다. 그래서 해결책을 찾았습니다.나는 코드와 함께 외부 PHP 파일을 사용하고, 그 후에 주 파일에서 include를 사용한다. 그런 식으로 나는 많은 시간, 어쨌든 재사용 할 수있는 하나의 코드만을 가지고있다!

0

당신이 변수에 HTML 코드가있는 경우,

echo htmlspecialchars($google_analytics); 

는 자세한 설명 this question from yesterday를 참조하십시오. 출력에

$google_analytics = <<<EOT 

<script type="text/javascript"><!-- 
google_ad_client = "pub-0743213818925076"; 
/* 728x90, date de création 11/02/10 */ 
google_ad_slot = "9774402576"; 
google_ad_width = 870; 
google_ad_height = 90; 
//--> 
</script> 
<script type="text/javascript" 
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> 
</script> 


EOT; 

echo htmlspecialchars($google_analytics); 
4

당신이 원하는 경우 일부 HTML 코드 를 (그리고 해석하지 않고 실제 HTML 코드를 참조) : 아직 변수에없는 경우

, 당신은 편의를 위해 히어 닥 표기법을 사용할 수 있습니다 당신은 둘 다의 조합을 사용할 수 있습니다 :

  • <pre> 태그, 그래서 표준 코드의 프레 젠 테이션이 유지됩니다; 즉, 줄 바꿈과 복수 공백은 브라우저에 의해 무시되지 않습니다.
  • htmlspecialchars과 같은 함수이므로 <, >, & 따옴표가 이스케이프 처리되어 브라우저에서 해석되지 않습니다. 예를 들어

:이 브라우저에 의해 해석되지 않고

$str = <<<HTML 
<script type="text/javascript"><!-- 
google_ad_client = "pub-0743213818925076"; 
/* 728x90, date de création 11/02/10 */ 
google_ad_slot = "9774402576"; 
google_ad_width = 870; 
google_ad_height = 90; 
//--> 
</script> 
<script type="text/javascript" 
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> 
</script> 
HTML; 

echo '<pre>'; 
echo htmlspecialchars($str); 
echo '</pre>'; 
die; 

는 HTML 코드를 표시 샤 우드.