View Single Post
  #6 (permalink)  
Old December 14th, 2004, 06:33 AM
SiliconFuRy SiliconFuRy is offline
Authorized User
 
Join Date: Oct 2004
Location: Edinburgh, Scotland, United Kingdom.
Posts: 84
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to SiliconFuRy
Default

Ah, cunning, nice one Snib. I do believe that works faster than the regex stuff... had to modify the functions bit from your examples, but heres how it works, using parse_Str....

<?php
$str = "name=james love\nage=20\nface=cake\nshoes=happy";
$matches = Array();
$str = str_replace("\n","&",$str);
$str = str_replace(" ", "+",$str);

parse_Str($str,$matches);

//print_r($matches);

$allowed_vars = Array("name","age","face");

foreach($matches as $k=>$v) {
        if(!in_array($k,$allowed_vars)) {
            echo "Variable name: " . $k .
            " not allowed, skipping...\n";
            continue;
        }
        $$k = $matches[$k];
}

echo "name: " . $name;
echo "\n age: : " . $age;
echo "\n face: " . $face;

?>

Many shoes,

Jamez/SiliconFuRy
Reply With Quote