PHP Questions Home | Register | Login
Categories
Arrays
Files
Forms
Creating PDFs
PHP Errors
Functions
Images
MySQL
Numbers
Others
Strings
Website
Unanswered

PHP Forums
Forums Index
MySQL Forum
PHP Forum
Flash/Actionscript
Javascript
Web design

More PHP
PHP Functions
Top Questions
Ask a Question
PHP Interview Questions
PHP Jobs
Ecommerce
IT Questions
Business Websites

Sponsors

sponsor ad
My Salary
PHP Developer Salary
Advertise Here

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.



Comment on this Question and Answer >>>

ASK A QUESTION

More strings PHP Questions

What is the usage of { } in string handling in php?

How do I calculate the metaphone of a string?

How do I make the first letter of each word upper case?

print(1 . " + " . 2 . " = " . 1+2 . "n"); gives answer 3 why?

How do you check if a variable is set or not in PHP?



Custom Search