Posted inProgramming / Mysql / Mysqli / php

PHP String Email word-char limit timestamp Examples

PHP String Email word-char limit timestamp Examples

In this Post We Will Explain About is PHP String Email word-char limit timestamp Examples With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to PHP Best Practices: a short, practical guide for commonExample

In this post we will show you Best way to implement Top 10 Best Usage Examples of PHP Simple HTML DOM Parser, hear for advanced php programming exampleswith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

1. PHP – Validate Email Address check

function valid_email($live_address)
{
  return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $live_address)) ? FALSE : TRUE;
}

2. PHP Converts simple local Unix timestamp to GMT

function local_to_gmt($live_time = '')
{
  if ($live_time == '')
	  $live_time = time();

  return mktime( gmdate("H", $live_time), gmdate("i", $live_time), gmdate("s", $live_time), gmdate("m", $live_time), gmdate("d", $live_time), gmdate("Y", $live_time));
}

3. PHP (Encode PHP Tags)Convert PHP tags to entities

function encode_php_tags($live_string)
{
    return str_replace(array(''),  array('<?php', '<?PHP', '<?', '?>'), $live_string);
}

4. PHP Simple Check the String is Alpha

function live_checka_alpha($live_string)
{
   return ( ! preg_match("/^([a-z])+$/i", $live_string)) ? FALSE : TRUE;
}

5. PHP Check the Simple String is Alpha Numeric

function check_live_alpha_numeric($live_string)
{
   return ( ! preg_match("/^([a-z0-9])+$/i", $live_string)) ? FALSE : TRUE;
}

6. Word Limiter –PHP Limits a string to N number of words

function word_live_limiter($live_string, $limit = 100, $last_char = '…')
{
	if (trim($live_string) == '')
	{
	  return $live_string;
	}

	preg_match('/^\s*+(?:\S++\s*+){1,'.(int) $limit.'}/', $live_string, $matches);

	if (strlen($live_string) == strlen($matches[0]))
	{
	  $last_char = '';
	}

	return rtrim($matches[0]).$last_char;
}

7. PHP Character Limiter Example

function live_character_limiter($live_string, $max = 500, $last_char = '…')
{
	if (strlen($live_string) < $max)
	{
		return $live_string;
	}

	$live_string = preg_replace("/\s+/", ' ', str_replace(array("\r\n", "\r", "\n"), ' ', $live_string));

	if (strlen($live_string) <= $max)
	{
		return $live_string;
	}

	$response = "";
	foreach (explode(' ', trim($live_string)) as $val)
	{
		$response .= $val.' ';

		if (strlen($response) >= $max)
		{
			$response = trim($response);
			return (strlen($response) == strlen($live_string)) ? $response : $response.$last_char;
		}
	}
}

8. PHP Generate Random String

function GUID_randomstring($cat = 'alnum', $len = 8)
{
  switch($cat)
  {
	  case 'basic'	: return mt_rand();
		  break;
	  case 'alnum'	:
	  case 'numeric'	:
	  case 'nozero'	:
	  case 'alpha'	:

			  switch ($cat)
			  {
				  case 'alpha'	:	$live_pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
					  break;
				  case 'alnum'	:	$live_pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
					  break;
				  case 'numeric'	:	$live_pool = '0123456789';
					  break;
				  case 'nozero'	:	$live_pool = '123456789';
					  break;
			  }

			  $live_string = '';
			  for ($i=0; $i < $len; $i++)
			  {
				  $live_string .= substr($live_pool, mt_rand(0, strlen($live_pool) -1), 1);
			  }
			  return $live_string;
		  break;
	  case 'unique'	:
	  case 'md5'		:

				  return md5(uniqid(mt_rand()));
		  break;
  }
}

//run or Executes
echo GUID_randomstring('alnum', 16);

9. PHP : Simple Find Number of Days in a Month

function all_find_days_in_month($live_month = 0, $year = '')
{
  if ($live_month < 1 OR $live_month > 12)
  {
	  return 0;
  }

  if ( ! is_numeric($year) OR strlen($year) != 4)
  {
	  $year = date('Y');
  }

  if ($live_month == 2)
  {
	  if ($year % 400 == 0 OR ($year % 4 == 0 AND $year % 100 != 0))
	  {
		  return 29;
	  }
  }

  $live_days_in_month	= array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
  return $live_days_in_month[$live_month - 1];
}

//run or Executes
echo all_find_days_in_month(06, 2005);

10. Validate Multiple Email Addresses

function valid_emails($live_string)
{
		if (strpos($live_string, ',') === FALSE)
		{
			return valid_email(trim($live_string));
		}

		foreach (explode(',', $live_string) as $email)
		{
			if (trim($email) != '' && valid_email(trim($email)) === FALSE)
			{
				return FALSE;
			}
		}
	return TRUE;
}

Example

I hope you have Got What is Word Limiter –PHP Limits a string to N number of words And how it works.I would Like to have FeadBack From My Blog(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype