Heim > Backend-Entwicklung > PHP-Tutorial > Parse error: syntax error, unexpected '"class_Rect.php"'

Parse error: syntax error, unexpected '"class_Rect.php"'

WBOY
Freigeben: 2016-06-23 13:45:01
Original
921 Leute haben es durchsucht

<html>	<head>		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />		<title>图形的周长和面积计算器</title>	</head>	<body>				<?php		//自动加载		requireonce"class_Rect.php";		requireonce"class_Triangle.php";		requireonce"class_Circle.php";			function __autoload($className){				include("class_".ucfirst($className).".php");			}		?>		<center>			<h2>图形的周长和面积计算器</h2>			<hr>			<a href="test.php?action=1">矩形</a>||			<a href="test.php?action=2">三角形</a>||			<a href="test.php?action=3">圆形</a><hr>		</center>		<?php			switch($_REQUEST["action"]) {				case '1':					$form=new Form("矩形",$_REQUEST,"test.php");					echo $form;					break;				case '2':					$form=new Form("三角形",$_REQUEST,"test.php","post","_blank");					echo $form;					break;				case '3':					$form=new Form("圆形",$_REQUEST,"test.php");					echo $form;					break;				default:				echo "请选择一个形状<br>";							}			if (isset($_REQUEST["act"])) {				switch ($_REQUEST["act"]) {					case '1':						$shape=new Rect($_REQUEST);						break;					case '2':						$shape=new Triangle($_REQUEST);						break;					case '3':						$shape=new Circle($_REQUEST);						break;														}				echo "面积为:".$shape->area()."<br>";				echo "周长为:".$shape->perimeter()."<br>";			}		?>	</body></html>
Nach dem Login kopieren


回复讨论(解决方案)

requireonce 应写作
require_once

不行啊,改了也不行,我设置了自动加载

<?php        //自动加载                    function __autoload($className){                include("class_".ucfirst($className).".php");            }        ?>
Nach dem Login kopieren


但是好像加载不过来

怎么可能?你也不看看是第几行报错!

        require_once "class_Rect.php";        require_once "class_Triangle.php";        require_once "class_Circle.php";
Nach dem Login kopieren

<html>	<head>		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />		<title>图形的周长和面积计算器</title>	</head>	<body>				<?php		//自动加载		require_once "class_Rect.php";        require_once "class_Triangle.php";        require_once "class_Circle.php";			function __autoload($className){				include("class_".ucfirst($className).".php");			}		?>		<center>			<h2>图形的周长和面积计算器</h2>			<hr>			<a href="test.php?action=1">矩形</a>||			<a href="test.php?action=2">三角形</a>||			<a href="test.php?action=3">圆形</a><hr>		</center>		<?php			switch($_REQUEST["action"]) {				case '1':					$form=new Form("矩形",$_REQUEST,"test.php");					echo $form;					break;				case '2':					$form=new Form("三角形",$_REQUEST,"test.php","post","_blank");					echo $form;					break;				case '3':					$form=new Form("圆形",$_REQUEST,"test.php");					echo $form;					break;				default:				echo "请选择一个形状<br>";							}						if (isset($_REQUEST["act"])) {				switch ($_REQUEST["act"]) {					case '1':						$shape=new Rect($_REQUEST);						break;					case '2':						$shape=new Triangle($_REQUEST);						break;					case '3':						$shape=new Circle($_REQUEST);						break;														}				echo "面积为:".$shape->area()."<br>";				echo "周长为:".$shape->perimeter()."<br>";			}		?>	</body></html>
Nach dem Login kopieren
Nach dem Login kopieren

<html>	<head>		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />		<title>图形的周长和面积计算器</title>	</head>	<body>				<?php		//自动加载		require_once "class_Rect.php";        require_once "class_Triangle.php";        require_once "class_Circle.php";			function __autoload($className){				include("class_".ucfirst($className).".php");			}		?>		<center>			<h2>图形的周长和面积计算器</h2>			<hr>			<a href="test.php?action=1">矩形</a>||			<a href="test.php?action=2">三角形</a>||			<a href="test.php?action=3">圆形</a><hr>		</center>		<?php			switch($_REQUEST["action"]) {				case '1':					$form=new Form("矩形",$_REQUEST,"test.php");					echo $form;					break;				case '2':					$form=new Form("三角形",$_REQUEST,"test.php","post","_blank");					echo $form;					break;				case '3':					$form=new Form("圆形",$_REQUEST,"test.php");					echo $form;					break;				default:				echo "请选择一个形状<br>";							}						if (isset($_REQUEST["act"])) {				switch ($_REQUEST["act"]) {					case '1':						$shape=new Rect($_REQUEST);						break;					case '2':						$shape=new Triangle($_REQUEST);						break;					case '3':						$shape=new Circle($_REQUEST);						break;														}				echo "面积为:".$shape->area()."<br>";				echo "周长为:".$shape->perimeter()."<br>";			}		?>	</body></html>
Nach dem Login kopieren
Nach dem Login kopieren




这里的报错是显示$_REQUEST["action"]不存在,没有这个索引

你需要判断是否为空

$action = isset($_REQUEST["action"]) ? $_REQUEST["action"] : '';switch($action){//。。。。。。。。}
Nach dem Login kopieren

Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage