2013-08-30 3 views

답변

0

는 HTML 청소기를 유지하기 "undefined"

<button 
    id="sharebutton" 
    class="g-interactivepost" 
    <?php if (isset($_GET['text']) && !empty($_GET['text']) && $_GET['text'] !== 'undefined') { ?> 
    data-prefilltext="<?php echo $_GET['text'];?>" 
    <?php } ?> 
> 
    Send 
</button> 
0
<button> 
id="sharebutton" 
class="g-interactivepost" 
data-prefilltext="<?php if (isset($_GET['text'] && !empty($_GET['text']) { echo $_GET['text']; } ?>" 
Send 
</button> 

이 필요하시면? 당신이 $_GET['text']을 할 경우

http://php.net/manual/en/function.isset.php

0

, 나는 아마 같은 실제 HTML 버튼 요소 이외의 문자열을 정의 할 문자열에 연결하기 :

<?php $prefilltext = isset($_GET['text']) ? 'data-prefilltext="' . $_GET['text'] . '"' : ''; ?> 

<button id="sharebutton" class="g-interactivepost" <?php echo $prefilltext;?>> 
Send 
</button> 

추신 : 나는 단순히 $_GET['text']의 존재를 확인했습니다. 물론 empty 또는 다른 비교 (예 : $_GET['text'] != 'undefined')를 확인하도록 변경할 수 있습니다.

0

당신은 다음을 수행 할 수 있습니다 : php.net에서 Ternary Operator

<button 
id="sharebutton" 
class="g-interactivepost" 
<?php echo ($_GET['text'] != 'undefined')? "data-prefilltext=\"".$_GET['text']."\" ": "";?> 
Send 
</button> 

체크 아웃

0
<button 
id="sharebutton" 
class="g-interactivepost" 
data-prefilltext="<?php if(isset($_GET['text']) && !empty($_GET['text']) { if($_GET['text'] == "undefined") { echo $_GET['text']; } else { // if text is not equal to undefined }?>" 
Send 
</button> 
관련 문제