1

I am working with PHP includes i.e:

include_once("somephpfile.php");

And a CSS/HTML designer that is very problematic. I am trying to keep all PHP away from the designer, as they become very panicked : \ and they create many problems, deleting code and things and messing up everything.

So I have been using the PHP includes to add the PHP where necessary between their HTML.

The PHP works fine and there are zero bugs.

It is the separation of the PHP into multiple include files that is causing my some problems.

Following is an example of what I am trying to separate.

The PHP to be separated:


<?php
$foo = 0;
$bar = 0;

if($foo == 0){

    $foo++;
    $bar++;
    // more php code

    while($foo < 20){

        $foo++;
        $bar++;
        // more php code

    // Now write the designers HTML here in this loop
    ?>  

        <BR /> Some HTML 
        <?php echo $foo; ?>
         more html 
        <?php echo $bar; ?>
        <BR /> More HTML <BR /> <BR />

    <?php
    // Done with the designers code -Now close my PHP here

   }// END while($foo < 5)

}// END if($foo == 0)
?>

I want to separate this into 2 includes - include1.php and include2.php

And I want to have the designers code between the while loop. So what I did was this:


include1.php

   if($foo == 0){

    $foo++;
    $bar++;
    // more php code

      while($foo < 20){

        $foo++;
        $bar++;
       // more php code
   ?>

DESIGNERS HTML and a little mixed PHP

    <BR /> Some HTML 
    <?php echo $foo; ?>
     more html 
    <?php echo $bar; ?>
    <BR /> More HTML <BR /> <BR />

include2.php

    <?php
   // Done with the designers code -Now close my PHP here

  }// END while($foo < 5)

}// END if($foo == 0)
?>

I get an error ("Parse error: syntax error, unexpected $end in)

I have multiple if's and while's and loops.

My question is: How do I separate these braces / brackets without an error?

Thank you

4

3 回答 3

0

你想做什么是错的。您不能将 PHP 控制结构分解ifwhile多个文件。如果您需要将 PHP 与 HTML 分开,您最好的选择可能是Smarty 模板。它们将使您的 HTML 保持稳定和干净,与 PHP 相同。

于 2012-11-25T23:52:47.033 回答
0

我认为您与包含中的开头<?php和结尾?>位不一致,如果它们与发布的一样。它们需要像往常一样在 PHP 代码之前和之后。即使那样,我也不确定它是否会起作用。

相反,您应该颠倒这个想法,为“设计者的 HTML”创建一个单独的 .php 文件,您可以将其包含到您的 PHP 中。这样,设计者就有了一个只有简单的 PHP 用于回显的文件。对于您的目的,这可能是逻辑和设计的合适分离。

于 2012-11-25T23:53:55.473 回答
0

使用智能。这将有助于将表示方面与 PHP 分开。

于 2012-11-26T01:34:23.643 回答