domingo, 29 de noviembre de 2015

clean this code

<?php
$str = <<<EOD

Event: MusicOnHoldStop
Privilege: call,all
Channel: SIP/callcentric-0000007c
ChannelState: 6
ChannelStateDesc: Up
CallerIDNum: 0411
CallerIDName: <unknown>
ConnectedLineNum: 2066013560
ConnectedLineName: 109
AccountCode:
Context: recording
Exten:
Priority: 1
Uniqueid: 1448837557.211

EOD;


//echo $str;

$result = stristr($str, 'event');
$a=str_replace(" ","<br>","$result");


$b=stristr($str, 'event');


echo "<br>";


echo "$b";
$c=explode(" ",$b);

echo "<br><br>";

echo $c[0];
?>

finding if string exist strripos()

Example #1 A simple strripos() example

<?php
$haystack = 'ababcd';
$needle   = 'aB';

$pos      = strripos($haystack, $needle);

if ($pos === false) {
    echo "Sorry, we did not find ($needle) in ($haystack)";
} else {
    echo "Congratulations!\n";
    echo "We found the last ($needle) in ($haystack) at position ($pos)";
}
?>


The above example will output:

   Congratulations!
   We found the last (aB) in (ababcd) at position (2

php searching string using stristr() & strpbrk()

<?php
$email  = 'name@example.com';


$domain = stristr($email, '@');


echo $domain."<br>"; // prints @example.com


$user = stristr($email, '@', true); // As of PHP 5.3.0


echo $user;


echo "<br>";

echo strpbrk($email,'a');


?>


@example.com
name
ame@example.com

finding if string exist on string strpos()

<?php
$mystring = 'abc';
$findme   = 'a';
$pos = strpos($mystring, $findme);

// The !== operator can also be used.  Using != would not work as expected
// because the position of 'a' is 0. The statement (0 != false) uates
// to false.
if ($pos !== false) {
     echo "The string '$findme' was found in the string '$mystring'";
         echo " and exists at position $pos";
} else {
     echo "The string '$findme' was not found in the string '$mystring'";
}
?>

php explode and list() function

<?php

$data "foo:*:1023:1000::/home/foo:/bin/sh";
list(
$user$pass$uid$gid$gecos$home$shell) = explode(":"$data);
echo 
$user// foo
echo $pass// *


?>



<?php

$data = "foo:*:1023:1000::/home/foo:/bin/sh";
$r=list($user, $pass, $uid, $gid, $gecos, $home, $shell) = explode(":", $data);

foreach($r as $value ){

echo $value."<br>";
}




?>

outout  :
foo
*
1023
1000

/home/foo
/bin/sh

sábado, 7 de noviembre de 2015

php date() format

<?php
// Assuming today is March 10th, 2001, 5:16:18 pm, and that we are in the
// Mountain Standard Time (MST) Time Zone

$today = date("F j, Y, g:i a");                 // March 10, 2001, 5:16 pm
$today = date("m.d.y");                         // 03.10.01
$today = date("j, n, Y");                       // 10, 3, 2001
$today = date("Ymd");                           // 20010310
$today = date('h-i-s, j-m-y, it is w Day');     // 05-16-18, 10-03-01, 1631 1618 6 Satpm01
$today = date('\i\t \i\s \t\h\e jS \d\a\y.');   // it is the 10th day.
$today = date("D M j G:i:s T Y");               // Sat Mar 10 17:16:18 MST 2001
$today = date('H:m:s \m \i\s\ \m\o\n\t\h');     // 17:03:18 m is month
$today = date("H:i:s");                         // 17:16:18
$today = date("Y-m-d H:i:s");                   // 2001-03-10 17:16:18 (the MySQL DATETIME format)
?>
http://php.net/manual/en/function.date.php

calculating the minute difference between dates

<?php


$datetime="2015-11-07 23:20:03";
$datetime1 = strtotime($datetime ); //convert date to unixtime
$datetime2 = time(); //actual date on unixtime
$interval  = abs($datetime2 - $datetime1);
$minutes   = round($interval / 60);
return  $minutes;



?>

check and uncheck

<!DOCTYPE html>
<html>
<head>
<script>
function togglecheckboxes(master,group){
        var cbarray = document.getElementsByClassName(group);
        for(var i = 0; i < cbarray.length; i++){
                var cb = document.getElementById(cbarray[i].id);
                cb.checked = master.checked;
        }
}
</script>
</head>
<body>

<form action="show_all.php" method=POST>


<input type="checkbox" id="cbgroup1_master" onchange="togglecheckboxes(this,'cbgroup1')"> Toggle All
<br><br>
<input type="checkbox" id="cb1_1" class="cbgroup1" name="cbg1[]" value="1"> Item 1<br>
<input type="checkbox" id="cb1_2" class="cbgroup1" name="cbg1[]" value="2"> Item 2<br>
<input type="checkbox" id="cb1_3" class="cbgroup1" name="cbg1[]" value="3"> Item 3<br>
<input type="checkbox" id="cb1_4" class="cbgroup1" name="cbg1[]" value="4"> Item 4<br>
<input type="submit" value="Submit">

</form>
</body>
</html>



PART 2

<?php



 foreach ($_POST[cbg1] as $d )
{
echo $d."\n";


}

echo  $_GET['id'];

?>