$rep_obj = new TextModify("<b>","</b>");こんな具合に、ヘッダーとフッターを引数に指定してnewしていることがわかります。
※リストが表示されない場合
AddBlockなどの広告ブロックツールがONになっているとリストなどが表示されない場合があります。これらのツールをOFFにしてみてください。
<?php class TextModify { private $header = "<b>"; private $footer = "</b>"; private $body = ""; private $find = "PHP"; public function __construct($h,$f){ $this->setHeader($h); $this->setFooter($f); } function setHeader($s){ $this->header = $s; } function setFooter($s){ $this->footer = $s; } function setBody($s){ $this->body = htmlspecialchars(strtoupper($s)); } function setFind($s){ $this->find = $s; } function getRenderText(){ $res = str_replace($this->find, $this->header . $this->find . $this->footer, $this->body); return $res; } function writeRenderText(){ echo $this->getRenderText(); } } // インスタンスの準備 $title_obj = new TextModify('<span style="color:red;">','</span>'); $title_obj->setFind("PHP"); $title_obj->setBody('Hello PHP!'); $msg_obj = new TextModify('<span style="color:blue;">','</span>'); $msg_obj->setBody('ここに、PHPという文字を含む文章を書いて下さい。'); $rep_obj = new TextModify("<b>","</b>"); if ($_POST != null){ $str = $_POST['text1']; $rep_obj->setBody($str); } ?> <!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" xml:lang="ja" lang="ja"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>sample page</title> </head> <body> <h1><?php $title_obj->writeRenderText(); ?></h1> <p><?php $msg_obj->writeRenderText(); ?></p> <hr> <p><?php $rep_obj->writeRenderText(); ?></p> <form method="post" action="./index.php"> <textarea name="text1" cols="40" rows="5"><?php echo $str; ?></textarea> <br><input type="submit"> </form> <hr> </body> </html>
<< 前へ | 次へ >> |