Page 1 of 1

[SOLVED] preg_replace \\1 inside function

Posted: Wed Apr 14, 2004 11:09 pm
by phice
I'm trying to get the value of \\1 into a function.

My code:

Code: Select all

$this->body = preg_replace("#\[attachment=(.*?)\]#si",           attachment("\\1"), $this->body);
I need to get the value of \\1 into the attachment() function. I'm sure it's possible, any help?

Posted: Thu Apr 15, 2004 12:15 am
by redmonkey

Posted: Thu Apr 15, 2004 7:30 am
by phice
Thanks! :)

For future reference (visitors looking for a default answer), here's the code that I used:

Code: Select all

$this->body = preg_replace_callback("#\[attachment=(.*?)\]#si",  create_function('$matches', 'return attachment($matches[1]);'), $this->body);

Posted: Thu Apr 15, 2004 7:38 am
by malcolmboston
omg phice i love you

ive had this problem for weeks!!!!

full steam ahead!!!

Posted: Thu Apr 15, 2004 8:01 am
by magicrobotmonkey
whats so great about this \\1 anyways?

Posted: Thu Apr 15, 2004 10:32 pm
by phice
\\1 returns the value of the first (hint: 1) (.*?) in the first set of quotes.