Welcome to W3Courses
 Like Us on Facebook

Programming

Pass Array from Multipart/Form-data Post Method or Query String with Foreach Function in PHP

You can have your form build an array of mutiple text box values and then pass it. The problem is that is global variables are on, it will work but if global variables are off you will have to retrieve each element like the following. If you are using the query string, replace $_Post with $_Get

<?php

echo("<form name='multiupload' enctype='multipart/form-data' method='post' action='{$_SERVER['PHP_SELF']}'>");

Share

Use in_array function to check if a value exists in an array using PHP

You can use in_array function to check if a value exists in an array:

For example:

<?php

$myname = "David";

$names = array("Paul","Maria","David","Lucy","Ana");

if (in_array($myname, $names))
       echo("Welcome $myname");
else
      echo "Sorry, that is not a valid name";

?>
 

Share

Loop through an Array using Foreach Function in PHP

You can loop through an array using foreach function. So instead of using:

<?php

$names = array("Paul","Maria","David","Lucy","Ana");

$i=0
while($names[$i] == true)
{
     echo("$names[$i]");
     $i++;
}

?>
 


You can be more efficient and use foreach:

<?php

Share

Delete File or an Image from the Server using PHP

If you want to delete a file or an image from the server via an interface from you website, you can use the following code

<?php

function deletemyfile($filename)
{

 $filearray = explode("/", $filename);

 $filecountno = count($filearray);
 $filecountno = $filecountno-1;
 for($i=0;$i<=$filecountno;$i++)
 {
  $myfilename = $filearray[$i];
 }

Share

Encrypt Decrypt using the Rijndael 256 Mcrypt Function in PHP

You can encrypt and decrypt data using the Mcrypt function below:

<?

$mykey = "THISisMyKey";

Share

Encrypt Decrypt using the Rijndael 256 Mcrypt Class in PHP

You can encrypt and decrypt data using the following Mcrypt class:

<?

class pWord
{
    var $mykey = "THISisMyKey";

Share