Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I would like to update some PHP code into the Joomla framework, replacing things like:

$myvar=$_POST["myvar"];

with

$myvar=JRequest::getVar('myvar');

This seems like it should be easy enough but I can't get it to work. How do I do that?

share|improve this question
1  
It's not clear what you want. The normal search/replace function doesn`t work for you? Do you want to batch-edit multiple files at once? –  slhck Aug 31 '11 at 20:42
    
Yes, many files with $_POST and $_GET needing to be replaced, and $_SESSION too. –  Don Aug 31 '11 at 20:47
    
Normal search lets me replace the $_POST[" then I have to carefully do the "] - usually miss one or two. –  Don Aug 31 '11 at 20:48
1  
What I have found: find: \$_POST["([\w\s]+)"]; replace: JRequest::getVar('\1',''); //$_POST["\1"]; The original code is preserved at the end of the line and rem'd out –  Don Aug 31 '11 at 21:48
1  
Don, looks like you found your own answer :-). If you post it below as an answer, you can accept it (two days from now) and get this question marked as answered :-) –  Jonas Heidelberg Aug 31 '11 at 22:33
show 2 more comments

1 Answer

Search for

$_POST\["([^"]+)"\]

and replace with

JRequest::getVar('\1')

\["([^"]+)"\] To match the square brackets literally, they need to be escaped using a backslash.

[^"] means every character, but not a ".

([^"]+) the round brackets put the found stuff into a capturing group, this could then be retrieved with \1 (used in the replacement)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.