How do I extract the values of variables from a string?
If you want to parse a string into the variables as though it were a query string, then you can do this easily using the parse_str function. Note that this can also accept an optional array for storing the variables in.
Here is a simple example that we could use if we always have the same form of string and just want to find out easily the values for each variable:
<?php
$str = "thisone=that &you=you are&they= confused&help= is certain";
parse_str($str);
echo $thisone;
echo $you;
echo $they;
echo $help;
//that you are confused is certain
?>
... and that's how to use the parse_str function.
Comment on this Question and Answer >>>
ASK A QUESTION
More strings PHP Questions
How do I count the number of words in my text?how to compare strings in PHP?
How do I break email address into username and hostname?
How do we count paragraphs or newlines?
How do I make the first letter of a string uppercase?
