Posts Tagged ‘PHP’
30
Jun

$rawPhoneNumber = "800-555-5555";

$phoneChunks = explode("-", $rawPhoneNumber);

echo "Raw Phone Number = $rawPhoneNumber <br />";

echo "First chunk = $phoneChunks[0]<br />";

echo "Second chunk = $phoneChunks[1]<br />";

echo "Third Chunk chunk = $phoneChunks[2]";

output

Raw Phone Number = 800-555-5555

First chunk = 800

Second chunk = 555

Third Chunk chunk = 5555

 

, , , , , , ,

30
Jun

$numberedString = "1234567890"; // 10 numbers from 1 to 0

$fivePos = strpos($numberedString, "5");

echo "The position of 5 in our string was $fivePos";

output

The position of 5 in our string was 4

 

 

, , ,

30
Jun

$pieces = array(“Hello”, “World,”, “I”, “am”, “Here!”);

$gluedTogetherSpaces = implode(” “, $pieces);

$gluedTogetherDashes = implode(“-”, $pieces);

for($i = 0; $i < count($pieces); $i++){

echo “Piece #$i = $pieces[$i] <br />”;

}

echo “Glued with Spaces = $gluedTogetherSpaces <br />”;

echo “Glued with Dashes = $gluedTogetherDashes”;

 

output

Piece #0 = Hello

Piece #1 = World,

Piece #2 = I

Piece #3 = am

Piece #4 = Here!

Glued with Spaces = Hello World, I am Here!

Glued with Dashes = Hello-World,-I-am-Here!

 

, , , , , , , ,

22
Jun

In PHP you can get contents of an output buffer using ob_get_contents(). The usage is given below:

ob_start();
echo "Schogini Inc";
$out_buffer = ob_get_contents();
ob_end_clean();
var_dump($out_buffer);

 

That’s it.

, , , ,

27
May

For Truecolor images the colors are simple 31-bit longs. Or,it is composed of 4 bytes .

The highest or leftmost bit in the alpha channel is not used which means the alpha channel can onlyhave values from 0 to 127.  You can use the ImageColorAllocate() as with paletted images, but you can also specify the color
directly.

<?php

$im  = ImageCreateTruecolor(300,256);

for($r=0; $r<256; $r++)

{

$col = ImageColorAllocate($im,$r,0,0);

ImageLine($im, 0,$r, 100, $r, $col);

}

for($g=0; $g<256; $g++)

{

$col = ImageColorAllocate($im,0,$g,0);

ImageLine($im, 100,255-$g, 200, 255-$g,
$col);

}

for($b=0; $b<256; $b++)

{

$col = ImageColorAllocate($im,0,0,$b);

ImageLine($im, 200,$b, 300, $b, $col);

}

Header('Content-Type: image/png');ImagePNG($im);

?>

output:

<?

$im = ImageCreateTrueColor(256,60);

for($x=0; $x<256; $x++)

{

ImageLine($im, $x, 0, $x, 19, $x);

ImageLine($im, 255-$x, 20, 255-$x, 39, $x<<8);

ImageLine($im, $x, 40, $x, 59, $x<<16);

}

Header('Content-Type: image/png');ImagePNG($im);

?>

output:

, , , , , , , , ,

27
May

GET:

  • When using method=”get” in HTML forms, all variable names and values are displayed in the URL.
  • The get method is not suitable for very large variable values.

    POST:

  • Information sent from a form with the POST method is invisible to others
  • no limits on the amount of information to send.

, , , ,

19
May
<?php
$myImage = ImageCreate(300,300);

$white = ImageColorAllocate ($myImage, 255, 255, 255);
$red  = ImageColorAllocate ($myImage, 255, 0, 0);
$green = ImageColorAllocate ($myImage, 0, 255, 0);
$blue = ImageColorAllocate ($myImage, 0, 0, 255);
$lt_red = ImageColorAllocate($myImage, 255, 150, 150);
$lt_green = ImageColorAllocate($myImage, 150, 255, 150);
$lt_blue = ImageColorAllocate($myImage, 150, 150, 255);

for ($i = 120;$i > 100;$i--) {
ImageFilledArc ($myImage, 100, $i, 200, 150, 0, 90, $lt_red, IMG_ARC_PIE);
ImageFilledArc ($myImage, 100, $i, 200, 150, 90, 180, $lt_green, IMG_ARC_PIE);
ImageFilledArc ($myImage, 100, $i, 200, 150, 180, 360, $lt_blue, IMG_ARC_PIE);
}

ImageFilledArc($myImage, 100, 100, 200, 150, 0, 90, $red, IMG_ARC_PIE);
ImageFilledArc($myImage, 100, 100, 200, 150, 90, 180 , $green, IMG_ARC_PIE);
ImageFilledArc($myImage, 100, 100, 200, 150, 180, 360 , $blue, IMG_ARC_PIE);

header ("Content-type: image/png");
ImagePNG($myImage);

ImageDestroy($myImage);
?>

output

 

, , , , , , ,

01
May

we can check whther the user logged in or not using worpress api function.

<?php
if ( is_user_logged_in() ) {
    echo 'Welcome, registered user!';
} else {
    echo 'Welcome, visitor!';
};
?>

, , , , ,

30
Apr

Apache’s mod_rewrite document, calls this module as “Swiss Army Knife of URL manipulation!”

 

mod_rewrite is an Apache module that allows for server-side manipulation of requested URLs. Incoming URLs are checked against a series of rules. The rules contain a regular expression to detect a particular pattern. If the pattern is found in the URL, and the proper conditions are met, the pattern is replaced with a provided substitution string or action. This process continues until there are no more rules left or the process is explicitly told to stop.

 

Fig: mod_rewrite control flow.

 

Advantages

  1. mod_rewrite can be used to transform long and complex urls into user friendly or short urls.

    For eg. http://myrurl.php/customer.php?name=shan&id=4562&aadr=561

    Above url can be converted to a more user friendly one as,

    http://myurl.php/customer/shan

     

  2. Security enhancement.

    Consider the above example a potential hacker can try out different urls to hack into the system by giving different parameters and values passed to customer.php, using mod_rewrite we can prevent such threats.

     

    mod_rewrite can be enabled by uncommenting the line,

    LoadModule rewrite_module modules/mod\_rewrite.so

    in apache configuration file httpd.conf.

, , , , , , , , , , , , , , , , , ,

04
Apr

If you want to add new items to NSPopUpButton using code in Cocoa Mac, then use the following lines of code

NSString *object1 = @"PHP";

NSString *object2 = @"SQL";

NSString *object3 = @"HTML";

NSString *object4 = @"Objective C";

NSMutableArray *myArray;

myArray= [NSMutableArray arrayWithObjects: object1, object2, object3, object4, nil];

[popUp removeAllItems];

[popUp addItemsWithTitles: myArray];

Here popUp is your NSPopUpButton.

This code will add the items, PHP, SQL, HTML & Objective C to your NSPopUpButton.

, , , , ,