Friday, November 30, 2018

boolen example

If you store only booleans, use this:
$a = array('a'=> true, 'b'=> true, 'c'=>true);
$af = array_filter($a);
if ($af == $a) {
    echo "all true";
}
if (empty($af)) {
    echo "all false";
}
// set default value
$result = false;

foreach ($array as $key => $value) {
    if ($value === true) {
        $result = true;
        break;
    } 
}

// $result is now true if any value was true, otherwise it's false 

Thursday, November 29, 2018

Searching strings


Searching strings
some thing practical


PHP provides you several useful function for searching strings including strstr(), strpos(),strrpos(), substr_count() and strpbrk().
Checking if a string contains a substring


To check if a string contains a particular substring, you use the strstr() function. The strstr()accepts two parameters: a string that to be checked and a substring that you want to search for. If the substring found, the function returns the portion of the string that begins of the found text to the end of the string. It returns false if the substring cannot be found.

<?php
$str = 'Find a substring in a string';
$sub_str = 'substring';
echo strstr($str,$sub_str); //substring in a string?>


Locating position of a substring within a PHP string


If you want to know exact position of a substring within a string, you use the strpos() function. It returns the first occurrence of a substring in a string.



<?php
$str = 'Using strpos function in PHP';
$sub_str = 'strpos';
echo strpos($str,$sub_str); // 6
?>

The strrpos() function is similar to the strpos() function except it returns the position of the last occurrence of a substring in a string.



 
<?php
$str = 'String function';
$sub_str = 'n';
echo strpos($str,$sub_str); // 4
echo strrpos($str,$sub_str); // 14
?>


Getting the number of occurrences of a substring


To get how many times a substring that appears in a string, you use the substr_count() function. The substr_count() function is useful in many cases e.g., you can count how many times a keyword is mentioned in an article to calculate its density.


 
<?php
$str = <<<EOT
This is sample text that demonstrates 
how to calulate keyword density in 
an article. We can use this function
for on-page optimization function in 
SEO software.
EOT;

$keyword = 'function';

$word_count = str_word_count($str);
$keyword_count = substr_count($str,$keyword);

if($word_count > 0){
$density = $keyword_count * 100 / $word_count;
echo number_format($density, 2, '.', '') . '%'; //7.69%
}?>



Checking if a string contains any character in a set of characters


To check if a string contains any character in a set of characters, you use strpbrk() function. The strpbrk() function accepts two parameters: a string and a set of characters that you want to find. It returns a substring starting from the character found or false if character in a set of characters does not appear in the string. The strbbrk() function is useful in many cases e.g., you can check if a user name contains any special character in a set !, @, $, %… as follows:



 
<?php
$username1 = 'zentut';
$username2 = 'zen@tut';

$not_allowed_chars = '!@#$%^&*';

if(strpbrk($username1, $not_allowed_chars)){
echo 'invalid username because it contains one of ' . $not_allowed_chars;
}

if(strpbrk($username2, $not_allowed_chars)){
echo 'invalid username because it contains one of ' . $not_allowed_chars;
}?>



Replacing in strings


PHP provides some useful string functions to replace some portions of a string with different strings including str_replace(), substr_replace() and strst().
Replacing all occurrences of a search string


To replace all occurrences of a search string with the replacement string, you use the str_replace()function. Let’s take a look at the following example:



 
<?php

$str = 'This is an example of a string 
that demonstrates string replacement';

echo str_replace('string', 'text', $str);

// This is an example of a text 
// that demonstrates text replacement
?>

We replaced all occurrences of ‘ string‘ by ‘ text‘ in the string $str.

To count how many times the search string was replaced, you need to pass the fourth argument to the function as follows:



<?php

$str = 'This is an example of a string 
that demonstrates string replacement';

$times = 0;
str_replace('string', 'text', $str,$times);

echo "The string was replaced $times time(s)";

?>



Removing whitespace


To remove whitespace from:
the beginning of a string you use the ltrim() function.
the end of the string you use the rtrim() function
both the beginning and the end of a string you use the trim() function.

Let’s take a look at the following example:



<?php

$s1 = ' a string with whitespace at the beginning';
$s2 = 'a string with whitespace at the end ';
$s3 = ' a string with whitespaces at the beginning and the end ';

echo ltrim($s1) . '<br/>';
echo rtrim($s2) . '<br/>';
echo trim($s3) . '<br/>';
?>

With those functions, you can remove other characters other than whitespace if you specify them as the second argument.

