我正在尝试使用php创建自定义CMS。我想做的是让“管理员”创建不同内容的不同HTML页面!
页面创建进展顺利但只有当html页面非常基本并且没有样式或jquery内容时它才会顺利进行! HTML页面也会有一些CSS样式和一些javascript和jQuery代码,但由于某些原因,在页面中使用它们会停止在PHP中创建HTML页面!
第一个代码(工作代码)使用:
`$html = "<html>\n<body>\n<p>Hello world</p>\n</body>\n</html>";`
,第二个代码(非工作代码)使用:
$html = "the whole HTML page with CSS and javascript/jQuery copy/pasted here";
此代码可以正常工作:
<?
if ($_POST["filename"]) {
error_reporting(0);
$i=1;
while($file = fopen("untitled$i.html", "r")) { fclose($file); $i++; }
if($file = fopen("untitled$i.html", "w")) {
$html = "<html>\n<body>\n<p>Hello world</p>\n</body>\n</html>";
if(fwrite($file, $html) === false) { echo "Could not write"; exit; }
fclose($file);
$newfile=$_POST["filename"].".html";
system("mv untitled$i.html $newfile");
header("Location: $newfile");
}
}
else {
echo "<form method=post action='".$_SERVER["SCRIPT_NAME"]."'>\n";
echo "New File Name: <input name='filename'>\n</form>\n";
}
?>
<table width="100%" border="0" cellpadding="8">
<tr>
<td> </td>
</tr>
<tr>
<td bgcolor="#FFDDDD"><form id="form2" name="form2" method="post" action="createpagestest.php" onsubmit="return validate_form2 ( );">
<br />
<input type="submit" name="button" id="button" value="Add Page" />
<input name="filename" type="text" id="filename" size="8" maxlength="11" />
<br />
</form></td>
</tr>
</table>
但如果我这样做,它根本不会创建任何HTML页面....
<?
if ($_POST["filename"]) {
error_reporting(0);
$i=1;
while($file = fopen("untitled$i.html", "r")) { fclose($file); $i++; }
if($file = fopen("untitled$i.html", "w")) {
$html = "<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">
<head profile="http://gmpg.org/xfn/11">
<title>My title</title>
<link rel="stylesheet" type="text/css" href="css/main.css">
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.js"></script>
<script src="http://dev.jquery.com/view/tags/ui/latest/ui/effects.core.js"></script>
<script src="http://dev.jquery.com/view/tags/ui/latest/ui/effects.slide.js"></script>
<script type="text/javascript" src="supersized.2.0.js"></script>
<script type="text/javascript">
$(function(){
$.fn.supersized.options = {
startwidth: 640,
startheight: 480,
vertical_center: 1,
slideshow: 1,
navigation: 1,
transition: 1, //0-None, 1-Fade, 2-slide top, 3-slide right, 4-slide bottom, 5-slide left
pause_hover: 0,
slide_counter: 1,
slide_captions: 1,
slide_interval: 6000
};
$('#supersize').supersized();
});
</script>
</head>
<body >
<div id="Details1">
<div class="txtD">
<h1>HOME</h1>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p><br /><br />
</div>
</div>
<div id="CloseButton"><a id="ClosePanel" href="#"><img src="images/close.png" width="15" height="11" /></a></div>
<div id="OpenButton"><a id="OpenPanel" href="#"><img src="images/open.png" width="15" height="11" /></a></div>
<div id="navBarHolder">
<a href="index_2.html" class="stamp"><img width="200" src="images/logoF.png"/></a>
<nav>
<ul>
<li><a href="#" id="home">Home</a></li>
<li><a href="#">Corporate</a></li>
<li><a href="#">Eco statement</a></li>
<li><a href="#">Private</a></li>
</ul>
</nav>
<nav id="nav2">
<ul>
<li><a href="#"><img src="images/facebook.png" width="20" height="20" alt="facebook" /></a></li>
<li><a href="#"><img src="images/twitter.png" width="20" height="20" alt="twitter" /></a></li>
<li><a href="#"><img src="images/pinterest.png" width="20" height="20" alt="instgram" /></a></li>
<li><a href="#"><img src="images/rhenvelope.png" width="20" height="20" alt="email" /></a></li>
</ul>
</nav>
<nav id="nav3">
<ul>
<li>Tell | 01700000</li>
<li>Fax | 01700000</li>
<li>info@site.com</li>
</ul>
</nav>
<nav id="nav4">
<ul>
<li>© site Copyright. All Rights Reserved.</li>
</ul>
</nav>
</div>
<!--Loading display while images load-->
<div id="loading"> </div>
<!--Slides-->
<div id="supersize">
<a href="#"><img src="images/bird.jpg" title="Bird On A Branch"/></a>
<a href="#"><img src="images/paradise.jpg" title="Paradise Lost"/></a>
<a href="#"><img src="images/snake.jpg" title="Morelia Viridis"/></a>
</div>
<!--Content area that hovers on top-->
<div id="content">
<div id="contentframe">
<!--Logo-->
<!--Navigation-->
<div id="navigation">
<a href="#" id="prevslide"><img src="images/back_dull.gif"/></a><a href="#" id="pauseplay"><img src="images/pause_dull.gif"/></a><a href="#" id="nextslide"><img src="images/forward_dull.gif"/></a>
</div>
</div>
</div>
<script type="text/javascript">
$(function(){
$('#Details1').animate({'left': 200},1000);
});
$(function(){
$("#ClosePanel").click(function () {
$("#Details1").animate({'left': -500},500,function(){
$("#Details1").css('display','none')
$("#CloseButton").css('display','none')
$("#OpenButton").css('display','block')
});
});
});
$(function(){
$("#OpenPanel").click(function () {
$("#Details1").animate({'left': 200},1000,function(){
$("#Details1").css('display','block')
$("#CloseButton").css('display','block')
$("#OpenButton").css('display','none')
});
});
});
</script>
</body>
</html>
";
if(fwrite($file, $html) === false) { echo "Could not write"; exit; }
fclose($file);
$newfile=$_POST["filename"].".html";
system("mv untitled$i.html $newfile");
header("Location: $newfile");
}
}
else {
echo "<form method=post action='".$_SERVER["SCRIPT_NAME"]."'>\n";
echo "New File Name: <input name='filename'>\n</form>\n";
}
?>
<table width="100%" border="0" cellpadding="8">
<tr>
<td> </td>
</tr>
<tr>
<td bgcolor="#FFDDDD"><form id="form2" name="form2" method="post" action="createpagestest.php" onsubmit="return validate_form2 ( );">
<br />
<input type="submit" name="button" id="button" value="Add Page" />
<input name="filename" type="text" id="filename" size="8" maxlength="11" />
<br />
</form></td>
</tr>
</table>
有人可以帮助我吗?
答案 0 :(得分:0)
也许这有效:
$html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">
<head profile="http://gmpg.org/xfn/11">
<title>My title</title>
<link rel="stylesheet" type="text/css" href="css/main.css">
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.js"></script>
<script src="http://dev.jquery.com/view/tags/ui/latest/ui/effects.core.js"></script>
<script src="http://dev.jquery.com/view/tags/ui/latest/ui/effects.slide.js"></script>
<script type="text/javascript" src="supersized.2.0.js"></script>
<script type="text/javascript">
$(function(){
$.fn.supersized.options = {
startwidth: 640,
startheight: 480,
vertical_center: 1,
slideshow: 1,
navigation: 1,
transition: 1, //0-None, 1-Fade, 2-slide top, 3-slide right, 4-slide bottom, 5-slide left
pause_hover: 0,
slide_counter: 1,
slide_captions: 1,
slide_interval: 6000
};
$("#supersize").supersized();
});
</script>
</head>
<body >
<div id="Details1">
<div class="txtD">
<h1>HOME</h1>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry"s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p><br /><br />
</div>
</div>
<div id="CloseButton"><a id="ClosePanel" href="#"><img src="images/close.png" width="15" height="11" /></a></div>
<div id="OpenButton"><a id="OpenPanel" href="#"><img src="images/open.png" width="15" height="11" /></a></div>
<div id="navBarHolder">
<a href="index_2.html" class="stamp"><img width="200" src="images/logoF.png"/></a>
<nav>
<ul>
<li><a href="#" id="home">Home</a></li>
<li><a href="#">Corporate</a></li>
<li><a href="#">Eco statement</a></li>
<li><a href="#">Private</a></li>
</ul>
</nav>
<nav id="nav2">
<ul>
<li><a href="#"><img src="images/facebook.png" width="20" height="20" alt="facebook" /></a></li>
<li><a href="#"><img src="images/twitter.png" width="20" height="20" alt="twitter" /></a></li>
<li><a href="#"><img src="images/pinterest.png" width="20" height="20" alt="instgram" /></a></li>
<li><a href="#"><img src="images/rhenvelope.png" width="20" height="20" alt="email" /></a></li>
</ul>
</nav>
<nav id="nav3">
<ul>
<li>Tell | 01700000</li>
<li>Fax | 01700000</li>
<li>info@site.com</li>
</ul>
</nav>
<nav id="nav4">
<ul>
<li>© site Copyright. All Rights Reserved.</li>
</ul>
</nav>
</div>
<!--Loading display while images load-->
<div id="loading"> </div>
<!--Slides-->
<div id="supersize">
<a href="#"><img src="images/bird.jpg" title="Bird On A Branch"/></a>
<a href="#"><img src="images/paradise.jpg" title="Paradise Lost"/></a>
<a href="#"><img src="images/snake.jpg" title="Morelia Viridis"/></a>
</div>
<!--Content area that hovers on top-->
<div id="content">
<div id="contentframe">
<!--Logo-->
<!--Navigation-->
<div id="navigation">
<a href="#" id="prevslide"><img src="images/back_dull.gif"/></a><a href="#" id="pauseplay"><img src="images/pause_dull.gif"/></a><a href="#" id="nextslide"><img src="images/forward_dull.gif"/></a>
</div>
</div>
</div>
<script type="text/javascript">
$(function(){
$("#Details1").animate({"left": 200},1000);
});
$(function(){
$("#ClosePanel").click(function () {
$("#Details1").animate({"left": -500},500,function(){
$("#Details1").css("display","none")
$("#CloseButton").css("display","none")
$("#OpenButton").css("display","block")
});
});
});
$(function(){
$("#OpenPanel").click(function () {
$("#Details1").animate({"left": 200},1000,function(){
$("#Details1").css("display","block")
$("#CloseButton").css("display","block")
$("#OpenButton").css("display","none")
});
});
});
</script>
</body>
</html>
';
答案 1 :(得分:0)
作为一般规则,您不能使用引号("
)在PHP中定义字符串,然后在其中放置一些其他引号而不转义它们。所以你可以这样做:
$var = "foo 'bar'";
或
$var = "foo \"bar\"";
或
$var = 'foo "bar"';
请记住,你不能将它们组合在一起,因为用引号声明的字符串中的未转义引号只会结束字符串声明,并且很可能在它之后写入会产生语法错误。
答案 2 :(得分:0)
在浏览器中按CTRL-U,然后在以下行中查看正在加载的CSS:
link rel="stylesheet" type="text/css" href="css/main.css"
或尝试添加斜杠
link rel="stylesheet" type="text/css" href="/css/main.css"