2012-12-01 3 views
0

PHP에서 HTML 코드의 출력을 변수로 가져올 수 있습니까? 기본적으로,이 코드에 대한 속기 찾고 있어요 :PHP 팩 html을 변수로 출력

<?php ob_start(); ?> 
<div class="headSection"> 
    <h1><?=$headline?></h1> 
    <p><?=$bottomline?></p> 
</div> 
<?php $contents = ob_get_contents(); ob_end_clean(); ?> 

나는 HTML 코드가 $contents 변수에 저장하고 싶습니다.

+0

내 대답은 당신을 위해 일한 않았다

$str = <<<EOF <div class="headSection"> <h1>$headline</h1> <p>$bottomline</p> </div> EOF; echo $str; 

데모? – Alex

+0

@ w0rldart 네, 죄송합니다 :) –

답변

3

사용 PHP의 EOF 문자열 http://codepad.org/9OeUiJNJ

+0

PHP 내부에서 변수를 구문 분석하지 않는 작은 따옴표 문자열을 에뮬레이트하려면'<<< 'EOF''를 사용할 수 있습니다. PHP 5.3에서는 nowdoc – pocesar