Monday, July 8, 2013

Get value of inside of "![CDATA" In PHP

If you have XML File and in this file data was stored like this.
"
<tourlist>
<item>
<tourName>
<![CDATA[Milano Card]]>
</tourName>
<tourCity>
<![CDATA[Milan]]>
</tourCity>
<tourCountry>
<![CDATA[Italy]]>
</tourCountry>
<highlights>
<![CDATA[Get all that you need at Milan and discover the heart of Europe from culture art entertainment and cuisine. Choose the service that you want and use your Milano Card for perks and discounts. Get to use public transportation for free for 3 days and gain free access to selected museums!]]>
</highlights>
</item>
</tourlist>
"
And if you want to get this data using PHP script  then execute this code. 

<?php 

  $doc = new DOMDocument();
  $doc->load('http://' . $_SERVER['HTTP_HOST'] . '/citytoursxmlfiles/city.xml' );
   $destinations = $doc->getElementsByTagName("item");
   $simpleXml = array();
   foreach ($destinations as $destination) {
            $simpleXml[] = $destination->nodeValue;
     }
      echo json_encode($simpleXml); 

?>

Get Latitude and Longitude with CIty,State,Country and Postal code of Given address

<html>
<title>Get Current Location</title>
<head>
<script language="JavaScript" type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script language="JavaScript" type="text/javascript" src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
<script language="JavaScript" type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=geometry"></script>
<script type="text/javascript">
 jQuery(function() {
var geocoder = new google.maps.Geocoder();
var add_r="Ahmedabad,India";
     geocoder.geocode( { 'address': add_r}, function(results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    var latitude = results[0].geometry.location.lat();
                    var longitude = results[0].geometry.location.lng();
jQuery('#latitude').text(latitude);
                    jQuery('#longitude').text(longitude);
                    jQuery('#content1').text(results[0].formatted_address);
                    jQuery('#city').text(results[0].address_components[1].long_name);
                    jQuery('#state').text(results[0].address_components[2].long_name);
                    jQuery('#country').text(results[0].address_components[3].long_name);
                    jQuery('#postalcode').text(results[0].address_components[4].long_name);
                } 
            });
});
</script>
<head>
<body>
    <div>
          <div>
                  Latitude =<b id="latitude"></b>
           </div>
   <div>
                  Longitude =<b id="longitude"></b>
           </div>
          <div>
                  City   =<b id="city"></b>
          </div>
 <div>
                  State   =<b id="state"></b>
          </div>
 <div>
                  Country   =<b id="country"></b>
          </div>
          <div>
                  Postal Code   =<b id="postalcode"></b>
          </div>
 <div>
                  Address   =<b id="content1"></b>
          </div>
 
    </div>
</body>
</html>

Get Current City's Temperature using Jquery

<html>
<title>Get Current Location</title>
<head>
<script language="JavaScript" type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script language="JavaScript" type="text/javascript" src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
<script language="JavaScript" type="text/javascript" src="http://j.maxmind.com/app/geoip.js"></script>
<script language="JavaScript" type="text/javascript" src="/js/jquery.simpleWeather-2.2.min.js"></script>
<script type="text/javascript">
 jQuery(function() {
     jQuery.simpleWeather({
                zipcode: '',
                woeid: '2357536',
                location: geoip_city(),
                unit: 'f',
                success: function(weather) {
                        jQuery('.container .location-temp').css('background','url('+weather.thumbnail+') no-repeat 0 2px');
                        jQuery('.container .location-temp').css('padding','5px 0px 0 53px');
                        jQuery('.container .location-temp').html(weather.tempAlt+'&deg;C');
                },
                error: function(error) {
                        jQuery("#weather").html('<p>'+error+'</p>');
                }
        });
});
</script>
<head>
<body>
<div>Get Current City's Temperature Please download "jquery.simpleWeather-2.2.min.js"</div>
    <div class="container">
          <div id="weather">
                  Temperature  : <b class="location-temp"></b>
           </div>
         
    </div>
</body>
</html>

Timer using Jquery

<html>
 <head>
<title>Get Current Location</title>
     <script language="JavaScript" type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script language="JavaScript" type="text/javascript" src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
<script type="text/javascript">
jQuery( document ).ready(function() {    
setInterval(function() {       
offset = '+2';       
d = new Date(jQuery.now());        
utc = d.getTime() + (d.getTimezoneOffset() * 60000);          
nd = new Date(utc + (3600000*offset));       
var currentMinutes = nd.getMinutes ( );       
var currentHours = nd.getHours ( );    
var currentSeconds = nd.getSeconds ( );       
currentHours = ( currentHours < 10 ? "0" : "" ) + currentHours;    currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes; 
currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds;
jQuery('.location-time').text(currentHours+":"+currentMinutes+":"+currentSeconds);    }, 1000);});
</script>
<head>
<body> 
<div>It is display "Italy" Time if you want chnage time accroding to your country so please change offset value as per your country.</div>    
<div>   Current Time = <b class="location-time"></b>    </div>
</body>
</html>    

Get current location using API

<html>
<title>Get Current Location</title>
<head>
<script language="JavaScript" type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script language="JavaScript" type="text/javascript" src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
<script language="JavaScript" type="text/javascript" src="http://j.maxmind.com/app/geoip.js"></script>
<script type="text/javascript">
 jQuery(function() {
     jQuery('#country_code').text(geoip_country_code());
     jQuery('#country_name').text(geoip_country_name());
     jQuery('#city').text(geoip_city());
     jQuery('#region_code').text(geoip_region());
     jQuery('#region_name').text(geoip_region_name());
     jQuery('#latitude').text(geoip_latitude());
     jQuery('#longitude').text(geoip_longitude());
});
</script>
<head>
<body>
    <div>
          <div>
                  Country Code=<b id="country_code"></b>
           </div>
         <div>
                  Country Name=<b id="country_name"></b>
           </div>
          <div>
                  City= <b id="city"></b>
           </div>
          <div>
                  Region Code=<b id="region_code"></b>
           </div>
           <div>
                  Region Name:<b id="region_name"></b>
           </div>
          <div>
                  Current Latitude=<b id="latitude"></b>
           </div>
           <div>
                  Current Longitude=<b id="longitude"></b>
           </div>

    </div>
</body>
</html>

Display popup before closing the window or refreshing the page.

<html>
 <head>
  <script src="http://code.jquery.com/jquery-latest.min.js"></script>
  <script type="text/javascript">
   window.onbeforeunload = function() {
    return "You're leaving the site.";
   };
   $(document).ready(function() {
    $('a[rel!=ext]').click(function() { window.onbeforeunload = null; });
    $('form').submit(function() { window.onbeforeunload = null; });
   });
  </script>
  <form name="firstsite">
   <input type="submit" name="submit" value="submit">
  </form>
 </head>
</html>