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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.