Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 7 of 7

Thread: PHP in PHP

  1. #1
    Senior Member
    Join Date
    Sep 2003
    Location
    Sydney
    Posts
    114
    Member #
    3051
    I'm trying to build a template for Joomla for this site that I'm doing, but I want it to break out of the template for the forum (because of the width).

    I'm trying to use if else to use different CSS, with luck.

    Where I run into trouble is if I then try and load the Joomla components. It doesn't render any of it, I assume because they're php tags inside of the if else statement.

    Anyone know a way around it?

    PHP Code:
    <?php defined'_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <?php $iso split'='_ISO );
    echo 
    '<?xml version="1.0" encoding="'$iso[1] .'"?' .'>';
    ?>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; <?php echo _ISO?>" />
    <?php mosShowHead(); ?>
    <?php
    if ( $my->id ) {
        
    initEditor();
    }

    if ((
    mosCountModules'user1' )) && (mosCountModules'user2' ))) {
    //if both modules are loaded, we need a 50%-layout for them
        
    $usera 'user1';
        
    $userb 'user2';
    } else if ((
    mosCountModules'user1' )) || (mosCountModules'user2' ))) {
    // if only one, then 100% no matter which one.
        
    $usera 'user3';
        
    $userb 'user3';
    }
    ?>
    <meta http-equiv="Content-Type" content="text/html; <?php echo _ISO?>" />
        <link href="<?php echo $mosConfig_live_site;?>/templates/spursca/css/template_css.css" rel="stylesheet" type="text/css" />
        </head>
        <body>
        <div id="header">
        <img src='<?php echo $mosConfig_live_site;?>/templates/spursca/images/header_logo.jpg' />
        </div>
        <?php if ($_GET['option'] == 'com_fireboard'){
        echo 
    "<div id='forumcontainer'>
    <!--rounded top--><div id='topleft'><div id='topright'><?php elseif (mosCountModules( 'left' )) { mosLoadModules ( 'left',-3); } ?></div></div><!--rounded top-->
        <div class='news'>Forum</div><br />
        <!--container--></div><!--container-->"
    ;
    }
    else { echo 
    "<div id='container'>
    <!--rounded top--><div id='topleft'><div id='topright'>Top</div></div><!--rounded top-->
        <div id='wrapper'>
        <div id='left'>
        <div class='news'>Stfs</div><br />
        <div class='headlines'>sda</div>
        <!--left--></div><!--left-->
        <div id='right'>
        <div class='search'>asd</div>
            <!--right--></div><!--right-->
        <!--wrapper--></div><!--wrapper-->
        <br class='clear:both' />
        <!--container--></div><!--container-->"
    ; } ?>
        </body>
    </html>

  2.  

  3. #2
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    Either don't use echo, or only use echo. You can effectively echo something out in an if statement by just closing your PHP block and putting whatever you want there, and then reopening it and putting your closing braces. Not that interpolating your PHP code into your HTML is such a great idea.

  4. #3
    ljm
    ljm is offline
    Senior Member ljm's Avatar
    Join Date
    Aug 2006
    Location
    Manchester, England
    Posts
    284
    Member #
    13684
    Liked
    1 times
    The problem is at the lower part of the document. You're echoing PHP code as plain text, so it won't be interpreted at all.

    Code:
    echo "... <?php elseif (mosCountModules( 'left' )) { mosLoadModules ( 'left',-3); } ?> ...";
    That won't work because you're enclosing PHP in itself, and even if it did work, you'd get errors if you just took out the [minicode]echo ""[/minicode] bit.

    If you did all that yourself, I suggest you recode it so it's more consistent, for example, either don't use echo, or only use it, like Shadowfiend said.

  5. #4
    Senior Member
    Join Date
    Sep 2003
    Location
    Sydney
    Posts
    114
    Member #
    3051
    Hmmm...not sure I understand too well. Are you saying that I should not use it this way?

  6. #5
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    PHP code in php tags in a PHP string isn't evaluated. The only way PHP code is evaluated is if it's between PHP tags and outside of a string.

  7. #6
    Senior Member
    Join Date
    Sep 2003
    Location
    Sydney
    Posts
    114
    Member #
    3051
    Okay cheers...I thought as much.

    Someone suggested using 'eval' instead of 'echo'...is that an option?

  8. #7
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    I doubt evaling code with <?php ?> is going to work. It really doesn't matter, though. What you're trying to do is trivially achievable by not using echo but just closing the PHP tags and then reopening them later.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 07:51 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com