Digital Point Forums
Winn Law Group

Go Back   Digital Point Forums > Design & Development > Programming > PHP
Google Analytics
Log In to view
your analytics

Reply
 
Thread Tools
  #1  
Old May 9th 2008, 6:42 am
J.T.D. J.T.D. is offline
Grunt
 
Join Date: Feb 2008
Posts: 86
J.T.D. is on a distinguished road
preg_replace Help

Ok. I'm trying to include files using a tag "{T.filename}". Here's my code:

php Code:
<?php
$str = '{T.test} test {T.lawl}';

preg_replace("#{T.(.+?)}#is", include(\\1), $str);
?>
I don't know how I would include it successfully. Any help?

- JTD
Reply With Quote
  #2  
Old May 9th 2008, 5:45 pm
TeraTask TeraTask is offline
Grunt
 
Join Date: Jan 2008
Location: Reno
Posts: 37
TeraTask is on a distinguished road
Check out "Example #4 Using the 'e' modifier" on the preg_replace php.net page. That's what allows you to execute functions in preg_replace.
Reply With Quote
  #3  
Old May 10th 2008, 10:17 am
J.T.D. J.T.D. is offline
Grunt
 
Join Date: Feb 2008
Posts: 86
J.T.D. is on a distinguished road
Could you please tell me how? I've been trying:

php Code:
$str = '{T.tester} hi';
preg_replace("/{T.(.+?)}/e", "file_get_contents(eval('\\1'))", $str);
php Code:
$str = '{T.tester} hi';
preg_replace("/{T.(.+?)}/e", "'.include('\\1').'", $str);
php Code:
$str = '{T.tester} hi';
preg_replace("/{T.(.+?)}/e", include("'\\1'")), $str);
And many more variations. I still don't get it =S
Reply With Quote
  #4  
Old May 10th 2008, 12:17 pm
hip_hop_x's Avatar
hip_hop_x hip_hop_x is offline
Hand of A'dal
 
Join Date: Jun 2007
Posts: 384
hip_hop_x is on a distinguished road
php Code:
preg_match("#{T\.([\S]+)}#i","{T.test} test {T.lawl}", $match);
/*
$match[1] is test
*/
__________________
Coderi
Reply With Quote
  #5  
Old May 10th 2008, 12:31 pm
jayshah's Avatar
jayshah jayshah is offline
of the Nightfall
 
Join Date: Jan 2008
Location: London, UK
Posts: 1,128
jayshah is a jewel in the roughjayshah is a jewel in the roughjayshah is a jewel in the rough
This works on PHP 5:

php Code:
<?php
function inc($match){
        include($match[1]);
}

$str = '{T.test} test {T.lawl}';

echo preg_replace_callback('#{T\.(.+?)}#', inc, $str);
?>
Rep would be appreciated

Jay
__________________
Jay Shah
MyCoHost - User Mode Linux VPS (DP Review)() - No OpenVZ = No Overselling

Managed VPS's with cPanel/WHM, Fantastico, WHM Master Resellers & RVSkins!
Reply With Quote
  #6  
Old May 10th 2008, 5:19 pm
J.T.D. J.T.D. is offline
Grunt
 
Join Date: Feb 2008
Posts: 86
J.T.D. is on a distinguished road
Quote:
Originally Posted by hip_hop_x View Post
php Code:
preg_match("#{T\.([\S]+)}#i","{T.test} test {T.lawl}", $match);
/*
$match[1] is test
*/
That only shows test, and doesn't show more stuff, like lawl...

Quote:
Originally Posted by jayshah View Post
This works on PHP 5:

php Code:
<?php
function inc($match){
        include($match[1]);
}

$str = '{T.test} test {T.lawl}';

echo preg_replace_callback('#{T\.(.+?)}#', inc, $str);
?>
Rep would be appreciated

Jay
Thanks +Rep.

Thanks everyone!!

- JTD
Reply With Quote
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Preg_Replace help please. Barbacamanitu PHP 1 Mar 14th 2008 4:23 am
preg_replace Help hrock PHP 2 Jan 4th 2008 7:25 am
Need help with preg_replace please. Jak PHP 2 Apr 16th 2007 3:30 pm
Preg_replace cbkman Programming 5 Jan 29th 2007 4:21 pm
preg_replace help!!! yo-yo PHP 2 Jul 28th 2005 11:36 am


All times are GMT -8. The time now is 8:54 am.