开发者

using a variable to referance another in a class in PHP

so here's a cut down version of my code:

class lookAClass
{
 public $pageTitle;

 public function add()
 {
  $tmp = 'just some filler text <[pageTitle]> and so开发者_如何学JAVAme more text';
  echo preg_replace_callback('<\<\[(.*)\]\>>', array(&$this, 'parseAdd'), $tmp);
 }

 private function parseAdd($matches)
 {
  return $this->$matches[1];
 }


}

$main = new lookAClass();

$main->add();

So basically what I'm trying to do is replace "<[pageTitle]>" with $this->pageTitle

I know $this->$matches[1] is incorrect but I can't seem to find how to make the connection.


How about this:

echo str_replace('<[pageTitle]>', $this->pageTitle, $tmp);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