CircusMusic
CircusMusic

Reputation: 3

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 some 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.

Upvotes: 0

Views: 56

Answers (1)

Bill H
Bill H

Reputation: 2069

How about this:

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

Upvotes: 1

Related Questions