kalyan02 Posted May 9, 2007 Share Posted May 9, 2007 i would like to convert $teststring = "SESSION[logged=admin]&(GET[id=23]|VAR[page=admin]|POST[pageid!=23])"; into something like this using regex.. "$_SESSION[logged]==admin and ( $_GET[id]==23 or $page=='admin' or $_POST[pageid]!=23 )"; please let me know how to do this....as i am not able to figure it out any help regarding this is appreciated Quote Link to comment Share on other sites More sharing options...
MadTechie Posted May 9, 2007 Share Posted May 9, 2007 probably like this $test = "SESSION[logged='admin']&(GET[id=23]|VAR[page='admin']|POST[pageid!=23])"; $result = preg_replace('/(SESSION|GET|POST)/i', '$_$1', $test); Quote Link to comment Share on other sites More sharing options...
obsidian Posted May 9, 2007 Share Posted May 9, 2007 probably like this $result = preg_replace('/(SESSION|GET|POST)/i', '$_$1', $subject); There's a little more to it than that, though, because of the comparison differences, too. Quote Link to comment Share on other sites More sharing options...
kalyan02 Posted May 9, 2007 Author Share Posted May 9, 2007 but you expression only adds the '$' sign Quote Link to comment Share on other sites More sharing options...
obsidian Posted May 9, 2007 Share Posted May 9, 2007 Try this, but it may still need some work: <?php $string = "SESSION[logged='admin']&(GET[id=23]|VAR[page='admin']|POST[pageid!=23])"; $pattern = array( '/(SESSION|GET|POST)\[([^=!\s]+)\s*([=!]+)\s*([^]]+)\]/i', '/VAR\[([^=!\s]+)\s*([=!]+)\s*([^]]+)\]/i', '/\s(\=)\s/', '/([&|]{1})/'); $replace = array( '\$_$1[$2] $3 $4', '\$$1 $2 $3', ' == ', ' $1$1 '); echo preg_replace($pattern, $replace, $string); ?> Hope this helps. Quote Link to comment Share on other sites More sharing options...
kalyan02 Posted May 9, 2007 Author Share Posted May 9, 2007 it works perfectly thanks a lot Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.