SACHIN GAJBHIYE SACHIN GAJBHIYE - 5 months ago 16
JSON Question

file_get_content doesnt get my values for address field after space

Here is code of my PHP file:

$result = file_get_contents('http://localhost/service/service.php?action=register&name='.$name.'&lname='.$lname.'&email='.$email.'&username='.$username.'&password='.$password.'&gender='.$gender.'&mobile='.$mobile.'&address='.$address);

Answer

You have to encode your variables in order to create a valid URL.

Use the function urlencode().

$name = urlencode($name);
$lname = urlencode($lname);
$email = urlencode($email);
$username = urlencode($username);
$password = urlencode($password);
$gender = urlencode($gender);
$mobile = urlencode($mobile);
$address = urlencode($address);

$result = file_get_contents('http://localhost/service/service.php?action=register&name='.$name.'&lname='.$lname.'&email='.$email.'&username='.$username.'&password='.$password.'&gender='.$gender.'&mobile='.$mobile.'&address='.$address);
Comments