Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP和HTML格式,超基本问题_Php_Html_Formatting - Fatal编程技术网

PHP和HTML格式,超基本问题

PHP和HTML格式,超基本问题,php,html,formatting,Php,Html,Formatting,在我的代码中,有一个阶段我有太多的代码,太多的HTML取决于某些服务器条件的后果 我只是想知道,有没有办法绕过: <?php if (cond) echo '<p class="someclass">some HTML</p>'; ?> 我现在所能做的就是: <?php if (x) require_once("includes/all_needed_part.php"); ?> 谢谢 猜你是在问是否有php可用的框架?答案是肯定的,这里

在我的代码中,有一个阶段我有太多的代码,太多的HTML取决于某些服务器条件的后果

我只是想知道,有没有办法绕过:

<?php if (cond) echo '<p class="someclass">some HTML</p>'; ?> 
我现在所能做的就是:

<?php if (x) require_once("includes/all_needed_part.php"); ?>


谢谢

猜你是在问是否有php可用的框架?答案是肯定的,这里至少有一个很好的答案:

不太清楚你在问什么,所以如果我正确理解你的问题,你是在寻找一种用PHP打印HTML块的方法吗

<?php if ($a == $b): ?>
  <div>a == b</div>
  <p>a is equal to b</p>
<?php else: ?>
  <div>a != b</div>
  <p>a is not equal to b</p>
<?php endif; ?>

a==b
a等于b

a!=B a不等于b


您可以将与结合使用。

我通常这样做:

<?
    function print_heading()
    {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title><? print_title(); ?></title>
    <link rel="stylesheet" type="text/css" href="..." />
    <script language="javascript" type="text/javascript" src="..."></script>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="title" content="<? print_title(); ?>" />
</head>
<?
    }
?>


您可以执行以下操作:

<?php if( cond ) { ?>
    SECRET!
<?php } ?>

秘密

还有另一种语法:

<?php if($x): ?>
do_a_lot_of_html_stuff;
<?php endif; ?>

做很多html的东西;

我建议您查看一个非常成熟的PHP应用程序。一个更新的(更干净的)解决方案是,它被采用了。

您可以使用类似c的语法,并且仍然可以做很多事情,比如

这是典型的php使用类似c的语法的方法

<?php
    if(1==1):
        echo 'i can do lots of stuff here';
        $variable = 'i hold some value';
        $array = array('1','two','three');
    endif;
?>

另一种实现方法是使用括号。比如说

<?php
if(condition) {
   //do some stuff here
} else if(cond) {
   //do another stuff here based on some conditions 
} else if(cond) {
    //you can extend the nested elseif as many times as you like
} else {
    //else execute this.
}
?>

我想您的代码应该使用面向对象编程。
过程编码很好,但最终会达到页面中的代码数量非常多的程度。

您可以在PHP条件之间添加HTML,如下所示:

<?php 
$a=1;
if($a==1){ ?>
<div>All the HTML Stuffs</div>
<?php } ?>

所有HTML内容

模糊的问题。你是说你想要一个框架吗?C版本和PHP版本一样冗长。无论您使用什么样的框架或模板系统,都会遇到这种单调乏味的情况。在某个时刻,你只需要咬着键盘开始打字。如果(cond){…;…;…;…;…;}
,做
有什么不对吗?这个问题不是:“你最喜欢的PHP框架是什么?请宣传它。”不是宣传我最喜欢的。我只是随便举个例子,没问题。顺便说一句,你也可以把
希望它有帮助!!
<?php 
$a=1;
if($a==1){ ?>
<div>All the HTML Stuffs</div>
<?php } ?>