Converting Text into Clickable Link – PHP

preg_replace - Searches $subject for matches to $pattern and replaces them with $replacement.
By using the above preg_replace function I have created a simple function which will first find urls inside text and convert all into clickable links
function convert_links($text)
{
 $text = preg_replace('#(script|about|applet|activex|chrome):#is', "\1:", $text);
 $ret = ' ' . $text;
 $ret = preg_replace("#(^|[n ])([w]+?://[w#$%&~/.-;:=,?@[]+]*)#is", "\1<a href="\2" target="_blank">\2</a>", $ret);
 $ret = preg_replace("#(^|[n ])((www|ftp).[w#$%&~/.-;:=,?@[]+]*)#is", "\1<a href="http://\2" target="_blank">\2</a>", $ret);
 $ret = preg_replace("#(^|[n ])([a-z0-9&-_.]+?)@([w-]+.([w-.]+.)*[w]+)#i", "\1<a href="mailto:\2@\3">\2@\3</a>", $ret);
 $ret = substr($ret, 1);
 preg_match_all("/<a href="(.+?)"/", $ret, $match);
 $result1 = array_unique($match);
 $count = count($result1[0]);
 if($count > 0)
 {
 foreach ($result1 as $val)
 {
 foreach ($val as $item)
 {
 $item = str_replace('<a href="', '', $item);
 $item = str_replace('"', '', $item);
 }
 }
 }
 return $ret;
}

Usage

echo convert_links('your text here');


Top 5 Free PHP & Mysql Cheat Sheets

The AddedBytes cheat sheet above covers multiple php topics such as functions list and regular expressions.
If you would rather not download a php cheat sheet, BlueShoes has provided an online php cheat sheet available for you to access at anytime.
Above you will find a helpful and quick online guide to basic and slightly complex MySQL commands.
If you’re looking for a full fledged MySQL cheat sheet, look no further. The cheat sheet above (again, by AddedBytes) contains MySQL native functions, php MySQL functions, MySQL data types, and MySQL sample queries.
The WikiBook MySQL Cheat Sheet is an open and member contributed online MySQL guide. It has the advantage of constantly being updated as the database languages evolves.

Validate IPv4 Address in PHP

Today I am going to tell how to validate IPv4 / IP address using PHP. Simple function which will used to check client IP address is valid or not.
Steps to validate IPv4 Address in PHP
  • Split IP address into segments  by dot(.)  using explode function
  • Make sure that there are 4 segments (eg : 192.168.1.45)
  • Make sure that IP cannot start with 0
  • IP segments must be digits & cannot be longer than 3 digits or greater than 255
function validate_ip($ip)
{
 //split ip address in to array by dot
 $ip_segments = explode('.', $ip);
 // Always 4 segments needed
 if (count($ip_segments) !== 4)
 {
  return FALSE;
 }
 // IP can not start with 0
 if ($ip_segments[0][0] == '0')
 {
  return FALSE;
 }
 // Check each segment
 foreach ($ip_segments as $segment)
 {
  // IP segments must be digits and can not be
  // longer than 3 digits or greater then 255
  if ($segment == '' OR preg_match("/[^0-9]/", $segment) OR $segment > 255 OR strlen($segment) > 3)
  {
   return FALSE;
  }
 }
 return TRUE;
}

//usuage
$ip = validate_ip("192.168.1.43");
if($ip)
{
  echo "Valid IP";
} else {
  echo "Invalid IP";
}


This function will return boolean true or false

Removing index.php from Codeigniter URL

If you are using Codeigniter you are noticed that by default index.php will be included with your URL.

But you can easily remove index.php from your CodeIgniter’s URL so that your URL should be like:

http://domain.com/about

To do this just follows the following steps:

Open config.php from system/application/config directory and replace

$config['index_page'] = “index.php” by $config['index_page'] = “”

Create a “.htaccess”file in the root of CodeIgniter directory (where the system directory resides), open the file using your favorite text editor, write down the following script and save it:

RewriteEngine on
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

In some case the default setting for uri_protocol does not work properly. To solve this problem just replace
$config['uri_protocol'] = “AUTO” by $config['uri_protocol'] = “REQUEST_URI” from system/application/config/config.php

use of $this->uri->segment(3) in codeigniter pagination


This provides you to retrieve information from your URI strings
$this->uri->segment(n); // n=1 for controller, n=2 for method, etc
it will return
$this->uri->segment(1); // controller
$this->uri->segment(2); // action
$this->uri->segment(3); // 1stsegment
$this->uri->segment(4); // 2ndsegment

pagination in codeigniter

view Code

 <?php
$i=1+$this->uri->segment(3);
if(is_array($displaydata))
{
foreach($displaydata as $db) {
?>

custom fileds...

 <?php $i++;  } } ?>

<?php if(empty($displaydata)) { ?>
            <tr>
            <td colspan="7" bgcolor="#F8F8F8">No Records Found .. .... ...</td>
            </tr>
            <?php }  ?>      
</table>  <?php echo $this->pagination->create_links();?></td>



controller code

public function certificatedata()
{
$displaydata = $this->mreminder->listcertificatedata('','') ;

$total_rows = count($displaydata) ;
$config['base_url'] =  base_url().'index.php/welcome/certificatedata/' ;
$config['per_page'] = 10 ;
$config['full_tag_open'] = '<div>' ;
$config['full_tag_close'] = '</div>' ;
$config['first_link'] = 'First' ;
$config['last_link'] = 'Last' ;
$config['use_page_numbers'] = FALSE ;
$config['prev_link'] = '&lt;';
$config['uri_segment'] = 3 ;
$config['num_links'] = 7 ;
$config['cur_tag_open'] = '<b>' ;
$config['cur_tag_close'] = '</b>' ;
$config['total_rows'] = $total_rows ;

$displaydata = $this->mreminder->listcertificatedata($config['per_page'], $this->uri->segment(3)) ;

$this->pagination->initialize($config);

$data = array(  
'displaydata' => $displaydata    
) ;

$this->load->view('certificatedata',$data);
}


Model COde

function listbillingdata($num, $offset)
{

if($offset!="")
{    
     $que = "select * from billingtbl where deleted=0  LIMIT ".$offset.", ".$num."";
}
else if($num!="")
{
  $que = "select * from billingtbl where deleted=0 LIMIT ".$num."" ;
}
else
   {
$que = "select * from billingtbl where deleted=0" ;
}


$query = $this->db->query($que) ;  
$results = $query->result_array() ;
return $results  ;
}


Collection of Important Dynamic Web Programming languages Ebooks

Hello Geeks! - you know i already have Collection of important Programming languages ebooks, but that is Software + Web App programming ebooks and after posting "How to become Web Programmer complete guide for beginners" many readers requested me to upload Dynamic Web Programming languges ebooks. In this post i've covered "AJAX, ASP.NET, Coldfusion, Perl, PHP, Ruby and Ruby on Rails Ebooks - Free giveaway.

Note : We've compressed Ebooks in ZIP format (99% Virus Free) Mediafire Download Links - Just Click on Ebook name & Download instantly. Thank you


I. AJAX (Asynchronous JavaScript and XML)



II. ASP (Advance Static Pages)



III. Coldfusion



IV. Perl



V. PHP (HyperText Preprocessor)

VI. Ruby


VII. Ruby on Rails



Thank you for reading my post, And if any link is broken feel free to comment and let me know your problem. You can also request any other Programming e-books (We'll upload it Asap!) If you like it please do a share to increase us.

How to become Web Programmer Guide for Beginners

Hello, Geeks! today m feeling little energetic and inspired so i thought to share little guide as per my experience and knowledge, well m not Professional Web Programmer - but here i got many tips, guides, tutorials to start learning Web programming language by Professional Programmers like my Sir (Teacher) in my Institute. From past couple of days I'm collecting information about How to start learning Web Programming language and it is totally for Beginners only.


How to start learning Web Programming Lang.

There are many types of Web Programming language being used by the Web Application but you've to start from the most basic Markup language and that is HTML commonly known as Hyper Text Markup language (HTML 5). HTML is very easy and interesting to learn, HTML is almost used by every Web Site & Web Application. After then move to  Dynamic Web Programming languages like JavaScript, AJAX, PHP, ASP etc. And the most  important thing I want to explain you that Programming just can't be learn by reading or  memorizing it - Programming is like body building the more you build the more you get  Stronger - (Hack w0rm). Try to create your own Web Page & App using  Dreamweaver, & test it in Local Host Server etc I'll elaborate more deeply in this Post.


First of all lemme explain you difference between Static & Dynamic Web Pages :

Static : Static pages are the generic .html files usually relegated to FAQs, contact information, Blog Articles etc. HTML is Static : Listen suppose you create an application that Says Hello World!, then anyone can able to see your code using Web Browser (Source Code) because you code is in .HTML and that is Static.

Dynamic : Dynamic Pages are really interesting and little protected, Nowadays almost every Web Site is using Dynamic Pages like (.asp, .jsp, .php, etc), You can't see the code of Dynamic Pages like you can see the code of .HTML. Usually all programmers use Dynamic Pages to generate Static Codes. For Example you create an application like search engine then you've to connect PHP/ASP page into action - well you can also use Static but it isn't like Dynamic. You can't simply see the code of .PHP action file.


Steps to get Started with Web Programming :

*Go through below stage and learn step by step :

1. HTML (Markup Language) : Folks! I want your base to be strong, If you know complete HTML 5 then it would be easy to learn another second stage Languages. HTML is Markup language which comes under Static Web Page. If you're beginner in Web Programming start with HTML.

2. CSS : Cascading Style Sheets is very easy Static Language. CSS is used for designing, fonts, lighting text, effects and whatever that makes your Web Site looks little attractive. CSS can be learnt in just 7 Days! Its pretty small and easy with lots of enjoyment. CSS only got a job of designing, Flash, Adding image effects, Font effects, Color, Application designing etc.

3. JavaScript : Commonly Javascript is used in every Web Sites, Javascript is Dynamic Web Programming language. If you're champ in HTML & CSS then it would be easy to learn Javascript easily. Javascript have an important role in Web Applications, Javascript is very intersting with lots of fun also.

4. AJAX : Now after completing Javascript move to most adorable programming language called AJAX : (Asynchronous JavaScript and XML) AJAX is a novel programming approach to web applications that creates the experience of “fat client” applications using lightweight JavaScript and XML technologies.

5. PHP/ASP : It's time to move on more advance Dynamic Web Programming language likes PHP or ASP. Both have an unbeatable competion but I'll recommend you to learn PHP. PHP (Hypertext Preprocessor) is very interesting dynamic  language. It isn't tough until you know HTML, Javascript etc. PHP is one my mine favorite Programming language.


Now, after learning 5 most important Web Programming languages : HTML, CSS, Javascript, AJAX, PHP. You can move to advance Web Programming languages like Ruby, Ruby on Rails, Visual Basic Web App Dev, C#, .NET, etc. But before doing all these advance please become champ in all that five Programming languages.

How to learn Web Programmnig Languages : (Methods to learn)

To learn Web Programming languages you'll require atleast 2 hour daily practice, refresh your skills everday and think how it works, what is the main conclusion. And go through below Guide to learn Programming easily.


The First Step : If you're going through my guide and learning that five programming languages sequencely then i'll recommend you to start with HTML. While learning HTML create one word file of all HTML Tags, with two line comments and defination of defined Tag. CSS doesn't have any heavy contents like Tag, scripts etc.. it's simply. JavaScript can give you little tough challenge, take your time to learn it slowly don't do rush and never skip any contents saying that i'll do it later, always try to challenge yourself with Programming. AJAX and PHP have coplicated contents, but if you learn sequencely and go on smoothly then it would be easy for you to learn PHP and AJAX.

Always take Tea/Coffee : While practicing and creating some Application with my own, sometimes my brain gets buzzed! that is why i always keep Coffee near to my Computer table. In programming you've to think and create it wisely, so you can impress yourself, public or your Boss/Teacher. But I'm not only recommending you to take Tea or Coffee only - Well mine some friends drink Mountain Dew, Red Bull etc. It will keep your mind cool and little fresh.

Download Dreamweaver CS6 : Adobe Dreamweaver CS6 is one the best Web Application Development Software commonly used by all Web Programmer.  Dreamweaver is easy to use with all types of Static, Dynamic web programming language. It will help you a lot to learn Web Programming and create Web App easily.


How Stuffs work : The main thing in programming is to think and understand how Web Application is working. While learning someguys just memorize Programming tags, scripts and codes , but when it comes to creating and facing an errors they just become BLANK!. Whenever you learn any programming language please always try to understand How it is working, and Visualize its structure & flow in your mind.

Web App Note : When I was pursuing my diploma they always tell us to keep a note of everything what you learn, In case you forget some programming codes or stucked into problem - your Note can remind you the solution. I m not saying to write all things whatever you learn, but just create atleast one note on Hard Stuffs.


How to test Programmed Web Page & Application ?

While learning HTML, JavaScript etc you'll need to test your Program wheather it is working correctly or not? - checking for any Error or Mistakes. So you'll need a Web Server to test Static and Dynamic Web Applications, Therefore i recommend you to download WAMP Server and Install it in your Computer, Start WAMP Server, Go to C:\wamp\www\ and paste your web page file in that folder, now open your browser and type localhost or 127.0.0.1 - Hit enter and you can access your Web Application on offline mode with all HTTP features.

From where Should I learn ?

This is the most common problem faced by learners, they don't get source to get started with simple example and tutorials, But I say if you've curiosity to learn and passion to do something then you can even learn just from an E-book. The best way to learn Programming is to Download E-books, Purchase Web Programming languages Books, Learn from W3Schools, Google your Queries, Try to understand How it works.

There are a lots of Ebooks on internet for Beginners to learn Web Programming languages. Click here to download some ebooks from our blog.


Web Programmers
              In this Era of Internet and technologies, Web Programmers are growing with lots of IT Skills, and Knowledge. well this is a tough Competion for guy like me and you who is interested in Hacking, Programming and other Computer Skills. As fast the IT (Information Technology) is growing the demand of Web Programmer, Computers Programmers are growing. Web Programming is one of the best future carrer option.

Other Tips to learn Web Programming Languages :

* Friends, Curiosity is the best way to learn anything
* Be Passionate and Confident while Learning
* Always test your Web Application in Local Server
* Learn from your mistakes, find an error and fix it
* Always use Google to clear your doubts.
* And always Stay connected with Bolt Geeks.


Thank you for reading my post, This is small guide by Vivek,I hope you enjoyed this post. Feel free to ask any doubt and lemme know your problem. If you liked it please share it to increase us.

Difference between stored procedures and user defined functions


2. Named Batches: Set of T-SQL statements can written and executed as a single unit with a proper name called Named batch. These includes

  1. Stored procedures
  2. User defined Functions
  3. Triggers

  1. Stored Procedures: Stored procedures are one of the database objects. There are two types of stored procedures available in SQL Server.

    1. System Defined Stored Procedures
    2. User Defined Stored Procedures

System Defined Stored Procedures: These are also known as predefined or built-in stored procedures.

E.g.: 
SP_HELP
SP_RENAMEDB
SP_RENAME
SP_HELPCONSTRAINT
SP_HELPTEXT
------
-----
-------

User Defined Stored Procedures: Procedures created by the user are called used defined stored procedures.

Syntax:
 CREATE PROC [EDURE] PROCEDURENAME
            [@PARA 1 DATATYPE (SIZE)[=DEFAULT_VALUE][OUTPUT]
            @PARA 2 DATATYPE (SIZE)[=DEFAULT_VALUE][VALUE],….]
AS
BEGIN
SELECT STATEMENT
END

Syntax to execute the user defined stored procedure:
EXEC [UTE] PROCEDURENAME [VALUE1,VALUE2,…]

Note: The number of values supplied through EXEC statement must be equal to the number parameters.



E.g.1: Write a procedure to select the data from EMP table.

CREATE PROCEDURE P1
AS
BEGIN
SELECT * FROM EMP
END

      EXEC P1

E.g.2: Write a procedure to select the data from EMP table based on user supplied DEPTNO.

CREATE PROCEDURE P2 @X INT
AS
BEGIN
SELECT * FROM EMP WHERE DEPTNO=@X
END

EXEC P2 20






E.g.3: Write a procedure to add two numbers

CREATE PROCEDURE P3 @A INT=10,@B INT=20
AS
BEGIN
DECLARE @C INT
SET @C=@A+@B
PRINT @C
END

EXEC P3
Output: 30
EXEC P3 25, 45
Output: 70

Note: Server will give highest priority to the user supplied values rather than default values.



USER DEFINED FUNCTIONS: Functions created by user are called user defined functions

Types of user defined functions:
1.      SCALAR VALUED FUNCTIONS
2.       TABLE VALUED FUNCTIONS

Scalar valued functions: These functions will return a scalar value to the calling environment
Syntax:
 CREATE FUNCTION < FUNCTION_NAME> (@PARA 1 DATA TYPE ,
@ PARA 2 DATATYPE ,…..)
RETURNS <DATATYPE>
AS
BEGIN
DECLARE  @VARIABLE  DATATYPE
--------
----------
RETURN  @VARIABLE
END

Syntax to execute the user defined function:
SELECT/PRINT DBO.FUNCTIONNAME (VALUE1,VALUE2,……….)

Note: The number of values supplied through PRINT/SELECT statement must be equal to the number parameters.


E.g.1: Write a function to find the product of two numbers

 CREATE FUNCTION F1 (@ A INT, @B INT)
 RETURNS INT
 AS
BEGIN
DECLARE @ C INT
SET @C = @A * @B
RETURN @C
END

SELECT/PRINT DBO.F1 (3,5)


E.g.2: Write function to find the net salary of an employee read  EMPNO though parameter and display the net to return value
 CREATE FUNCTION F2 (@ VNO INT)
            RETURNS  INT
            AS
BEGIN
            DECLARE @ VSAL INT, @VCOM INT, @NET INT
            SELECT @VSAL =  SAL, @VCOM=COM
FROM EMP WHERE EMPNO =@VNO
IF @ VCOM IS NULL
BEGIN
PRINT ‘COMMISION IS NULL’
SET @NET = @VSAL
END
ELSE
BEGIN
SET @ NET = @VSAL + @VCOM
END
RETURN (@NET)
END

PRINT/SELECT DBO.F2(22)








2) Table valued function: These functions will return entire table to the calling environment.

Syntax:
CREATE FUNCTION <FUNCTION_NAME>(PARA 1 DATA TYPE ……….)
RETURNS TABLE
AS
BEGIN
<FUNCTION BODY>
RETURN (SELECT STATEMENT)
END

E.g.1: Write a function to return entire dept table
CREATE FUNCTION F3()
RETURNS TABLE
AS
BEGIN
RETURN (SELECT * FROM DEPT)
END




SELECT * FROM F3()
DEPT
DNAME
LOC







E.g2:
CREATE FUNCTION F4()
RETURN TABLE
AS BEGIN
RETURN(SELECT ENAME, DNAME FROM EMP, DEPT
                      WHERE EMP.DEPTNO = DEPT.DEPTNO)
END
SELECT * FROM F4()
ENAME                                 DNAME
SMITH                        RESEARCH
MILLER                     ACCOUNTING

Creating jQuery Popup

Jquery popup is extremely popular effect for websites, as a web developer or designer we can apply this effects very easy in our projects, we can search and download, using third party jQuery plugins. If your wonder on how to create popup div in your own hand. In this article i would like to share, on how to create a pop up div, effect using the popular jQuery library.


In this jquery example / tutorial we create jquery popup div in ‘click trigger’ event, it pop up displays with opacity background and it will remains center the popup if you scrolling zoom out the browser and closing it fadeout, and also you can customize the content of the popup div. Let’s begin

1. Creating the Page Template

index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Creating Popup Div | istockphp.com</title>
<link href="style/style.css" rel="stylesheet" type="text/css" media="all" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"> </script>
<script type="text/javascript" src="js/script.js"></script>
</head>

<body>
 <a href="#" class="topopup">Click Here Trigger</a>

    <div id="toPopup">

        <div class="close"></div>
        <span class="ecs_tooltip">Press Esc to close <span class="arrow"></span></span>
  <div id="popup_content"> <!--your content start-->
            <p>netus et malesuada fames ac turpis egestas. </p>
            <p align="center"><a href="#" class="livebox">Click Here Trigger</a></p>
        </div> <!--your content end-->

    </div> <!--toPopup end-->

 <div class="loader"></div>
    <div id="backgroundPopup"></div>
</body>
</html>



In index.html, we include the css, jQuery and js script after the title tag; in the body we have 3 div containers for popup div event.

div container for loading
div container for popup background,
and div container for popup
2. The stylesheet

style.css

#backgroundPopup {
    z-index:1;
    position: fixed;
    display:none;
    height:100%;
    width:100%;
    background:#000000;
    top:0px;
    left:0px;
}
#toPopup {
    font-family: "lucida grande",tahoma,verdana,arial,sans-serif;
    background: none repeat scroll 0 0 #FFFFFF;
    border: 10px solid #ccc;
    border-radius: 3px 3px 3px 3px;
    color: #333333;
    display: none;
    font-size: 14px;
    left: 50%;
    margin-left: -402px;
    position: fixed;
    top: 20%;
    width: 800px;
    z-index: 2;
}
div.loader {
    background: url("../img/loading.gif") no-repeat scroll 0 0 transparent;
    height: 32px;
    width: 32px;
    display: none;
    z-index: 9999;
    top: 40%;
    left: 50%;
    position: absolute;
    margin-left: -10px;
}
div.close {
    background: url("../img/closebox.png") no-repeat scroll 0 0 transparent;
    cursor: pointer;
    height: 30px;
    position: absolute;
    right: -27px;
    top: -24px;
    width: 30px;
}
span.ecs_tooltip {
    background: none repeat scroll 0 0 #000000;
    border-radius: 2px 2px 2px 2px;
    color: #FFFFFF;
    display: none;
    font-size: 11px;
    height: 16px;
    opacity: 0.7;
    padding: 4px 3px 2px 5px;
    position: absolute;
    right: -62px;
    text-align: center;
    top: -51px;
    width: 93px;
}
span.arrow {
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 7px solid #000000;
    display: block;
    height: 1px;
    left: 40px;
    position: relative;
    top: 3px;
    width: 1px;
}
div#popup_content {
    margin: 4px 7px;
    /* remove this comment if you want scroll bar
    overflow-y:scroll;
    height:200px
    */
}




