Replace only the outer tag if nested tag exists in a reg exp
Posted: Thu Dec 21, 2006 12:28 am
feyd | Please use
I need to replace only the outer tag pair [somecode] [/somecode] with <abc> </abc>
The result should look like:
If anyone have any idea, please help me to solve this.
Thanks in advance
Ashly
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi,
I am working with PHP 5.0 . I have a string like this:Code: Select all
[somecode]
function getSize($userIDArr)
{
$arrSize = sizeof($userIDArr);
}
[somecode]
function getUserNames($userIDArr)
{
for($i=0; $i < sizeof($userIDArr); ++$i)
{
$userNamesArr[$i] = $userIDArr[$i];
}
return $userNamesArr;
}
[/somecode]
[/somecode]I need to replace only the outer tag pair [somecode] [/somecode] with <abc> </abc>
The result should look like:
Code: Select all
<abc>
function getSize($userIDArr)
{
$arrSize = sizeof($userIDArr);
}
[somecode]
function getUserNames($userIDArr)
{
for($i=0; $i < sizeof($userIDArr); ++$i)
{
$userNamesArr[$i] = $userIDArr[$i];
}
return $userNamesArr;
}
[/somecode]
</abc>If anyone have any idea, please help me to solve this.
Thanks in advance
Ashly
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]