Operation on String and String Function - Copy
Operation on String and String Function - Copy
FUNCTIONS
strlen()
strlen() - Return the Length of a String
The PHP strlen() function returns the
length of a string.
Example
Return the length of the string "Hello
world!":
<?php
echo strlen("Hello world!"); // outputs 12
?>
str_word_count()
str_word_count() - Count Words in a
String
The PHP str_word_count() function counts
the number of words in a string.
Example
Count the number of word in the string
"Hello world!":
<?php
echo str_word_count("Hello world!"); //
outputs 2
?>
strrev()
strrev() - Reverse a String
The PHP strrev() function reverses a
string.
Example
Reverse the string "Hello world!":
<?php
echo strrev("Hello world!"); // outputs
!dlrow olleH
?>
strpos()
Example
Convert all characters to uppercase:
<?php
echo strtoupper("Hello WORLD!");
?>
Output
HELLO WORLD!
PHP strtolower() Function
Example
Convert all characters to lowercase:
<?php
echo strtolower("Hello WORLD.");
?>
Output
hello world.
PHP strcmp() Function
<?php
echo strcmp("Hello world!","Hello world!");
?>
</body>
</html>
output
0
If this function returns 0, the two strings are equal
PHP ucwords() Function
<?php
echo ucwords("hello|world", "|");//displays Hello|World
?>
</body>
</html>
Basic graphics concept
There's more to documents than text.
Most PDF files contain some type of logo,
diagram, illustration, or picture. This
section shows how to include image files,
build your own line-art illustrations, and
repeat elements on every page (for
instance, a header with a logo).
docstore.mik.ua/orelly/webprog/php/ch10
_04.htm
PHP | imagecreate()
Function
The imagecreate() function is an inbuilt
function in PHP which is used to create a
new image. This function returns the
blank image of given size. In
general imagecreatetruecolor() functio
n is used instead of imagecreate()
function
because imagecreatetruecolor() functi
on creates high quality images.
Syntax:
imagecreate( $width, $height )
<?php
header("Content-Type: image/png");
imagepng($image);
imagedestroy($image);
?>
output
<?php
imagepng($image);
?>
output
Creating a pdf of
document
PDF supports many different embedded
image formats: PNG, JPEG, GIF, TIFF, CCITT,
and a raw image format that consists of a
stream of the exact byte sequence of pixels.
Not every feature of every format is
supported, however.
Adding an image to a PDF document is
relatively simple. The first step is to call the
appropriate open function for the type of
image you are using. These functions all take
the form pdf_open_ format( ). For instance:
$image = pdf_open_jpeg(pdf, filename);
Once you have opened the image, use
pdf_place_image( ) to indicate where in your
document the image should be located. While
you have an image open, you can place it
multiple times throughout your document; your
generated file will contain only one copy of the
actual image data. When you are done placing
your image, call the pdf_close_image( ) function:
pdf_place_image(pdf, image, x, y, scale);
pdf_close_image(pdf, image); The scale
parameter indicates the proportional scaling
factor to be used when placing the image in the
document. You can get the dimensions of an
image via
pdf_get_value( ) calls on the imagewidth and
imageheight keywords.
Some of the image creating
functions
1 imagejpeg()
2 imagegif()
3imagepng()
4imagewbmp()
Imagecolorallocate()
It is used to set the color to image
Syntax-
Imagecolorallocate(image,red,green,blue)
Imagestring(_)
It is used to drop the string on the given
image
Syntax-
imagrstring(image,fontsize,x,y,string,strin
g_color)
Ex-
<?php
$i=imagecreate(500,500);
$back=imagecolorallocate($i,0,200,0);
$text=imagecolorallocate($i,255,255,255
);
$imagestring($i,5,150,200,”Hello PHP “,
$text);
Header(content type:image/jpeg);
Imagejpeg($i);
?>
Scalling image
(1)Imagecreatetruecolor()
This inbuilt function is used to create
anew true color image. It returns an
image identifier representing a blank
image of the specified size.
Syntax-
imagecreatetruecolor(width,height);
(2)imagecopyresampled()
It copies rectangular portion of one image
to another image by smoothly
interpolating pixel values. So that in
particular reducing the size of an image
and still retains its clarity.
Syntax-.
Imagecopyresampled($dst _img,srs_img,
$dst_x,$dst_y,$src_x,$src_y,$dst_w,
$dst_h,$src_w,$src_h);