In the css, if you want scrollbar in the popup just remove comment in line 74.

3. The jQuery script

script.js

jQuery(function($) {

 $("a.topopup").click(function() {
   loading(); // loading
   setTimeout(function(){ // then show popup, deley in .5 second
    loadPopup(); // function show popup
   }, 500); // .5 second
 return false;
 });

 /* event for close the popup */
 $("div.close").hover(
     function() {
      $('span.ecs_tooltip').show();
     },
     function () {
         $('span.ecs_tooltip').hide();
       }
    );

 $("div.close").click(function() {
  disablePopup();  // function close pop up
 });

 $(this).keyup(function(event) {
  if (event.which == 27) { // 27 is 'Ecs' in the keyboard
   disablePopup();  // function close pop up
  }
 });

        $("div#backgroundPopup").click(function() {
  disablePopup();  // function close pop up
 });

 $('a.livebox').click(function() {
  alert('Hello World!');
 return false;
 });

  /************** start: functions. **************/
 function loading() {
  $("div.loader").show();
 }
 function closeloading() {
  $("div.loader").fadeOut('normal');
 }

 var popupStatus = 0; // set value

 function loadPopup() {
  if(popupStatus == 0) { // if value is 0, show popup
   closeloading(); // fadeout loading
   $("#toPopup").fadeIn(0500); // fadein popup div
   $("#backgroundPopup").css("opacity", "0.7"); // css opacity, supports IE7, IE8
   $("#backgroundPopup").fadeIn(0001);
   popupStatus = 1; // and set value to 1
  }
 }

 function disablePopup() {
  if(popupStatus == 1) { // if value is 1, close popup
   $("#toPopup").fadeOut("normal");
   $("#backgroundPopup").fadeOut("normal");
   popupStatus = 0;  // and set value to 0
  }
 }
 /************** end: functions. **************/
}); // jQuery End


