Beste sitedealers
heb al heel wat geprobeerd maar tevergeefs.
Ik wil dus alles van de output in een aparte variabele hebben zitten.
OUTPUT:
ip2locationlite.class.phpCode:statusCode : OK statusMessage : ipAddress : 81.242.167.124 countryCode : BE countryName : BELGIUM regionName : BRUSSELS HOOFDSTEDELIJK GEWEST cityName : BRUSSELS zipCode : - latitude : 50.8463 longitude : 4.35473 timeZone : +01:00
index.phpPHP Code:
<?php
final class ip2location_lite{
protected $errors = array();
protected $service = 'api.ipinfodb.com';
protected $version = 'v3';
protected $apiKey = '';
public function __construct(){}
public function __destruct(){}
public function setKey($key){
if(!empty($key)) $this->apiKey = $key;
}
public function getError(){
return implode("\n", $this->errors);
}
public function getCountry($host){
return $this->getResult($host, 'ip-country');
}
public function getCity($host){
return $this->getResult($host, 'ip-city');
}
private function getResult($host, $name){
$ip = @gethostbyname($host);
if(preg_match('/^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:[.](?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}$/', $ip)){
$xml = @file_get_contents('http://' . $this->service . '/' . $this->version . '/' . $name . '/?key=' . $this->apiKey . '&ip=' . $ip . '&format=xml');
try{
$response = @new SimpleXMLElement($xml);
foreach($response as $field=>$value){
$result[(string)$field] = (string)$value;
}
return $result;
}
catch(Exception $e){
$this->errors[] = $e->getMessage();
return;
}
}
$this->errors[] = '"' . $host . '" is not a valid IP address or hostname.';
return;
}
}
?>
PHP Code:
<?
include('ip2locationlite.class.php');
//Load the class
$ipLite = new ip2location_lite;
$ipLite->setKey('7e9597004d1fa88bbba9f1e8e25fce0423b44b403907376dbed124d321d52c3b');
//Get errors and locations
$locations = $ipLite->getCity($_SERVER['REMOTE_ADDR']);
$errors = $ipLite->getError();
?>
<table width="100%" border="0">
<tr>
<? if (!empty($locations) && is_array($locations)) {
foreach ($locations as $field => $val) {
echo '<tr>';
echo '<td>' .$field . ' : </td>';
echo '<td>' . $val . '</td>';
echo '</tr>';
}
}
?>
</tr>
</tr>
</table>
- php alles in een variabele
-
23-04-2011, 17:01 #1
- Berichten
- 1.025
- Lid sinds
- 14 Jaar
php alles in een aparte variabele
Laatst aangepast door Danny vs : 23-04-2011 om 17:08
-
23-04-2011, 17:12 #2
- Berichten
- 1.899
- Lid sinds
- 18 Jaar
Re: php alles in een variabele
Als dat een textstring is kun je hem exploden op "\n" (newline) en daarna elk result op ":" en daar een key/value pair van maken toch? Maar aan je code te zien is het een XML return?
-
23-04-2011, 23:30 #3
- Berichten
- 1.025
- Lid sinds
- 14 Jaar
Re: php alles in een variabele
Iemand die mij nog kan helpen
-
24-04-2011, 01:03 #4
- Berichten
- 756
- Lid sinds
- 16 Jaar
Re: php alles in een variabele
Zo te zien heb je elk veld al "appart" in de array $locations
PHP Code:<?php
echo $locations['statusCode'];
echo $locations['ipAddress'];
?>
PHP Code:<?php
$sLocations = "";
foreach ($locations as $sField => $sVal) {
$sLocations .= $sField.":".$sVal."\n";
}
echo $sLocations;
?>
-
24-04-2011, 10:16 #5
- Berichten
- 1.025
- Lid sinds
- 14 Jaar
Re: php alles in een variabele
Bedankt het werkt, maar nu nog 1 iets
Dit heb ik nu
Code:$BezoekerLand = ucfirst($locations['countryName']);
ik moet enkel de eerste letter in een hoofdletter
-
24-04-2011, 10:49 #6
- Berichten
- 756
- Lid sinds
- 16 Jaar
Re: php alles in een variabele
PHP Code:$BezoekerLand = ucfirst(strtolower($locations['countryName']));
-
24-04-2011, 10:54 #7
- Berichten
- 1.025
- Lid sinds
- 14 Jaar
Re: php alles in een variabele
Helemaal bedankt voor alles
Alles werkt
Plaats een
- + Advertentie
- + Onderwerp
Marktplaats
Webmasterforum
- Websites algemeen
- Sitechecks
- Marketing
- Domeinen algemeen
- Waardebepaling
- CMS
- Wordpress
- Joomla
- Magento
- Google algemeen
- SEO
- Analytics
- Adsense
- Adwords
- HTML / XHTML
- CSS
- Programmeren
- PHP
- Javascript
- JQuery
- MySQL
- Ondernemen algemeen
- Belastingen
- Juridisch
- Grafisch ontwerp
- Hosting Algemeen
- Hardware Info
- Offtopic