Skip to main content

Posts

Showing posts from April, 2016

Write a PHP script to count lines in a file.

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Count File</title> </head> <body> <p>Count File</p> <p>Count File</p> <p>Count File</p> <p>Count File</p> </body> </html> <?php $file =basename($_SERVER['PHP_SELF']); $no_of_lines =count(file($file)); echo $no_of_lines; ?> Output:
Write a PHP script to print current PHP version <?php echo 'Current PHP version : ' . phpversion(); ?>  Write a PHP script to redirect a user to a different page . <?php header('Location:http://www.google.com'); ?> Write a PHP script to get last modified information of a file. <?php $file_last_modified = filemtime(basename($_SERVER['PHP_SELF']));    echo "Last modified " . date("l, dS F, Y, h:ia", $file_last_modified);   ?>

Write a PHP script, which change the color of first character of a word.

Write a PHP script, which change the color of first character of a word. <?php   $text = 'PHP Tutorial';   $text = preg_replace('/(\b[a-z])/i','<span style="color:red;">\1</span>',$text);   echo $text;   ?>  

Write a PHP script, which will return the following components of the url 'http://localhost/ex/php/8.php'.

Write a PHP script, which will return the following components of the url 'http://localhost/ex/php/8.php'. <?php $url1 ='http://www.w3resource.com/php-exercises/php-basic-exercises.php';   $url = 'http://localhost/ex/php/8.php';   $url=parse_url($url);   echo "<pre>"; print_r($url); echo 'Scheme : '.$url['scheme'].'<br />';   echo 'Host : '.$url['host'].'<br />';   echo 'Path : '.$url['path'].'<br />';   ?>

Write a simple PHP browser detection script.

Write a simple PHP browser detection script. <?php echo $_SERVER['HTTP_USER_AGENT']; $browser = get_browser(); echo "<pre>"; print_r($browser); ?>

Write a PHP script to get the client IP address.

Write a PHP script to get the client IP address. <?php   //whether ip is from share internet   if (!empty($_SERVER['HTTP_CLIENT_IP']))        {       $ip_address = $_SERVER['HTTP_CLIENT_IP'];     }   //whether ip is from proxy   elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))       {       $ip_address = $_SERVER['HTTP_X_FORWARDED_FOR'];     }   //whether ip is from remote address   else     {       $ip_address = $_SERVER['REMOTE_ADDR'];     }   echo $ip_address;   ?>  

Create a simple HTML form and accept the user name and display the name through PHP echo statement.

Create a simple HTML form and accept the user name and display the name through PHP echo statement. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Post Data</title> </head> <body> <form method="POST" action=""> <label>Enter First Name</label> <input type="text" name="firstname" id="firstname" /> <input type="submit" name="submit_button" value="Submit Name" /> </form> </body> </html> <?php if(isset($_POST) && !empty($_POST)) { echo "<h3> Hello ".$_POST['firstname']."</h3>"; } ?> Output:

$var = 'PHP Tutorial'. Put this variable into the title section, h3 tag and as an anchor text within a HTML document.

$var = 'PHP Tutorial'. Put this variable into the title section, h3 tag and as an anchor text within a HTML document.  <?php echo "<html>"; echo "<head>"; echo "<title>"; echo "PHP TUTORIAl"; echo "</title>"; echo "<body>"; echo "<h3>PHP TUTORIAL</h3>"; echo "<hr>"; echo "<p>PHP, an acronym for Hypertext Preprocessor, is a widely-used open source general-purpose scripting language. It is a cross-platform, HTML embedded server-side scripting language and is especially suited for web development.</p>"; echo "</body>"; echo "</head>"; echo "</html>"; ?> Output:

Generate Sprial matrix In Php

Generate Sprial matrix In Php <html> <head> <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.3.min.js"></script>     <script> $(document).ready(function (){     spiralArray = function (edge) {     var arr = Array(edge),         x = 0, y = edge,         total = edge * edge--,         dx = 1, dy = 0,         i = 0, j = 0;     while (y) arr[--y] = [];     while (i < total) {         arr[y][x] = i++;         x += dx; y += dy;         if (++j == edge) {             if (dy < 0) {x++; y++; edge -= 2}             j = dx; dx = -dy; dy = j; j = 0;        }     }     return arr; } // T E S T: arr = spiralArray(edge = 5); for (y= 0; y < edge; y++) {     console.log(arr[y].join(" ")); }     }); </script> </head> <body> <p></p> </body> </html>

Find a Pinpoint on map using Google Map url

Find a Pinpoint on map using Google Map url  <?php $email  = 'https://www.google.co.in/maps/place/Tour+Eiffel,+5+Avenue+Anatole+France,+75007+Paris,+France/@48.8582641,2.2923184,17z/data=!3m1!4b1!4m2!3m1!1s0x47e66fe1f3bfb4ad:0x7bd31375becf28cd'; if(isset($_POST['get_location'])) { $email = $_POST['location_url']; } $domain = strstr($email, '@'); echo $domain;  echo "<br/>"; echo "<br/>"; echo strpbrk($domain, '@'); echo "<br/>"; $keywords = preg_split("/[\s,@]+/", $domain); extract($keywords); echo $keywords[0] ; echo "<br/>"; echo $keywords[1] ; echo "<br/>"; echo $keywords[2]; echo "<br/>"; $zoom = $keywords[3]; echo $zoom; echo "<br/>"; $zoomlevel = substr($zoom, 0, -1); echo $zoomlevel; ?> <!DOCTYPE html> <html> <head> <s

Find a Pinpoint Using Address In Php

Find a Pinpoint On Map Using Address In Php <!DOCTYPE html> <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <script src="http://jashkenas.github.com/coffee-script/extras/coffee-script.js"></script> <meta charset=utf-8 /> <title>Welcome to JS Bin</title> <meta name="viewport" content="width=device-width"> <link href='http://fonts.googleapis.com/css?family=Doppio+One' rel='stylesheet' type='text/css'> <script> $(document).ready(function(){   var src =$("address").text();  /*$("#map").attr("src","https://www.google.co.in/maps/place/NCrypted+Technologies/@22.280131,70.799031,15z/data=!4m2!3m1!1s0x0:0xb5f28739a2446f67?sa=X&ved=0CHkQ_BIwC2oVChMIh6f12bLuxgIVBiaUCh2Bjggs");  */ $("address").each(function(){                      

Remove Multiple Character From string

Remove Multiple word From a string in comma separated String. <?php function removeFromString($str, $item) {     $parts = explode(',', $str);     while(($i = array_search($item, $parts)) !== false) {         unset($parts[$i]);     }     return implode(',', $parts); } $arra ="one,two"; $string ='one,two,three,four'; $array =explode(",",$arra); foreach($array as $key=>$value) { $string= removeFromString($string, $value); } echo $string; ?> OutPut: three,four