In the click event we triggered the 'loading()' function and delay .5 second and triggered the loadPopup(), and same for close trigger, we add little more for closing the popup, if hover the ‘Close’ the tool tip message will triggered and keyboard event for close.

4. Done

Wer’e done, we learn one of jquery sample on creating our own popup div using jQuery, you can edit the content of the popup like adding text or form. Let’s have a look at what we’ve achieved:

We create popup div without third party plugin
Works in old IE browser, IE 7,8
We add little feature, hover tool tip and keyboard event
If you enjoyed this article, please consider sharing it!

How To create Widget In Wordpress

In this tutorial, we will create a simple widget that just greets visitors. Take a look at this code and then paste it in your site-specific plugin to see it in action.


// Creating the widget 
class wpb_widget extends WP_Widget {

function __construct() {
parent::__construct(
// Base ID of your widget
'wpb_widget', 

// Widget name will appear in UI
__('WPBeginner Widget', 'wpb_widget_domain'), 

// Widget description
array( 'description' => __( 'Sample widget based on WPBeginner Tutorial', 'wpb_widget_domain' ), ) 
);
}

// Creating widget front-end
// This is where the action happens
public function widget( $args, $instance ) {
$title = apply_filters( 'widget_title', $instance['title'] );
// before and after widget arguments are defined by themes
echo $args['before_widget'];
if ( ! empty( $title ) )
echo $args['before_title'] . $title . $args['after_title'];

// This is where you run the code and display the output
echo __( 'Hello, World!', 'wpb_widget_domain' );
echo $args['after_widget'];
}
  
// Widget Backend 
public function form( $instance ) {
if ( isset( $instance[ 'title' ] ) ) {
$title = $instance[ 'title' ];
}
else {
$title = __( 'New title', 'wpb_widget_domain' );
}
// Widget admin form
?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> 
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
</p>
<?php 
}
 
// Updating widget replacing old instances with new
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
return $instance;
}
} // Class wpb_widget ends here

