Question

I coded this script and when I search for a user it shows

string(30) "result=2014-01-30 12:18:03&b=r"

the result=000000000 0000000&b=r is part of the api I'm using but the string(30) isn't and it outputs that too, how do I remove the string(30) and would I be able to replace the result text with something I choose?

Here's my script, you search a username and it outputs their last logged on date.

<html>
<h2> ----- </h2>
<?php
    if (!empty($_GET['userID'])) { //First check
        $url = 'http://api-testing.agame.com/php/getLastLog.php';
        $data = array('userID' => $_GET['userID']); //Then use the value

        // use key 'http' even if you send the request to https://...
        $options = array(
            'http' => array(
                'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
                'method'  => 'POST',
                'content' => http_build_query($data),
            ),
        );
        $context  = stream_context_create($options);
        $result = file_get_contents($url, false, $context);

        var_dump($result);
    }
?>

<form action='' method='get'>
    <input type='text' name='userID' />
    <input type='submit' value='Search' />
</form>
</html>

No correct solution

OTHER TIPS

look at var_dump() it is used for check the value and type of php variables(debugging purpose).

You have correct data in this line :

$result = file_get_contents($url, false, $context);

so just remove this line :

var_dump($result);

Use parse_str():

$result = file_get_contents($url, false, $context);
parse_str($result);
echo $result; // 2014-01-30 12:18:03

or

$result = file_get_contents($url, false, $context);
parse_str($result, $output);
echo $output['result']; // 2014-01-30 12:18:03
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top