PHP Classes

HARD ONE! preg_replace_callback, HELP!

Recommend this page to a friend!

      Top level forums  >  PHP Specialists  >  General  >  HARD ONE! preg_replace_callback, HELP!  
Subject:HARD ONE! preg_replace_callback, HELP!
Summary:I really need help to solve var questions with create_function
Messages:3
Author:Tiago Diaz
Date:2009-10-08 01:56:04
Update:2009-10-08 09:30:06
 

  1. HARD ONE! preg_replace_callback, HELP!   Reply   Report abuse  
Picture of Tiago Diaz Tiago Diaz - 2009-10-08 02:04:23
Well to understood what i am trying... Run the code above!

<?php
class teste{

var $rep;

public function sql($sql_){
$this->rep['id'] = '0';
$this->rep['name'] = "'teste'";
$this->rep['text'] = "'testando...'";

return $this->returnSQL($sql_,$this->rep);
}

public function returnSQL($sql,$rep){
return preg_replace_callback("/%([A-Za-z0-9]*)%/",create_function('$arr','global $rep; return $rep[$arr[1]];'),$sql);
}
}

$temp = new teste();
echo $temp->sql("SELECT * FROM teste WHERE id = %id% AND temp = %text% AND temp_3 = %text% AND temp_1 = %name%");
?>

I need to get the $this->rep from inside the preg_replace_callback with the create_function, but i tryed everything i can, but nothing worked, i am really desesperated... needing an urgent help!

There are 2 replies in this thread, which are not being displayed.
Browsing this forum thread replies is available only to premium subscribers.


Go to the premium subscriptions page to learn how to become a premium subscriber and have full access to this forum.