2017-01-04 1 views
0

PHP에서 조건부 연산자로 프레임 태그를 사용하고 싶습니다. 특정 필드를 확인하고 싶습니다. 값이 있습니다. 예를 들어 프레임 src.의 값을 인쇄하고 싶습니다. 떠나고 싶지 않습니다. 빈.조건부 연산자에 html 태그 추가

<?php print (!empty($fields['field_perspective_video'])) ? 
    echo '<iframe src="'.$fields['field_perspective_video']->content.'"></iframe>'; : ''; ?> 

위의 행에서 예기치 않은 반향 오류가 발생했습니다. 때 이미 당신은 에코가 필요하지 않습니다

<?php 
    $auxVar = ''; 
    print (!empty($fields['field_perspective_video'])) ? 
    $auxVar = '<iframe src="'.$fields['field_perspective_video']->content.'"></iframe>' : $auxVar = ''; 
    echo $auxVar; 
?> 

답변

0
차라리 변수를 만들 것

한 다음, 다음 또는 iframe을하지 않고 변수를 인쇄하는 에코을하는 경우는 내부 값의 설정 사용되는 인쇄

print (!empty($fields['field_perspective_video'])) ? 
     '<iframe src="'.$fields['field_perspective_video']->content.'"></iframe>' : ''; 
+0

잡은 구문 오류, 예기치 않은 ' – user3386779

+0

편집하고 여기에 당신이 코드가 오류없이 컴파일 볼 수 있습니다, 예상치 못한 기호를 제거 : http://sandbox.onlinephpfunctions.com/code/ba120e347253e09fc34576937e3931cae3322acd – avilac