Q:

Use regex to find variables into string

I'm not able to find out some regex to match multiple php variables into a string
below is an example:
$var = "SELECT * FROM table WHERE admin='".$admin."' AND id=".$idclient." AND something=".$something;

so actually I need to match the whole query string and replace only variables with a function() with variables inside.
The final result that I need should looks like:
$var = "SELECT * FROM table WHERE admin='".functionname($admin)."' AND id=".functionname($idclient)." AND something=".functionname($something);

A:

If I don't misunderstood your requirements, then you can try like this with regex
<?php
$re = '/([$][a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+)/m';
$str = '"SELECT * FROM table WHERE admin=\'".$admin."\' AND id=".$idclient." AND something=".$something;';
$subst = 'functionname($1)';
$result = preg_replace($re, $subst, $str);
echo $result;
?>

REGEX: https://regex101.com/r/1Jg5FN/3
DEMO: https://3v4l.org/DXuMr

