R
R
RaininoYT2020-05-28 21:37:40
PHP
RaininoYT, 2020-05-28 21:37:40

How to handle application/x-www-form-urlencoded data in PHP?

Hello! My PHP script receives application/x-www-form-urlencoded data from the server.
I need to check only some "fields" of all this data, namely
"key", "pr1", "pr2", "pr3"
and push the values these fields into the corresponding variables $key, $pr1, $pr2, $pr3.
Can you suggest a solution and give an example code? Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikolay Panaitov, 2020-05-28
@Picknice

Все зависит от того как приходят данные, они могут быть в переменной $_REQUEST или их нужно достать из JSON контента с помощью file_get_contents("php://input").
Допустим они в $_REQUEST,
$key, $pr1, $pr2, $pr3;
$keys = array( "key", "pr1", "pr2", "pr3" );
foreach( $_REQUEST as $k => $v ){
if( in_array( $k, $keys ) ){
$$k = $v;
}
}
// Тут можешь для проверки вывести
echo $key . '<br>';
echo $pr1 . '<br>';
echo $pr2 . '<br>';
echo $pr3 . '<br>';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question