Loading...

Follow PHP CORE LAB on Feedspot

Continue with Google
Continue with Facebook
or

Valid

What is Palindrome?

Palindrome is a word, phrase, sentence, or number that reads the same from both backward or forward. If you reverse the string it is same as original string.

$myValue = 121;   // Define string madam,nitin ,1881,2002
        
        $myArray = array(); // define php array
        $myArray = str_split($myValue); //split the array
      
        $len = sizeof($myArray); // use php function to get size of array
        $newString = "";
        //reverse the value        
        for ($i = $len; $i >= 0; $i--) 
        {       
         $newString.=$myArray[$i];
        }
		
        //check if the string and reverse string is equal       
        if($myValue == $newString){
            echo $myValue." Yes! the value is Palindrome ";    
        }else{
            echo $myValue." Oops! the value is not a Palindrome! ";    
        }

Also We can use PHP inbult strrev() function to reverse the string and check.

The post Check Palindrome number or string in PHP appeared first on PHPCORELAB.

  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

$num= 20;   // It print all prime number till 20
for($j=2;$j<=$num;$j++ )
{
for($k=2;$k<$j;$k++ ) 
{
if($j%$k==0)
{
break;
}
}
if( $k == $j )
echo "Prime Number  : $j <br />";
}

The post Write a program to print Prime number appeared first on PHPCORELAB.

  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

$num = 6;  // Change to any number

for($i=1 ; $i<=10 ; $i++)
{
echo $i*$num;  // Multiply index to number
echo '<br>'; // For new line
}

The post Write a program to print table of any number appeared first on PHPCORELAB.

  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

To get hostname we use PHP inbuilt function parse_url.

$url = 'http://google.com/dhasjkdas/sadsdds/sdda/sdads.html';
$parse = parse_url($url);
print $parse['host']; // prints 'google.com

Parsing Domain From URL In PHP

This function is not used for validate the given URL, it only breaks it up into the above  parts.

The post How to get hostname from any url appeared first on PHPCORELAB.

  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

In windows system you can not create a file without name it not allow you to create a .env file directly from the windows explorer. However, we can create .env file from command line of PHP console using following –
Stpes to create .env file


Step 1:
Create anything.txt file in same folder
Step 2:
Choose any method
Method 1 – If you have installed php then run this command in console php -r “copy(‘anything.txt’, ‘.env’);”
Method 2 – Create a txt file called anything.txt open CMD and find its dir then run   ” ren anything.txt .env ”

You can create .htaccess file using same method.

The post Creating .env file in Windows system appeared first on PHPCORELAB.

  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

If we want to get youtube video ID from any youtube video URL
For this we need to parse youtube URL using PHP function

$url = ‘https://www.youtube.com/watch?v=RddUmlqghSY’;
parse_str( parse_url( $url, PHP_URL_QUERY ), $my_array_of_vars );
$youtubelink = $my_array_of_vars[‘v’];

// Output is RddUmlqghSY

The post How to get youtube video ID from youtube URL ? appeared first on PHPCORELAB.

  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

If we have table like below
Table structure
id name salary
1 Saurabh 20000
2 Arpit 15000
3 Navneet 17000
4 Harper 19500
5 Raghu 21000
6 Dyal 17000
7 Gopal 16000
8 Jaswant 15500
9 Santosh 20000
10 Venkata 21000

To get top 5 salaried employee from table we get DISTINCT salary and sub query

SELECT DISTINCT sal,emp FROM emp a WHERE 5 >= (SELECT COUNT(DISTINCT sal) FROM emp b WHERE b.sal >= a.sal) ORDER BY a.sal DESC

top

The post How to get top 5 salaried employee in mysql appeared first on PHPCORELAB.

  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

To enable DB query you need to add “use DB;” on top of the controller

If you want to count row in table you can use count in your query

$total = DB::table(‘tablename’)
->where(‘userid’, ‘=’, $userid)
->count();

If you want to count total data created in a monthe so you can use whereMonth and count in your query

$totalbymonth = DB::table(‘tablename’)
->where(‘userid’, ‘=’, $userid)
->whereMonth(‘created_at’, ‘=’, $currentmonth)
->count();

The post How to count row data in laravel appeared first on PHPCORELAB.

  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

MySQL:  update a field only if condition is true.Update a field only if condition is true in query

Using IF statement we can do this
For example :- If i want to update user level if user score is 500+
and if user join time in 24 hour

We can add multiple condtion in IF statement

UPDATE table SET level = IF(score > 500 AND  jointime (HOUR, jointime , ‘2018-06-27 16:27:54’) > 24 , USERNEWLEVEL , level) WHERE user_id = 5

The post MySQL: How to update a field only if condition is true appeared first on PHPCORELAB.

  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Separate tags by commas
To access this feature, please upgrade your account.
Start your free month
Free Preview