// Register and load the widget
function wpb_load_widget() {
 register_widget( 'wpb_widget' );
}
add_action( 'widgets_init', 'wpb_load_widget' );

/*---------------------------------------------------------------*/

Now go to Appearance » Widgets, drag and drop WPBeginner Widget in your sidebar to see this custom widget in action.
Simple wasn’t it? First we created a custom widget. Then we defined what that widget does and how to display the widget back-end. Then we defined how to handle changes made to widget. Lastly, we registered and loaded the widget.


Import Gmail contacts using PHP


In this tutorial, we can import Gmail contacts using PHP.
Kindly follow below steps.


  <?php   error_reporting(E_ALL);   $user = "Your Gmail ID"; // Enter your gmail ID   $password = "Your Gmail Password"; // Enter your Gmail account password.       // ref: http://code.google.com/apis/accounts/docs/AuthForInstalledApps.html       // step 1: login   $login_url = "https://www.google.com/accounts/ClientLogin";   $fields = array(   'Email' => $user,   'Passwd' => $password,   'service' => 'cp', // <== contact list service code   'source' => 'test-google-contact-grabber',   'accountType' => 'GOOGLE',   );       $curl = curl_init();   curl_setopt($curl, CURLOPT_URL,$login_url);   curl_setopt($curl, CURLOPT_POST, 1);   curl_setopt($curl, CURLOPT_POSTFIELDS,$fields);   curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);   curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);   $result = curl_exec($curl);       $returns = array();       foreach (explode("\n",$result) as $line)   {   $line = trim($line);   if (!$line) continue;   list($k,$v) = explode("=",$line,2);       $returns[$k] = $v;   }       curl_close($curl);       // step 2: grab the contact list   $feed_url = "http://www.google.com/m8/feeds/contacts/$user/full?alt=json&max-results=250";       $header = array(   'Authorization: GoogleLogin auth=' . $returns['Auth'],   );       $curl = curl_init();   curl_setopt($curl, CURLOPT_URL, $feed_url);   curl_setopt($curl, CURLOPT_HTTPHEADER, $header);   curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);   curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);       $result = curl_exec($curl);   curl_close($curl);       $data = json_decode($result);       $contacts = array();       foreach ($data->feed->entry as $entry)   {   $contact = new stdClass();   $contact->title = $entry->title->{'$t'};   $contact->email = $entry->{'gd$email'}[0]->address;   $contacts[] = $contact;   }   echo "<pre>";   print_r($contacts);

PHP CLOSING TAG TIPS


The PHP closing tag?> ) on a PHP document is optional to the PHP parser. However, if used, any whitespace following the closing tag, whether introduced by the developer, user, or an FTP application, can cause unwanted output, PHP errors, or if the latter are suppressed, blank pages. I think you have faced this frustrating issues and had to waste your valuable time to debug. For this reason, all PHP files shouldOMIT the closing PHP tag, and instead use a comment block to mark the end of file and it’s location relative to the application root. This allows you to still identify a file as being complete and not truncated. Here is an example:
BAD PRACTICE:
1<?php 
2echo "Here's my code!"
3?>
GOOD PRACTICE:
1<?php 
2echo "Here's my code!";
Also, while using php code into html pages it is not recommended that you use php short form (<? ?>) because this may not support if it is configured in the php.ini. So, if you use this and found your application is not working and in the same time you can’t modify the php.ini then you have to change those which will kill lots of your time! So best is always use: