Jump to content

how to convert into php format using Regex


kalyan02

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.