How to use PHP Else Function

Discussion in 'PHP' started by misohoni, Jan 22, 2014.

  1. #1
    I think this is called compact PHP code or something and I'm guessing the Colon : is the else function but how do I get it to work, this is my current code - but I'd like to put an Else in there for non-IsMobile's:

    <?php $check = $detect->isMobile(); if($check): ?>
    <script type="text/javascript">
    jwplayer('video-player').setup({
        height: 320,...
    </script>
    <?php endif; ?>
    Code (markup):
     
    Solved! View solution.
    misohoni, Jan 22, 2014 IP
  2. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #2
    <?php $check = $detect->isMobile(); if($check): ?>
    <script type="text/javascript">
    jwplayer('video-player').setup({
        height: 320,...
    </script>
    <?php else : ?>
    <?php // put your code here ?>
    <?php endif; ?>
    PHP:
     
    stephan2307, Jan 23, 2014 IP
  3. #3
    I'd sooner eat a bullet than open and close PHP that many times, PARTICULARLY the moment you get logic (like IF) involved.

    I also see no reason to waste an extra variable on that.

    
    
    <?php
    
    if ($detect->isMobile()) {
    
    	echo '
    		<script type="text/javascript"><!--
    			jwplayer(\'video-player\').setup({
    				height: 320,...
    			});
    		--></script>';
    
    } else {
    
    	echo '
    		Whatever your other code is';
    		
    }
    
    ?>
    Code (markup):
    Though you shouldn't be browser sniffing server side over something like a video file in the first place. You're using jwplayer, why aren't you embedding your various formats?

    Again though, I'd be pitching jwPlayer in the trash since it's doesn't let you just use the proper damned markup yourself; and has no scripting off graceful degradation.
     
    deathshadow, Jan 23, 2014 IP
  4. misohoni

    misohoni Notable Member

    Messages:
    1,717
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    200
    #4
    Yep it's all down to JWplayer, you can offer multiple formats but it will play the first file only and playlist the rest.
     
    misohoni, Jan 23, 2014 IP
  5. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #5
    Actually you can do multiple files per play-item -- it's called "levels"; I forget how to use it through, I only used jwplayer long enough to go "this is trash".
     
    deathshadow, Jan 23, 2014 IP
  6. Murugesan.quadraincorp

    Murugesan.quadraincorp Greenhorn

    Messages:
    15
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    23
    #6
    Hi,

    Do you use this simple code....

    <?php $check = $detect->isMobile();


    if(empty($check))
    {
    echo"some text":
    }
    else
    {?>
    <script type="text/javascript">
    jwplayer('video-player').setup({
    height: 320,...
    </script>

    <?php endif; ?>
     
    Murugesan.quadraincorp, Jan 23, 2014 IP
    misohoni likes this.