if true false

some thing practical



<?php
define('val___nul', "");
define('val___nul5', "fillup feild!_please");

?>





<?php 

$a=val___nul!=val___nul5;
if($a=== true){ echo val___nul5;}
else {echo "its not ok";}

?>

<br>
First, you specify the operator <<<, followed by an IDENTIFIER, and then a newline. Next, you put a string value. Finally, you use the same

IDENTIFIER to close the string.

The following example defines a string using heredoc syntax:
<?php

$s = <<<EOT
I'm a string that is using
heredoc syntax. I can contain
single quotation marks (') and double quotation 
mark(") without using escape character
EOT;

echo $s;?>

Notice that PHP replaces the variables by their values in a string defined using heredoc syntax.

The nowdoc syntax is similar to the heredoc syntax except the identifier in nowdoc syntax is enclosed in single quotation marks.
<?php

$s = <<<'EOT'
I'm a string that is using
nowdoc syntax. I can contain
single quotation marks (') and double quotation 
mark(") without using escape character
EOT;

echo $s;?>


In addition, PHP does not parse and replace variables by their values in a string defined using nowdoc syntax.

Accessing characters in a string
To access a character of a string at a particular position, you use the following syntax:


$s[index]

<br>


<?php

$str = 'this is a PHP string';
$str[0] = 'T';

echo $str;?>


<br>
Getting the length of a string
To get the number of characters in a string, you use a built-in function strlen(). It accepts a string as a parameter and returns the number of

characters in that string. Let’s take a look a the following example of using the strlen() function:


<?php

$str = 'this is a PHP string';
echo strlen($str);?>
<br>

If you want to count the number of words in a string, you use the str_word_count() function instead.
<br>


<?php
$str = 'this is a PHP string';
echo str_word_count($str);
 // 5
?>

<br>

Comparing strings
PHP provides two built-in functions strcmp() and strcasecmp() that allow you to compare two strings. Both functions accept two string arguments and

return an integer number:

If two strings are equal, it returns 0.
If the first string is greater than the second string it returns a number that is greater than 0 .
If the first string is less than the second string, it returns a number that is less than 0.
The only difference between strcmp() and strcasecmp() functions is that the strcasecmp() function compares strings in case-insensitive manner

whereas the strcmp() function does not.

<br>


<?php 
$str1 = 'PHP String';
$str2 = 'php string';
$result = strcasecmp($str1,$str2);

if($result == 0){

 echo '$str1 and $str2 are equal';

}else if($result > 0){

 echo '$str1 is greater than $str2';

}else{
 echo '$str1 is less than $str2';
}?>


<br>

If you replace the strcasecmp() function by strcmp() function in the code snippet above, the output will be different.

Concatenating strings
PHP allows you to concatenate strings using period ( .) operator. If you concatenate a string with a variable that is not a string type, the result

is a string because PHP automatically converts the non-string variable into a string variable before concatenating.

The following example demonstrates strings concatenation:

<br>
<?php
   $str = 'This is' . ' a string';
   echo $str . '<br/>';

   $age   = 22;
   $s1 = 'years old';

   $s2 = 'Are you ' . $age . ' ' . $s1 . '?';
   echo $s2;
?>


<br>




URDU FONT STYLE

URDU FONT STYLE

 <HTML>
 <HEAD>
 <META content="text/html; charset=utf-8" http-equiv=Content-Type>
 <TITLE>Ghazal</TITLE>
 <STYLE TYPE="text/css">
 H1  {
   color: #007c78;
    font-family: "Jameel Noori Nastaleeq;";
    font-size: 15px; }
 #urdu {
    font-family: "Jameel Noori Nastaleeq;";
        font-size: 32px; }
 }


.ab{ font-size:20px;padding-left:23px; font-family:Nafees Nastaleeq;}
 </STYLE>
  </HEAD>
 <BODY bgcolor="#ffffff">

 <center>
 <table border=0>
 <tr><td align=right>
 <h1 align=right>
 &#65231;&#65143;&#65200;&#65142;&#65245;  <br>
 </h1>

 <span id="ab">
  <P>
&#65207;&#65166;&#65249;&#65146; &#65231;&#65143;&#65250; &#65243;&#64431;

&#65165;&#65203;&#65147;&#65268;&#65198; &#64424;&#65143;&#65268;&#64415;

&#64424;&#65143;&#65250; &#65247;&#65262;&#64402;  <br>
&#65203;&#65145;&#65170;&#65186;&#65146; &#65255;&#65143;&#65262;

&#65243;&#64431; &#65203;&#65143;&#65236;&#65147;&#65268;&#65198;

&#64424;&#65143;&#65268;&#64415; &#64424;&#65143;&#65250;

&#65247;&#65262;&#64402;  <br>
  <P>
&#65169;&#65145;&#65184;&#64427; &#64380;&#65145;&#64640;

&#64424;&#65143;&#64431; &#64380;&#65143;&#65198;&#65165;&#65229;

&#64404;&#65262; &#65193;&#65146;&#65245; &#64567;  <br>
&#64344;&#64429;&#65147;&#65198; &#65169;&#64429;&#65147;&#64509;

&#65197;&#65261;&#65207;&#65143;&#65254;

&#65215;&#65143;&#65252;&#65147;&#65268;&#65198;

&#64424;&#65143;&#65268;&#64415; &#64424;&#65143;&#65250;

&#65247;&#65262;&#64402;  <br>
  <P>
&#65267;&#65166;&#65201;&#65262; &#65231;&#65143;&#65250;

&#65243;&#65147;&#64509; &#64424;&#65143;&#64431; &#64404;&#65143;&#65198;

&#65243;&#65262;&#65163;&#65147;&#64509;

&#65239;&#65147;&#65268;&#65252;&#65143;&#65174;  <br>
&#64344;&#64429;&#65147;&#65198; &#65175;&#65262; &#65203;&#65143;&#65168;

&#65203;&#64431; &#65165;&#65251;&#65147;&#65268;&#65198;

&#64424;&#65143;&#65268;&#64415; &#64424;&#65143;&#65250;

&#65247;&#65262;&#64402;  <br>
  <P>
&#65165;&#65267;&#65242; &#65251;&#65143;&#65262;&#64424;&#64472;&#65249;

&#65203;&#65166;

&#65175;&#65143;&#65212;&#65143;&#65262;&#65149;&#65144;&#65197;

&#64424;&#65143;&#65268;&#64415;  <br>
&#65165;&#65267;&#65242;

&#65251;&#65143;&#65194;&#65149;&#64428;&#65143;&#65250;

&#65247;&#65143;&#65244;&#65147;&#65268;&#65198;

&#64424;&#65143;&#65268;&#64415; &#64424;&#65143;&#65250;

&#65247;&#65262;&#64402;  <br>
  <P>
&#65239;&#65166;&#65175;&#65147;&#65248;&#65262;&#64414; &#65243;&#64431;

&#65255;&#65143;&#64405;&#65143;&#65198; &#65251;&#65268;&#64415;

&#65165;&#65163;&#64431; &#65267;&#65166;&#65197;&#65261;  <br>
&#65165;&#64424;&#65246;&#65146; &#65193;&#65146;&#65245; &#65243;&#64431;

&#65251;&#65145;&#65208;&#65147;&#65268;&#65198;

&#64424;&#65143;&#65268;&#64415; &#64424;&#65143;&#65250;

&#65247;&#65262;&#64402;  <br>
  <P>
&#65165;&#65267;&#65242; &#65255;&#65143;&#65224;&#65143;&#65198;

&#65243;&#65147;&#64509; &#64424;&#65143;&#65252;&#65268;&#64415;

&#65169;&#64429;&#65147;&#64509; &#65193;&#64430; &#65193;&#65261;

&#65169;&#64429;&#65147;&#65268;&#65242;  <br>
&#65197;&#65165;&#65257; &#64380;&#65143;&#65248;&#65176;&#64431;

&#65235;&#65143;&#65240;&#65147;&#65268;&#65198;

&#64424;&#65143;&#65268;&#64415; &#64424;&#65143;&#65250;

&#65247;&#65262;&#64402;  <br>
  <P>
&#64344;&#64429;&#65147;&#65198;

&#65251;&#65147;&#65248;&#65268;&#64405;&#65166; &#65255;&#65143;&#65258;

&#65203;&#65166;&#65193;&#65257; &#65193;&#65146;&#65245;

&#64424;&#65143;&#65250; &#65203;&#65166;  <br>
&#65235;&#65147;&#64509; &#65199;&#65142;&#65251;&#65166;&#65255;&#65258;

&#65255;&#65143;&#65200;&#65146;&#65267;&#65198;

&#64424;&#65143;&#65268;&#64415; &#64424;&#65143;&#65250;

&#65247;&#65262;&#64402;  <br>
  <P>
&#65191;&#64472;&#65193; &#64424;&#65143;&#65252;&#65268;&#64415;

&#65169;&#64429;&#65147;&#64509; &#64424;&#65143;&#64431;

&#65153;&#65203;&#65198;&#65165; &#65193;&#65142;&#65197;&#64567;&#65197; 

<br>
&#65251;&#65143;&#65174; &#65243;&#65143;&#64425;&#65262;

&#65193;&#65142;&#65203;&#65176;&#64405;&#65147;&#65268;&#65198;

&#64424;&#65143;&#65268;&#64415; &#64424;&#65143;&#65250;

&#65247;&#65262;&#64402;  <br>
  <P>
 &#65199;&#65142;&#65235;&#65143;&#65198; &#65165;&#65251;&#65143;&#65198; 
 ٹاس کرنے پہنچ گئے،سوشل میڈیا صارفین برہم
<br>
 </span>

 </td></tr>
 </table>


 <style>

 div{ font-family: Jameel Noori Nastaleeq;
 font-size:20px;padding-left:23px; }  </style> <div> وہ ہر چند چاہیں گے کہ آگ سے نکل جائیں مگر اس سے نہیں نکل سکیں گے اور ان کیلئے ہمیشہ کا عذاب ہے۔ اور چوری کرنے والا مرد اور چوری کرنے والی عورت ان کا ایک ایک ہاتھ کاٹ دو ، یہ ان کے کرتوتوں کی سزا اور اللہ کی طرف سے عبرت کے طور پر ہے اور اللہ زبردست ہے صاحب حکمت ہے۔ پھر جو شخص گناہ کے بعد توبہ کرلے اور نیکو کار ہو جائے تو اللہ اسکو معاف کردے گا، کچھ شک نہیں کہ اللہ بڑا بخشنے والا ہے بڑا مہربان ہے۔



 kljhlkjjlkjkl</div>


 <span style="font-size:20px;padding-left:23px; font-family:Nafees Nastaleeq;"><i> براے مہربانی اپنی باری کا انتظار کریں </i></span>
 </body>
 </html>

project practical tag

project practical tag
<p dir="rtl" lang="ar" style="color:#ecc;font-size:20px;">رَبٍّ زِدْنٍي عِلمًا</p>

رَبٍّ زِدْنٍي عِلمًا

 <p dir="rtl" lang="ar" style="color:green;font-size:20px;"> رَبٍّ زِدْنٍي عِلمًا</p>
رَبٍّ زِدْنٍي عِلمًا

Wednesday, November 28, 2018

PHP File Permissions

PHP File Permissions

Summary: in this tutorial, you will learn how to deal with PHP file permissions including checking and changing file permissions.
File permissions specify what you can do with a particular file in the system e.g., reading, writing or executing the file. Notice that PHP automatically grants appropriate permissions behind the scenes. For example, if you creates a new file for writing, PHP automatically grants read and write permissions to you.
In addition, PHP also provides some useful functions for checking and changing the file permissions.

PHP checking file permissions

PHP gives you three handy functions that allow you to check file permissions:
  • is_readable() returns true if you are allowed to read the file, otherwise returns false.
  • is_writable() returns true if you are allowed to write the file, otherwise returns false.
  • is_executable() returns true if you are allowed to execute the file, otherwise returns false.
Let’s take a look at the following example:
Besides those functions, PHP also provides the fileperms() function that returns an integer, which represents the permissions that are set on a particular file.

PHP changing file permissions

To change the file permissions, or mode, you use chmod() function. First, you need to pass the name of the file that you want to set permission. Second, you need to specify the desired permission. The chmod() function returns true if the permission was set successfully otherwise it returns false.
A file permission is represented by an octal number that contains three digits:
  • The first digit specifies what the owner of the file can do with file.
  • The second digit specifies what the owner group of the file can do with the file.
  • The third digit specifies what everyone can do with the file.
The following table illustrates the value of each digit that represents the access permission for particular users ( user, user group or everyone) :
ValuePermission
0cannot read, write or execute
1can only execute
2can only write
3can write and execute
4can only read
5can read and execute
6can read and write
7can read, write and execute
For example, to set a permission that only creator or owner can read and write a file, everyone else only can read the file, we use the following code:
Notice that we put 0 before 644 to ask PHP to interpret it as an octal number.

form validation

function formsubmit ( ) { var empname = document .getElementById ( 'emp_name' ). value ; var email = document .getElem...