I would like make a script that automatically insert in a Array the Google+ ID's fetched from
the SocialGraphs Api but i can't understand the type of this result,here's the example of the result: http://pastebin.com/wfBAtjH7
If can be help,i've seen the method for isolate the ID's done in Javascript:
var oids = [];
var reobg = new RegExp("\\d{21}","g"); // only interested in user ID so prepare regexp
oids = resp.match(reobg); // get an array of ids
if (!oids == null){ // if something stringify it
oids = oids.join(",");
}
For get in a variable all the text,i've used this code:
$gplus = file_get_contents('https://plus.google.com/u/0/_/socialgraph/lookup/visible/?o=[null,null,"103227580967788703328"]&rt=j');
Where 103227580967788703328 is an example Google Plus ID.
Thanks in advance.
Kind Regards.
Luca.
Try and cycle through the input with this regex:
\[\[,,"(\d+)"\]
and grab the first group each time.
Try this \[(.*),(.*),"(.*)"\] this is may help U.
Related
I'm really stuck and would appreciate any advice. I have an XML document I want to be able to read but I can't get it to work with either Jquery or PHP. I have read multiple pages on online and tried everything including JSON encoding. I have read nearly a hundred tutorials online but everything I do doesn't seem to work. Is anybody able to write a script that can enable me to use some of the nodes in my document? The code below is the best I have been able to do so far. Is anybody able to make it so I can loop through the nodes etc?
To the person who marked this as a duplicate I have tried to look at those questions but I can't access the URL. I therefore can't compare the nodes/etc to see what I am doing wrong. I would really appreciate some help as I am quite new to this.
Thanks in advance for your help
<?php
$url = "https://developerdemo.isams.cloud/api/batch/1.0/xml.ashx?
apiKey=0A1C996B-8E74-4388-A3C4-8DA1E40ADA57";
$xml = simplexml_load_file($url);
$myJSON = json_encode($xml);
?>
<script>
var name='<?php echo $myJSON; ?>';
$.each(name, function(key, value) {
alert( "The key is '" + key + "' and the value is '" + value + "'" );
});
</script>
Once you have the code you already have it's simply a case of working with the XML structure, the following example loads the XML and then gives a list of the pupils (with a few details)...
$url = "https://developerdemo.isams.cloud/api/batch/1.0/xml.ashx?apiKey=0A1C996B-8E74-4388-A3C4-8DA1E40ADA57";
$xml = simplexml_load_file($url);
foreach ( $xml->PupilManager->CurrentPupils->Pupil as $pupil) {
echo $pupil['Id']." ".$pupil->SchoolCode." ".$pupil->Surname.PHP_EOL;
}
The id it puts out is the Id attribute of the Pupil element, the SchoolCode is the SchoolCode element in the Pupil.
The first few lines of output are...
1 101314800 Richards
3 PRE0000003SUF Thomas
5 PRE0000005SUF Davies
7 PRE0000007SUF Poole
What you can do is:
header('Content-Type: text/plain');
$resultArray = file_get_contents('path/to/file.xml');
$resultArray = (array)simplexml_load_string($resultArray);
The result will be an array of XML Objects and arrays, which you can access later via their property name or index respectively ($resultArray["foo"]->foo).
I'm trying to get all of the notes from a particular evernote notebook. I am able to display all of the data as an array, and I'm trying to use a foreach loop to get the title. I also want to be able to get the content, date, etc.
$filter = new NoteFilter();
$filter->notebookGuid = $notebookGuid;
$notelist = $client->getNoteStore()->findNotes($authToken, $filter, 0, 100);
foreach($notelist as $value) {
echo $value->title;
}
I know that I'm being really stupid, but I'm new to php and evernote. Any help is appreciated!
The return value of NoteStore.findNotes is NoteList which is not a collection. You have to get notes attribute from NoteList and then iterate it.
By the way, findNotes is now deprecated so please use findNotesMetadata.
You might want to check the following example from evernote:
https://github.com/evernote/evernote-sdk-php/blob/master/sample/client/EDAMTest.php
i am looking for some help to find the distance between two address through php
as i can not use the google maps api. so get a way from this post
Distance between two addresses
but i need to know how can send the request using URL pattern
and grab the repose to save them in database.
http://maps.google.com/maps/api/directions/xml?origin=550+Madison+Avenue,+New+York,+NY,+United+States&destination=881+7th+Avenue,+New+York,+NY,+United+States&sensor=false
thanks for any suggestion.
///////////////
After these answers i am there
$customer_address_url = urlencode($customer_address);
$merchant_address_url = urlencode($merchant_address);
$map_url = "http://maps.google.com/maps/api/directions/xml?origin=".$merchant_address_url."&destination=".$customer_address_url."&sensor=false";
$response_xml_data = file_get_contents($map_url);
$data = simplexml_load_string($response_xml_data);
XML response is visible when i put this url : http://maps.google.com/maps/api/directions/xml?origin=Quentin+Road+Brooklyn%2C+New+York%2C+11234+United+States&destination=550+Madison+Avenue+New+York%2C+New+York%2C+10001+United+States&sensor=false
but can not printing through
echo "<pre>"; print_r($data); exit;
You can try this..
$url = "http://maps.google.com/maps/api/directions/xml?origin=550+Madison+Avenue,+New+York,+NY,+United+States&destination=881+7th+Avenue,+New+York,+NY,+United+States&sensor=false";
$data = file_get_contents($url);
Now $data contains resulting xml data. You can parse this xml data using..
http://php.net/manual/simplexml.examples.php
use the haversine formula
Also check https://developers.google.com/maps/documentation/distancematrix/
Ok so what i want to be able to do is to perform a suggestive style search using the contents of an array instead of a doing a mySQL database query on every keyup.
So imagine a javascript object or array that is full of people's names:
var array = (jack,tom,john,sarah,barry,...etc);
I want to then query the contents of this array based on what the user has typed into the input box so far. So if they have typed 'j',both jack and john will be pulled out of the array.
I know this is possible via php mysql and ajax calls, but for reason of optimization I would like to be able to query the js array instead.
Hope someone can help me with this!
W.
as the name suggests, this finds elements of an array starting with the given string s.
Array.prototype.findElementsStartingWith = function(s) {
var r = [];
for(var i = 0; i < this.length; i++)
if(this[i].toString().indexOf(s) === 0)
r.push(this[i]);
return r;
}
// example
a = ["foo", "bar", "fooba", "quu", "foooba"];
console.log(a.findElementsStartingWith("fo"))
the rest is basically the same as in ajax-based scripts.
http://wwwo.google.com?q=autosuggest+using+javascript
AJAX calls fetch the contents from another serverside script files. You already have your data in the JS. Read a AJAX tutorial doing this. Then, just remove the parts where AJAX calls are made and replace it with your array's contents, and you're good to go.
I ended up using the following function to build my AJAX free instant search bar:
Example JS object being searched:
var $members = {
"123":{firstname:"wilson", lastname:"page", email:"wilpage#blueyonder.co.uk"},
"124":{firstname:"jamie", lastname:"wright", email:"jamie#blueyonder.co.uk"}
}
Example of function to search JS object:
$membersTab.find('.searchWrap input').keyup(function(){
var $term = $(this).val(),
$faces = $membersTab.find('.member'),
$matches = [];
if($term.length > 0){
$faces.hide();
$.each($members,function(uID,details){
$.each(details,function(detail,value){
if(value.indexOf($term) === 0){//if string matches term and starts at the first character
$faces.filter('[uID='+uID+']').show();
}
});
});
}else{
$faces.show();
}
});
It shows and hides users in a list if they partially match the entered search term.
Hope this helps someone out as I was clueless as to how to do this at first!
W.
I'm trying to access the individual member-fields of a JSON object in PHP from a JSON string but I can't to access the inner-json, all I get is Array.
This is the JSON string
data = (
{
"created_time" = "2018-10-07T04:42:39+0000";
id = 1069496473131329;
name = "NAME_0";
},
{
"created_time" = "2018-09-09T10:31:50+0000";
id = 955684974605664;
name = "NAME_1";
},
At the moment my code is:
$nameString = $_POST["nameData"];
$nameJsonString = json_encode($nameString, JSON_FORCE_OBJECT);
$jsonNameObj = json_decode($nameJsonString, true);
I've been trying to access the individual entry with:
$element = $jsonNameObj['data'][0];
But only receive Array.
Any help would be greatly appreciated,
Cheers :)
After checking the inputted JSON data, I've realised that it doesn't have a consistent form. As opposed to the overall structure being:
JSON -> List -> JSON
Instead, it's:
JSON -> List
The list contains individual elements that can be in a different order. Consequently, calling:
$element = $jsonNameObj['data'][0]['created_time'];
Works sometimes. As there are three-values/object, I can congregate these values into a trio.
I'm sure there's a way to condense this list into a fixed-JSON format but I'm not familiar with how I'd go about that.
At the moment, with a bit of logic on the back-end, I can retrieve the values.
Thanks for your help #Difster and #Osama!