조건이 충족 될 때 때로는 앵커 태그로 묶어야하는 HTML이 있습니다. 나는 이런 식으로 뭔가 할 수있는 :PHP : 문자열을 따옴표로 묶지 않고 인수로 전달하는 방법은 무엇입니까?
<?php
$html = '<div>my html</div>';
if ($condition):
?>
<a href="http://google.com"><?php echo $html ?></a>
<?php else: ?>
<?php echo $html ?>
<?php endif; ?>
을 ...하지만 난 문자열로 돌려 따옴표 내 HTML을 포장하고 싶지 않아요. 이것은 두 가지 이유 때문입니다. 구문 강조 표시가 사라지고 유지 관리가 더 어려워집니다.
어떻게하면 다음과 같이 할 수 있습니까?
<!-- pseudo code -->
<?php if ($condition): echo $this->wrapWithLinkTo('http://google.com', ?>
<div>my html</div>
<?php); endif; ?>
... 최종 결과가 될 수 있도록 :
<!-- when $condition is true -->
<a href="http://google.com"><div>my html</div></a>
<!-- when $condition is false -->
<div>my html</div>
나는 따옴표를 제안한다. – cwallenpoole
html을 별도의 .html 파일에 넣고/require/file_get_contents를 include하는 것보다는 짧게하는 것이 좋습니다. 따옴표를 사용해야합니다. –