答案:class htmlcode {
public $content;
public function __construct($content = '') {
$this->content = $content;
}
public function replace($str, $tostr) {
$this->content = str_replace($str, $tostr, $this->content);
}
public function getNewContent() {
return $this->content;
}
}
//实例化
$html = new htmlcode('asdfasad dfasdf<br>adsfdf df df');
$html->replace("<br>", "\n");
$html->replace("f", "F");
echo $html->getNewContent();
//或
$html = new htmlcode();
$html->content = 'asdfasad dfasdf<br>adsfdf df df';
$html->replace("<br>", "\n");
$html->replace("f", "F");
echo $html->getNewContent();
其他:class str{
public function htmlcode($content=''){
$content=str_replace("\n","<br>",str_replace(" "," ",$content));
return $content;
}
}
调用:
$str=new str;
$abc=$str->htmlcode('<div></div>');
上一个:编写程序由表单递交运算数与运算符,输出运算式与运算结果,用php编写。
下一个:我想学习网页制作,现在的情况是,会写C++程序,但是对html,php这类的一窍不通。请问该从哪里先学起?