php - 使用 PHP 类更改 HTML 的颜色和字体大小
问题描述
我需要编写继承(扩展)我的 Colored 类的类。在新类中,文本可以有不同的字体大小以及不同的颜色。字体大小应由设置器设置。必须将其验证为 10 到 24 之间的整数,否则会引发错误消息。我的颜色类效果很好,但我的字体大小没有,有人可以帮忙吗?
class coloredHtmal extends Htmalpage {
protected $color = 'red';
public function __set($property,$value){
if($property == 'color'){
$colors = array('blue','yellow','green','black','pink','gray','gold');
if(in_array($value,$colors)){
$this->color = $value;
}
else {
die("Please select one of the allowed colors");
}
}
}
public function view(){
echo "<html>
<head>
<title> $this->title</title>
</head>
<body>
<p style = 'color:$this->color'>$this->body</p>
</body>
</html>";
}
}
class fontSizeHtmal extends coloredHtmal {
protected $fontsize = '10';
public function __set($property,$value){
if($property == 'fontsize'){
$fontsizes = array('10','11','12');
if(in_array($value,$fontsizes)){
$this->fontsize = $value;
}
else {
die("Please select one of the allowed font size");
}
}
}
public function view(){
echo "<html>
<head>
<title> $this->title</title>
</head>
<body>
<p style = 'font-size:$this->fontsize'>$this->body</p>
</body>
</html>";
}
}
这是一个示例,仅用于测试 10、11、12 字体大小的类
我用一个简单的 html 代码 (php) 对此进行了测试
<?php
include "htmalpage.php";
?>
<?php
$hml = new coloredHtmal("[title goes here]","[body goes here]");
$hml->color = 'green';
$hml->fontsize = '5';
$hml->view();
?>
解决方案
推荐阅读
- angular - 构建生产时如何禁用Angular 7代码修改?
- java - 是否可以在内存中本地创建和运行 bigquery 临时表?
- laravel-5 - Laravel 5.7 - 如何在系统启动时将 .env 中的所有变量设置为指向测试环境?
- coded-ui-tests - 有没有办法让 Coded UI Test Builder 工具不隐藏 Visual Studio?
- quarkus - 如何在 Quarkus 原生镜像中包含类路径资源?
- angular - Angular - 与同一路径的子路径关联的两个不同的延迟加载模块
- android - 如何将共享首选项从一项活动传递到另一项活动?
- angular - 在 TypeScript 中创建 const 对象的问题
- python-3.x - 即使 numpy 数据形状正确,skLearn 拟合数据输入也会失败
- visual-studio-code - 如何在 VS Code 工作区设置中使用 ${workspaceFolder}?