PHP - How to get phone carrier info from number - php

Are there any good, free ways to do this?
I found http://fonefinder.net, which looks okay. If that's my best best, how can I query it with a phone number and get the returned carrier? (I don't see an API).

Well, it looks like your query URL is as follows:
http://www.fonefinder.net/findome.php?npa={First Three}&nxx={Next Three}&thoublock={Last Four}
I would just get that page, use PHP's XML parser on the document. This should get you started:
<?php
$xmlDOC = simplexml_load_file(/* Your Request URL */);
print_r($xmlDOC->center->table[1]->tbody->tr[1]->td[4]->a->attributes());
?>

There is this website http://phonenumberprovider.com, for some reason it doesn't have a public API yet, but the developer told me that I can use this at the moment:
http://phonenumberprovider.com/api/json/+187605591648
Returns JSON like this:
{"result":"success","description":"Phone number provider found","operator":"JAMAICA","operatorPrefix":"1876","operatorCountry":"JM"}

Related

PHP Variables not passing to url correctly from API

I'm trying to use the Premium URL Shortener script from codecanyon, I have asked for support but they seem to be a little busy, so the response time is not to quick.
The issue I have is when the API sends the request to the url shortener script with the following shortened query for example purposes:
$short = "http://myurl/api?api=MYAPI&format=text&url=http://myfullwebsite.com/email/quote.php?fullname=$fullname&address=$address&emailaddress=$emailaddress";
Although the variables are being placed in the script correctly using echo function at the end of the script after the api request is sent shows they are correctly inserted like so:
http://myurl/api?api=MYAPI&format=text&url=http://myfullwebsite.com/email/quote.php?fullname=Dan Smith&address=12 Main Street, London&emailaddress=dan#smith.com
However if I click the shortened url provided to me from the script I only get the following url string appear in the browser:
http://myfullwebsite.com/email/quote.php?fullname=Dan
It seems as soon as there is a space or even if there is no second name such as Dan Smith and only Dan is the available name, it will not even apply the second ampersand or & sign.
I have tried to use urlecode() but still no joy and I've been pulling my hair out for the last 3 days!
As a novice beginner it has been somewhat difficult to try and achieve the end result and it seems unreachable so I would appreciate any kind help or advice if possible, Maybe I'm missing something so simple?
I've thought of having the url query build from an array of variables but as a novice I've tried one way and failed so not sure if I have done it wrong.
Here is my full api code where I have tried both with SESSION and GET but that is not the problem as the end result echos to the browser with the variables there.. it's only when you follow the shortened url link that you see they're missing.
<?php
session_start();
$fullname = htmlspecialchars($_GET["fullname"]);
$address = htmlspecialchars($_GET["address"]);
$postcode = htmlspecialchars($_GET["postcode"]);
$emailaddress = htmlspecialchars($_GET["emailaddress"]);
$short = "http://myurl/api?api=MYAPI&format=text&url=http://ukhomesurveys.co.uk/email/quote.php?fullname=$fullname&address=$address&emailaddress=$emailaddress";
echo $short;
// Using Plain Text Response
$api_url = $short;
$res= #file_get_contents($api_url);
if($res){
echo $res;
}
?>
Hope I covered everything and hope I have not confused anyone. Thanks.
I think the good choice here is to encode your query with base64 and then pass it to the shortener. In your http://myfullwebsite.com/email/quote.php you just decode the query and use it. The standart PHP functions are base64_encode and base64_decode.
Did you try to encode URI using rawurlencode?
$url = rawurlencode('http://myfullwebsite.com/email/quote.php?fullname=Dan Smith&address=12 Main Street, London&emailaddress=dan#smith.com');

splitting apart response from an API

I am trying to start using APIs, doing calls and so forth. Just barely starting to learn. Found a way to get Facebook shares on a post using the graph api.
I did this with PHP; here is the code:
$response = file_get_contents('https://graph.facebook.com/? id=mydomain.com');
echo $response;
this is the response that I get:
{"id":"http://sportsmockery.com/2014/11/hey-bears-fire-everyone/","shares":22}
What I want is to somehow get the share count (22) into a variable so I can do stuff with it…(i changed the domain that gets that share count to my domain.com);
anyway; I am not sure what is the standard way to do this, if you control what is received with how you do your call; or if you just get the full response and pull out what you want…
Been looking around and have not been able to find anything that will really help with this.
I am hoping someone can help me with this…
All the best, G
Use json_decode() which will make all of the properties easily accessible.
$parsedResponse = json_decode($response);
$count = $parsedResponse->shares;
echo $count;
This is a json response.
Parsing JSON file with PHP
http://php.net/manual/en/function.json-decode.php

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 i.e. $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");

Get "score" from JSON array

I got a response from the reddit API where the statistics from a link is made into a array. However, I can't figure out how to get the score-value from the response.
My current code:
http://pastebin.com/mH7udEKD
The response I get:
http://pastebin.com/N5smhxry
Should give you the score value:
$json_output['data']['children'][0]['data']['score']
it seems the only way to reach it is $json_result["data"]["children"][0]["data"]["score"].. are you sure this is the way to pull what you want from the API?
Just look at the response. Looks like this should do it:
$json_output['data']['children'][0]['data']['score']

using file get contents on a url that requires post data

i need to do a "file_get_contents" on a URL and there has to be data posted to the url before the contents are retrieved. is this possible? maybe something like
$contents = file_get_contents($_POST"http://www.example.com/");
so that i can then work with the $contents variable?
You cannot*** POST data using file_get_contents, you must use something like cURL
* I mark this because it is actually possible taking advantage of the third parameter which uses http context(see example one). However it really isn't worth your trouble if you have something like cURL.
Ah, I have tried to do this. Simply put you can't unless you install new extra software on your sever and go through A LOT of hassel and server load.
Best bet is to use GET if at all possible!
:)

Categories