Calculate age from date of birth in php | Age calculator code in PHP

So many time we need to calculate user age from date of birth of the user. Here I'm giving an example code in PHP. I have written a function getAge() and you just need to pass the date of birth of the user in a given format. You will get the age of the user.

 

Share This:


Php highlight multiple keywords in text

If you have search something on web and you got a long then how will you highlight your search text here is the answer of this. I have written a PHP program to highlight the multiple keywords in text.

I'm just iterating the whole text and finds the match keyword to be highlighting.

 

Share This:


Dynamically load data on div scroll using php, mysql, jquery and ajax

If you have lots of data and displaying the whole data in one time is very costly. There comes to approach one is lazy loading and another is pagination.

Here we are going to discuss the lazy loading in PHP, MySQL and Ajax. In lazy loading user can keep scrolling and keep getting the data until the whole data completes. Just like we quora and facebook do, User keep scrolling and post keep coming.

Mysql QueryClick here to download demo code

db.php

index.php

posts.php

 

Share This:


Dependent dropdown example in PHP, MySQL

dependent_dropdownIf you wanted to change the another select box value on the change of the first select box, Here is the answer of your question.

I'm writing an article on dependent select box in PHP, MySQL and Ajax. If you change the first drop down value then second drop down options will get change according to first drop down.

Here I'm explaining an example of dependent select box like if you change the country name 'India' then in second select box India's States will be populated and so on.



 ...  Read More

Share This:


Create random strings in php

Often we need to create random strings in PHP. Like sometime if we are uploading an image then we rename that image and create some random string and put that string as image name.

Another example if we wanted to cerate a token then many times we need to create random string.

How to do that?

Here is code which creates random strings. I have written three functions to create the random string. So you can create three types of random string here.

  1. randomStringAlpha() : Creates random string of alpha bates.
  2. randomStringNum() : Creates random string of numbers.
  3. randomAlphaNumString() : Creates random string of alpha bates and numbers.

You also can define the length of the random string by changing the $length variable.

  ...  Read More

Share This:


Google Cloud Messaging (GCM) in Android using PHP

If you are developing you so many time need a PHP code to send the push notification on android devices. Learn here how to send push notification in PHP to an android device.

Before sending the push we need Google API key for validation. You can generate the Google API key from your Google account.

You also need an array of device tokens of android devices for you wanted to send the push notifications.

 

Share This:


iOS Push Notifications in PHP

While developing web services you may need PHP code to send push notifications on IOS devices. Here is the PHP code to send IOS push notifications.

To send the push notifications we need 2 things from Apple:

  1. pem file
  2. Passphrase

Remember pem file is different for development and production.

Now if you have device token of ios device token also please try the below code, It will send the push notification to the IOS device.

 

Share This:


Send message to XMPP group in php

Here we have created the chat room in XMPP using PHP and Here we have defined how to join a chant room in XMPP.

Now I'm going to explain how to send a message into a chat room in XMPP.

 

Share This:


XMPP create room in php

If you wanted to send a message to a number of people you can do it with XMPP. Yes, Here I'm going to explain how you can create the chat room on XMPP ejabbered server in PHP.

 

Share This:


Send message to XMPP server in php

If you are creating any chat application or wanted to send real time messages or data you simplest possible solution is XMPP. Here I'm writing the for sending the messages on XMPP server in PHP. I'm using ejabbered server here. so both sender and receiver have to register themselves over the ejabbered server before sending the messages to each other. Here is the code to register the user on ejabbered XMPP server.

Here is the PHP code to send the messages.

 

Share This: