简体   繁体   中英

Get Request to an API url

I have signed up to a synonym API.. see the details on this page

I am having trouble implementing this in my php code.

If I copy and paste the link into the web browser, I can see the results no problem.

Instead of typing the word in manually, I wish to have a variable in the link with the relevant word ie $variable_with_word_stored as shown below.

    http://words.bighugelabs.com/api/2/xxxxxxxx/$variable_with_word_stored/php 

    //format could be php (I would unserialize)..or json..I could decode it?

Any ideas guys? Thanks.

It sounds like you mean you want the result from calling that webpage and store it in a variable. What you should be looking to do is sending a http get request to that page within the code.

Check out using curl with php, you can send a http request to your requested url, capture the result back and parse it through json_decode

http://php.net/manual/en/curl.examples-basic.php

try it like this, maybe that you dont need curl:

$key = "xxxxxxxx";
$word = "love";

echo file_get_contents("http://words.bighugelabs.com/api/2/$key/$word/php");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM