Tuesday, May 22

Very Simple way to find a given string is Palindrome or NOT.


Hi All,
Here  i have added the simple way to find a Palindrome using String Function.


<?php


// Palindrome using String function


$str = "1441";


$str1 = "12521";


$str2 = "MALAYALAM";


$str3 = "Game";


$strrev = strrev($str2);
if($str2 === $strrev){
echo $strrev ." is Palindrome"."</br>";
}else{
echo $str2. " Not a Palindrome"."</br>";
}


$strrev1 = strrev($str1);
if($str1 === $strrev1){
echo $strrev1 ." is Palindrome"."</br>";
}else{
echo $str1. " Not a Palindrome"."</br>";
}


$strrev2 = strrev($str);
if($str === $strrev2){
echo $strrev2 ." is Palindrome"."</br>";
}else{
echo $str. " Not a Palindrome"."</br>";
}


$strrev3 = strrev($str3);
if($str3 === $strrev3){
echo $strrev3." is Palindrome"."</br>";
}else{
echo $str3. " Not a Palindrome"."</br>";
}


?>


OUTPUT:
MALAYALAM is Palindrome
12521 is Palindrome
1441 is Palindrome

Game Not a Palindrome

PHP String Functions

STRING FUNCTIONS

Hi All,

I have added few important string functions. I hope it help you to understand and remember the string functions in PHP.

<?php

$str = "Welcome to Techie Snacks";
$str1 = "here you can find all the technical solutions across the platform";
$str2 = "\t\t New Era begins\t\t";

$email = "xxxx@gmail.com";


/*
  strtoupper
All characters of the String have Converted into UPPERCASE
Syntax: strtoupper($string);
*/


$upper = strtoupper($str);
echo $upper."</br>";


/*
strtolower
All characters of the String have Converted into LOWERCASE
Syntax: strtolower($string);
*/


$lower = strtolower($str);
echo $lower."</br>";


/*
ucfirst
First character of the word have Converted into UPPERCASE
Syntax: ucfirst($string);
*/


$ucupper = ucfirst($str1);
echo $ucupper."</br>";


/*
lcfirst
First character of the word have Converted into LOWERCASE
Syntax: lcfirst($string);
*/


$lcupper = lcfirst($str);
echo $lcupper."</br>";


/*
ucwords
First character of every word in UPPERCASE and all other characters remains unchanged.
Syntax: ucwords($string);
*/


$lcupper = ucwords($str1);
echo $lcupper."</br>";


/*
strlen
Returns and integer value representing the length of string.
It calculates the length of the string including all the whitespace and special characters.
Syntax: strlen($string)
*/


$strlength = strlen($str1);
echo $strlength."</br>";


/*
ltrim
Strip whitespace (or other characters) from the BEGINNING of a string
Syntax: string ltrim ( string $str [, string $character_mask ] );
*/


$ltrimmed = ltrim($str2,"\t");
echo $ltrimmed."</br>";


/*
trim
Strip whitespace (or other characters) from the BEGINNING and END of a string
Syntax: string trim ( string $str [, string $character_mask = " \t\n\r\0\x0B" ] );
*/


$trimmed = trim($str2, "e");
echo $trimmed."</br>";

/* strrev
Reverse a string
Syntax: strrev (string $string);
*/


$reverse = strrev($str);
echo $reverse."</br>";

/* strpos
Find the position of the first occurrence of a substring in a string
Syntax: int strpos ( string $haystack , mixed $needle [, int $offset = 0 ] );
*/
$find   = 'a';
$strpos = strpos($str, $find);
echo $strpos."</br>";


/* strstr
Find the first occurrence of a string
Syntax: string strstr ( string $haystack , mixed $needle [, bool $before_needle = FALSE ] );
*/
$domain_name = strstr($email, '@');
echo $domain_name."</br>";


/* stristr
Find the first occurrence of a string using insensitive
Syntax: string strstr ( string $haystack , mixed $needle [, bool $before_needle = FALSE ] );
*/
$domain_name = stristr($str1, 'H');
echo $domain_name."</br>";

?>

OUTPUT:
WELCOME TO TECHIE SNACKS
welcome to techie snacks
Here you can find all the technical solutions across the platform
welcome to Techie Snacks
Here You Can Find All The Technical Solutions Across The Platform
65
New Era begins
New Era begins
skcanS eihceT ot emocleW
20
@gmail.com

here you can find all the technical solutions across the platform

Friday, May 18

Object-Oriented Programming Concepts in PHP – Interface

Interface

Interfaces are defined in the same way as a class, but with the interface keyword replacing the class keyword and without any of the methods having their contents defined.
All methods declared in an interface must be public; this is the nature of an interface.
Interfaces allow you to create code which specifies which all methods a class must implement.
Note that it is possible to declare a constructor in an interface.

Implements

  • To implement an interface, the implements operator is used.
  • All methods in the interface must be implemented within a class; failure to do so will result in a fatal error.
  • Classes may implement more than one interface if desired by separating each interface with a comma.
  • Interfaces can be extended like classes using the extends operator.
  • The class implementing the interface must use the exact same method signatures as are defined in the interface. Not doing so will result in a fatal error.

Example:

<?php
// Declare the interface 'myImplement'
interface myImplement
{
public function setVariable($name, $val);
public function getVariable($tempdata);
}
// Implement the interface
class temp implements myImplement
{
private $vars = array();
 // Implementing the SetVatiable  Method
public function setVariable($name, $val)
{
       $this->vars[$name] = $name;
       $this->vars[$val] = $val;
}
 // implementing the GetVariable Method
public function getVariable($tempdata)
   {
       foreach($this->vars as $name => $value) {
        $tempdata = str_replace('{' . $name . '}', $value, $tempdata);
    }
//return the result
    return $tempdata;
}
}
// Instance creation ( object)
$objTemp = new temp();
// set the values to setvariable method
$rest=$objTemp -> setVariable('bala','Welcome');
$rest=$objTemp -> setVariable('balaa','Welcome1');
$rest=$objTemp -> setVariable('bala1','Welcome2');
$rest=$objTemp -> setVariable('bala2','Welcome3');
// get the value from getvariable method
$objTemp -> getVariable($rest);
echo "<pre>";
print_r($objTemp);
?>


OUTPUT:

temp Object
(
   [vars:temp:private] => Array
       (
           [bala] => bala
           [Welcome] => Welcome
           [balaa] => balaa
           [Welcome1] => Welcome1
           [bala1] => bala1
           [Welcome2] => Welcome2
           [bala2] => bala2
           [Welcome3] => Welcome3
       )

)

Backup files to google drive using PHP coding

 Dear All, To backup files to Google Drive using PHP coding, you can use the Google Drive API and the Google Client Library for PHP. Here...