2014-10-08 2 views
-2

당신이 그것을 너무 자주 '" 방법이 많이 들어 볼 수 있듯이 다음PHP : 둘 다 '와'

echo (
<script> 
$(document).ready(function() { 
    $('#example').dataTable({ 
    "bPaginate": false, 
    "order": [[ 3, "asc" ]], 
    "dom": '<"top"lp>', 
    "aoColumnDefs": [ 
      { 'bSortable': false, 'aTargets': [ 0 ] } 
     ], 
    "aoColumns" : [ 
      { sWidth: '3%' }, 
      { sWidth: '45%' }, 
      { sWidth: '45%' }, 
      { sWidth: '7%' } 
     ] 
    }); 
    oTable = $('#example').dataTable(); 
$('#dataTables_filter').keyup(function(){ 
     oTable.fnFilter($(this).val()); 
}) 
}); 
</script> 
); 

에코 시도 포함 문자열을 반향하고 그것을 추가 할 고통이 얼마나 \ 다른 방법이 있습니까? stackoverflow에서 검색 한 결과 지금까지 아무 것도 찾지 못했습니다 ...

+0

왜 '에코'주위에 포장합니까? – Daan

+0

PHP에서 벗어나거나 HereDoc – raser

+0

@ Daan을 사용하여 내가 무엇을 반향하려고하는지 알 수 있습니다. – rez

답변

1

필요하면 PHP 모드로 이동하십시오.

1

데이터 처리 나 데이터 처리가 필요한 경우에만 다시 들어가십시오. 변수에 대한 액세스 :

function functionName() { 
    ?> 
     <script> 
      // free text 
      var foo = <?php echo json_encode($some_variable); ?>; 
     </script> 
    <?php 
} 
+0

PHP 함수에서 이것을 수행해야합니다. – rez

+0

@Shiro 함수에서 PHP에서 벗어날 수 있습니다. 함수에서 작동 할 것입니다. (예 : net/manual/en/language.types.string.php # language.types.string.syntax.nowdoc) 'echo' 또는'print' 호출과 동일 – raser

+0

@Shiro echo 함수를 대체하는 함수 내에서 작동합니다. – worldofjr

2

사용 히어 닥 문자열 : 모든 그 안에 http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

는 따옴표없이 문자열로 수 있습니다 :

echo <<<EOT 
<script> 
$(document).ready(function() { 
    $('#example').dataTable({ 
    "bPaginate": false, 
    "order": [[ 3, "asc" ]], 
    "dom": '<"top"lp>', 
    "aoColumnDefs": [ 
      { 'bSortable': false, 'aTargets': [ 0 ] } 
     ], 
    "aoColumns" : [ 
      { sWidth: '3%' }, 
      { sWidth: '45%' }, 
      { sWidth: '45%' }, 
      { sWidth: '7%' } 
     ] 
    }); 
    oTable = $('#example').dataTable(); 
$('#dataTables_filter').keyup(function(){ 
     oTable.fnFilter($(this).val()); 
}) 
}); 
</script> 
EOT; 

는 들여 쓰기없이 최종 라벨 'EOT'를 쓸주의하십시오.

+0

'echo '<<< EOT sometext EOT;''그거? – rez

+0

따옴표 필요 없음, PHP man 페이지 확인 – Chococroc

1
$str = <<<EOF 
<script> 
$(document).ready(function() { 
    $('#example').dataTable({ 
    "bPaginate": false, 
    "order": [[ 3, "asc" ]], 
    "dom": '<"top"lp>', 
    "aoColumnDefs": [ 
     { 'bSortable': false, 'aTargets': [ 0 ] } 
    ], 
     "aoColumns" : [ 
     { sWidth: '3%' }, 
     { sWidth: '45%' }, 
     { sWidth: '45%' }, 
     { sWidth: '7%' } 
    ] 
}); 
oTable = $('#example').dataTable(); 
$('#dataTables_filter').keyup(function(){ 
    oTable.fnFilter($(this).val()); 
}) 
}); 
</script> 
EOF; 

echo $str; 
관련 문제