解析する文字列:
$str = "
public $xxxx123;
private $_priv ;
$xxx = 'test';
private $arr_123 = array();
"; // | |
// ^^^^^^^---- get the variable name
私がこれまでに得たもの:
$str = preg_match_all('/\$\S+(;|[[:space:]])/', $str, $matches);
foreach ($matches[0] as $match) {
$match = str_replace('$', '', $match);
$match = str_replace(';', '', $match);
}
それは機能しますが、 preg を改善できるかどうか知りたいです。たとえば、2つを取り除き、str_replace
おそらくに\t
含める(;|[[:space:]])