PHP Questions Home

Categories

Arrays
Files
Forms
Functions
Images
MySQL
Numbers
Others
Strings
Website


PHP Functions

PHP Functions


More PHP

Top Questions
Ask a Question

How do I extract the values of variables from a string?


There are several ways you could do this.

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.



More strings PHP Questions

How do I remove space from the start of a PHP string?
How do I find the position of a letter in a string in PHP?
How do I check if a string contains HTML?
How do I convert characters to HTML entities using PHP?
How do I remove trailing whitespace from a string?