Category: PHP

  • what is the difference between $a and $aa?

    $a=’hello’; $$a = ‘php’; $$$a=’world’; echo “$a ${$a} ${${$a}}”; Output : ==>hello php world   More Information : http://www.php.net/manual/en/language.variables.variable.php

  • How to read html table tag in php?

    <?php // new dom object $dom = new DOMDocument(); //load the html $html = $dom->loadHTMLFile(“test.html”); //discard white space $dom->preserveWhiteSpace = false; //the table by its tag name $tables = $dom->getElementsByTagName(‘table’); //get all rows from the table $rows = $tables->item(0)->getElementsByTagName(‘tr’); // loop over the table rows foreach ($rows as $row) { // get each column by…

  • how to create multiple domain session?

    config.php (http://admin.abc.com/config.php) ————————————————————————————————- session_set_cookie_params(0,’/’,’.abc.com’); session_start(); $_SESSION[‘darshak’]=’darshak’; ======================================================= session.php (http://admin.abc.com/session.php) ———————————————————————————————— session_set_cookie_params(0,’/’,’.abc.com’); session_start(); echo $_SESSION[‘darshak’]; =============================================================== session.php (http://www.abc.com/session.php) ———————————————————————————————— session_set_cookie_params(0,’/’,’.abc.com’); session_start(); echo $_SESSION[‘darshak’]; ===============================================================   Refer Link : http://php.net/manual/en/function.session-set-cookie-params.php

  • how to working with two database in php/mysql?

    //connection file //tested in php 5.3.5 & mysql 5.5.8 //make sure database username & database host are same at same place… $host=”localhost”; $dbnm=’db1′; $dbunm=’root’; $dbpass=”; $conn=mysql_connect($host,$dbunm,$dbpass); $db=mysql_select_db($dbnm,$conn); //==================================================================// $host_=”localhost”; $dbnm_=’db2′; $dbunm_=’root’; $dbpass_=”; $conn_=mysql_connect($host_,$dbunm_,$dbpass_); mysql_select_db($dbnm_,$conn_) or die(mysql_error()); //==============   Example  =============================// $sql=”select * from db1.test”; $re=mysql_query($sql) or die(mysql_error()); $sql_=”select * from db2.test”; $re_=mysql_query($sql_); //join query between two database’s tables….…

  • how to get xml CDATA content and write in csv format in php?

    <!–?php $url = ‘http://calendar.forex-tsd.com/calendar.php?xml=1&calendar[]=4’; //get file content but not display in browser because xml content some <![CDATA[ CDATA – (Unparsed) Character Data $test = file_get_contents($url); //so we replace replace with @#$ and store into $arr array variable. $arr=explode(‘@#$’,str_replace(‘]]>’,”,str_replace(‘<![CDATA[‘,’@#$’,$test))); $str[]=”; //we open or create a file.csv file. $fp = fopen(‘file.csv’, ‘w’); //we write a data in…

  • how to Change browser url without page reloading with ajax request using JavaScript, HTML5 history API, jQuery, PHP like Facebook, Github navigation menu?

    Consider a page that has the following links to three menu items and a div to display the ajax content. <div id=”menu”>  <a href=”m1.php” rel=”tab”>menu1</a> |  <a href=”m2.php” rel=”tab”>menu2</a> |  <a href=”m3.php” rel=”tab”>menu3</a> </div> To override the default action for the link(anchor tag), use the following jQuery code snippet. $(function(){   $(“a[rel=’tab’]”).click(function(e){     //code for the link…

  • How to create robots.txt file?

    Robots.txt is a text (not html) file you put on your site to tell search robots which pages you would like them not to visit. Robots.txt is by no means mandatory for search engines but generally search engines obey what they are asked not to do. It is important to clarify that robots.txt is not…

  • how to set default timezone in php?

    <?php date_default_timezone_set(‘Europe/London’); echo date(‘Y-m-d H:i:s’); ?>

  • how to fetch all supported timezones in PHP?

    <?php $timezone_offsets = array(); foreach(timezone_identifiers_list() as $timezone_identifier) { $date_time_zone = new DateTimeZone($timezone_identifier); $date_time = new DateTime(‘now’, $date_time_zone); $timezone_offsets[$timezone_identifier] = $date_time_zone->getOffset($date_time); } echo “<pre>”; print_r($timezone_offsets); ?>

  • how to refresh particular div tag content without reloading page using jquery?

    // Note : First include jquery.js file….. <script type=”text/javascript”> var auto_refresh = setInterval( function () { $(‘#load_div’).load(‘load.php’).fadeIn(“slow”); }, 100000); // refresh every 10000 milliseconds </script> //index.php <div id=”load_div”> </div> //load.php In this page you can write your code. like load randam user,image etc….