prova così:

$text = preg_replace("/\$variabile = '(.*)';/i", "\$variabile = '$str';",$text);