PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
elecktricity
Forum Contributor
Posts: 128 Joined: Sun Sep 25, 2005 8:57 pm
Location: Trapped in my own little world.
Contact:
Post
by elecktricity » Thu May 25, 2006 12:36 pm
Code: Select all
$str = 'hello [i=55] this work?';
$str = preg_replace ('/\[i=(.*?)\]/is', workstuff($1), $str);
workstuff is a function I need $1 to go in but it wont work, probally isnt supported, there another way of going about this?
TheMoose
Forum Contributor
Posts: 351 Joined: Tue May 23, 2006 10:42 am
Post
by TheMoose » Thu May 25, 2006 12:47 pm
You have to find all the matches first and work off each one in a loop, such as:
Code: Select all
$str = 'hello [i=55] this work?';
preg_match_all('/\[i=(.*?)\]/is', $str, $matches);
foreach ($matches[1] as $find) {
$str = preg_replace ('/\[i=' . $find . '\]/is', workstuff($find), $str);
}
timvw
DevNet Master
Posts: 4897 Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium
Post
by timvw » Thu May 25, 2006 1:30 pm