I have hundreds of variables with this structure:
$bsdatA = $_POST['bsdat_a'];
$bsdatB = $_POST['bsdat_b'];
…
The problem is that i have to add isset() function to every of it, like this:
$bsdatA = isset($_POST['bsdat_a']) ? $_POST['bsdat_a'] : '';
$bsdatB = isset($_POST['bsdat_b']) ? $_POST['bsdat_b'] : '';
…
This is a manual copy and paste on every single line… Can it be done via regular expression? If yes, can someone write me down the exact formula? It would save me lot of time.
Thank you very much.
I assume that you are trying to change the code using an IDE that supports Regex Replaces:
Here’s the regex for Eclipse:
Find:
\$(\w+) = \$_POST\['(\w+)'\]Replace:
$1 = isset(\$_POST['$2']) ? \$_POST['$2'] : '';