<?php $fileData = '$orange="100kg";$Apple="400kg";$Peach="543kg";'; $patternVars = '/(?<=\$).*?(?=\=)/m'; $patternValues = '/(?<="(?!;)).*?(?=")/m'; $vars = preg_match_all($patternVars, $fileData, $varMatches); // Match all variables $values = preg_match_all($patternValues, $fileData, $valueMatches); // Match all values forEach($varMatches[0] as $key => $value){ // Use the value to name your variable (hence the weird looking "$$") and set the value of this variable to the matches of your values. $$value = $valueMatches[0][$key]; } var_dump($orange); // Will output "100kg"
You have javascript disabled. You will not be able to edit any code.
Value for `_results` contains invalid data `array`