martes, 24 de febrero de 2015

PHP Function preg_split()


previous

Advertisements

Syntax

array preg_split (string pattern, string string [, int limit [, int flags]]);

Definition and Usage

The preg_split() function operates exactly like split(), except that regular expressions are accepted as input parameters for pattern.
If the optional input parameter limit is specified, then only limit number of substrings are returned.
flags can be any combination of the following flags:
  • PREG_SPLIT_NO_EMPTY: If this flag is set, only non-empty pieces will be returned by preg_split().
  • PREG_SPLIT_DELIM_CAPTURE: If this flag is set, parenthesized expression in the delimiter pattern will be captured and returned as well.
  • PREG_SPLIT_OFFSET_CAPTURE: If this flag is set, for every occurring match the appendant string offset will also be returned.

Return Value

  • Returns an array of strings after splitting up a string.

Example

Following is the piece of code, copy and paste this code into a file and verify the result.
<?php

$ip = "123.456.789.000"; // some IP address
$iparr = split ("/\./", $ip); 
print "$iparr[0] <br />";
print "$iparr[1] <br />" ;
print "$iparr[2] <br />"  ;
print "$iparr[3] <br />"  ;

?>
This will produce following result.
123
456
789
000 

domingo, 22 de febrero de 2015

php basic function return

<?php


function sum($a,$b){
   

$x=$a+$b;

    return $x;
}

$r= sum(411,45);

echo $r;

////////
salida
456
--------------------
<?php


function sum($a,$b){
   

  echo ($a+$b);

   
}

$r= sum(411,45)



////salida  456

------------------------

<?php


function sum($a,$b){
   

  return ($a+$b);

   
}

$r= sum(411,45);
echo $r;


////salida  456




//////////COLOR  OUPUT
<?php

function alert($var) {

if ($var<50) {

$var="<font color=blue>$var</font>";

}


if($var>50) {

$var="<font color=red>$var</font>";


}


return $var;


}

 echo '$var  color  is   '.alert(30);

?>

Fatal error: Call to undefined function mysql_connect()

Open your terminal and run bellow command. 

sudo apt-get install mysql-server
 
 
 
If you are running PHP you will also need to install the php module for mysql 5:

sudo apt-get install php5-mysql
 
 
http://stackoverflow.com/questions/10615436/fatal-error-call-to-undefined-function-mysql-connect 

jueves, 19 de febrero de 2015

PHP logical operators and or

$a=10;
$b=11;
if($a==10 and $b==11)
{
echo $a+$b;

}

else {

echo $a-$b;   
}

21

------------

$a=10;
$b=111;
if($a==10 or $b==11)
{
echo $a+$b;

}

else {

echo $a-$b;


   
}

121

while and break and continue

$i = 1;
while ($i <= 10) {
    echo $i++."<br>";
   
    if ($i==6)
    {
    echo "founded $i";
   
    break;
   
    }
   
    }
   

1
2
3
4
5
founded 6



------------
$i = 1;
while ($i <= 10) {
    echo $i++."<br>";
   
    if ($i==6)
    {
    echo "founded $i";
   
    continue;
   
    }
   
    }
    



1
2
3
4
5
founded 66
7
8
9
10

php elseif

<?phpif($a) { conditional1(); }
elseif(
$b) { conditional2(); }
elseif(
$c) { conditional3(); }
elseif(
$d) { conditional4(); }
elseif(
$e) { conditional5(); }
elseif(
$f) { conditional6(); }
elseif(
$g) { conditional7(); }
elseif(
$h) { conditional8(); }
else {
conditional9(); }?>

lunes, 16 de febrero de 2015

Query por fecaha actual

mysql> select  count(*) as  calls,dcontext as ivr,month(now()) as month ,dayofmonth(now())as day from cdr where dcontext='ivr_5' and month(calldate)=month(now()) and dayofmonth(calldate)=dayofmonth(now());
+-------+-----+-------+------+
| calls | ivr | month | day  |
+-------+-----+-------+------+
|     0 | NULL |     2 |   16 |
+-------+-----+-------+------+
1 row in set (0.16 sec)


calldate es dnde estan las fechas