Preg_replace How to replace Preg_replace_callback

Source: Internet
Author: User
Tags html comment mysql query
Younger brother previously engaged in Delphi development, was forced to learn PHP society, today blow directly blindfolded.
How to change this, the program error needs to replace the preg_replace into Preg_replace_callback
$fields = Preg_replace ('/([a-za-z0-9_]+) \. ( [a-za-z0-9_*]+)/E ', "\ $this->_getfieldtable (' \\1 '). \\2 ' ", $fields);


Reply to discussion (solution)

This is too difficult!!!!

$fields = Preg_replace ('/([a-za-z0-9_]+) \. ( [a-za-z0-9_*]+]/', function ($r) {  return $this->_getfieldtable ($r [1]). $r [2];  }, $fields);

$fields = Preg_replace ('/([a-za-z0-9_]+) \. ( [a-za-z0-9_*]+]/', function ($r) {  return $this->_getfieldtable ($r [1]). $r [2];  }, $fields);

Error
Object of class Closure could not being converted to string

Then you've already had an error.

$fields = Preg_replace_callback ('/([a-za-z0-9_]+) \. ( [a-za-z0-9_*]+]/', Array ($this, "_getfieldtable"), $fields);

But _getfieldtable to change it, because it is an array.

Attached source, God help me see

* * The field list when getting queries * * @author Garbin * @param string $src _fields_list * @return St        Ring */function Getrealfields ($src _fields_list) {$fields = $src _fields_list;        if (! $src _fields_list) {$fields = '; }//$fields = Preg_replace ('/([a-za-z0-9_]+) \. ( [a-za-z0-9_*]+)/E ', "\ $this->_getfieldtable (' \\1 '). \\2 ' ", $fields); $fields = Preg_replace_callback ('/([a-za-z0-9_]+) \. (        [a-za-z0-9_*]+]/', function ($r) {return $this->_getfieldtable ($r [1]). $r [2];}, $fields); $fields = Preg_replace_callback ('/([a-za-z0-9_]+) \. (    [a-za-z0-9_*]+]/', function ($r) {return $this->_getfieldtable ($r (1). $r (2));}, $fields); return $fields;     }/** * Parse field belongs to * * @author Garbin * @param string $owner * @return string        */function _getfieldtable ($owner) {if ($owner = = ' this ') {return $this->alias;        } else{$m =& m ($owner);            if ($m = = = False) {/* If there is no object, returns the */return $owner;        } return $m->alias; }    }

15,16 I use the xuzuning of the great God.


        $fields = Preg_replace ('/([a-za-z0-9_]+) \. ( [a-za-z0-9_*]+)/E ', "\ $this->_getfieldtable (' \\1 '). \\2 ' ", $fields);        $fields = Preg_replace_callback ('/([a-za-z0-9_]+) \. ( [a-za-z0-9_*]+]/', function ($r) {return $this->_getfieldtable ($r [1]). $r [2];}, $fields);           $fields = Preg_replace_callback ('/([a-za-z0-9_]+) \. ( [a-za-z0-9_*]+]/', function ($r) {return $this->_getfieldtable ($r (1). $r (2));}, $fields);        return $fields;


The combined query statement looks like this.
MySQL error[1054]: Unknown column ' User_privprivs ' in ' field list ' MySQL query:select user_privprivs, SSTORE_NAME,USER_PR ivuser_id,s.store_id from Ecm_store s left JOIN ecm_user_priv user_priv on s.store_id = user_priv.store_id WHERE user_priv . user_id in (' 1 ') ORDER by sstore_id DESC wrong File: \eccore\model\mysql.php[534]


It's supposed to be that way.
SELECT User_priv.privs, s.store_name,user_priv.user_id,s.store_id from Ecm_store s left joins Ecm_user_priv User_priv on S . store_id = user_priv.store_id WHERE user_priv.user_id in (' 1 ') ORDER by s.store_id DESC

The problem with the error is that User_priv.privs and user_priv.user_id and s.store_id focus on the reference "." None of them.

Oh, I missed a point.

$fields = Preg_replace ('/([a-za-z0-9_]+) \. ( [a-za-z0-9_*]+]/', function ($r) {  return $this->_getfieldtable ($r [1]). ". $r [2]";  }, $fields);

the last one, thank you xuzuning the great God. Preg_replace How to replace the last face

/** * Replace the picture path in the module * * @author Liupeng * @param string $source content * @return string **/function        Smarty_prefilter_precompile ($source) {$file _type = Strtolower (STRRCHR ($this->_current_file, '. '));        $tmp _dir = "; /* Replace the file encoding header */if (Strpos ($source, "\XEF\XBB\XBF")!== FALSE) {$source = Str_replace ("\xef\xbb\x        BF ",", $source); if ($this->store_id > 0) {if (Strpos ($this->_current_file, '/mall/resource ')!== fals                e) {$mall _skin = $this->options[' Mall_skin ');            $tmp _dir = "themes/mall/skin/$mall _skin/"; } else {$tmp _dir = "themes/store/skin/". $this->skin.            '/' ; }} else {$tmp _dir = "themes/mall/skin/". $this->skin.        '/' ; } $pattern = Array ('/
 /',//replace Smarty Notes '/
 /',//replace the non-newline HTML comment '/(href=[' |\ ']) \.\.\/(. *?) (["|\ '])/I ',//Replace relative link '/((?: background|src) \s*=\s*[" |\ ') "(?: \. \/|\.\.\/)? (images\/.*?) ["|\']) /is ',//before images plus $tmp _dir '/((?: background|background-image): \s*?url\ () (?: \. \/|\.\.\/)? (images\/)/is ',//before images plus $tmp _dir '/{nocache} (. +?)        {\/nocache}/ise ',//no cache module); $replace = Array (' \1 ', ' ', ' \1\2\3 ', ' \1 '. $tmp _dir. ' \2 ', ' \1 '. $tmp _dir. ' \2 ', ' ' {insert name=\ ' nocache\ '. '" . $this->_echash. "' . Base64_encode (' \\1 ').        '}'",            );    Return Preg_replace ($pattern, $replace, $source); }

The only last pair that needs to be modified:

$source = Preg_replace_callback ('/{nocache} (. +?) {\/nocache}/is ', function ($r) {    return ' {Insert name= ' NoCache "'  . $this->_echash.  Base64_encode ($r [1]). '}'; }, $source);

Xu always give strength Ah,

    function Fetch_str ($source)    {        if (!defined (' is_backend '))        {            $source = $this->smarty_prefilter_ Precompile ($source);        }        Return Preg_replace ("/{([^\}\{\n]*)}/e", "\ $this->select (' \\1 ');", $source);    }

/E is eval ("return string")
You take off the outer quotes, you're right.

function ($r) {
return $this->select ($r [1]);
}

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.