0% found this document useful (0 votes)
3 views24 pages

Operation on String and String Function - Copy

The document provides an overview of various PHP string functions such as strlen(), str_word_count(), strrev(), strpos(), and str_replace(), along with examples of their usage. It also covers basic graphics concepts in PHP, including image creation with functions like imagecreate() and imagecreatetruecolor(), and how to manipulate images and add text. Additionally, it discusses how to create and embed images in PDF documents using specific PDF functions.

Uploaded by

bansalhemant
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views24 pages

Operation on String and String Function - Copy

The document provides an overview of various PHP string functions such as strlen(), str_word_count(), strrev(), strpos(), and str_replace(), along with examples of their usage. It also covers basic graphics concepts in PHP, including image creation with functions like imagecreate() and imagecreatetruecolor(), and how to manipulate images and add text. Additionally, it discusses how to create and embed images in PDF documents using specific PDF functions.

Uploaded by

bansalhemant
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 24

PHP STRING

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()

 The PHP strpos() function searches for a


specific text within a string. If a match is
found, the function returns the character
position of the first match. If no match is
found, it will return FALSE.
 Example
 Search for the text "world" in the string "Hello
world!":
 <?php
echo strpos("Hello world!", "world"); // outputs
6
?>
str_replace()

 The PHP str_replace() function replaces


some characters with some other
characters in a string.
 Example
 Replace the text "world" with "Dolly":
 <?php
echo str_replace("world", "Dolly", "Hello
world!"); // outputs Hello Dolly!
?>
PHP strtoupper() Function

 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

 Compare two strings (case-sensitive):


 <html>
 <body>

 <?php
 echo strcmp("Hello world!","Hello world!");
 ?>

 <p>If this function returns 0, the two strings are equal.</p>

 </body>
 </html>
 output
 0
 If this function returns 0, the two strings are equal
PHP ucwords() Function

 The ucwords() function converts the first character of


each word in a string to uppercase.
 Syntax
 ucwords(string, delimiters)
 <html>
 <body>

 <?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

 // Create the size of image or blank image


 $image = imagecreate(500, 300);

 // Set the background color of image


 $background_color = imagecolorallocate($image, 0, 153, 0);

 // Set the text color of image


 $text_color = imagecolorallocate($image, 255, 255, 255);

 // Function to create image which contains string.


 imagestring($image, 5, 180, 100, "GeeksforGeeks", $text_color);
 imagestring($image, 3, 160, 120, "A computer science portal",
$text_color);

 header("Content-Type: image/png");

 imagepng($image);
 imagedestroy($image);

 ?>
output
 <?php

 // Create the size of image or blank image


 $image = imagecreate(500, 300);

 // Set the vertices of polygon


 $values = array(
 50, 50, // Point 1 (x, y)
 50, 250, // Point 2 (x, y)
 250, 50, // Point 3 (x, y)
 250, 250 // Point 3 (x, y)
 );
 // Set the background color of image
 $background_color = imagecolorallocate($image, 0, 153, 0);

 // Fill background with above selected color


 imagefill($image, 0, 0, $background_color);

 // Allocate a color for the polygon


 $image_color = imagecolorallocate($image, 255, 255, 255);

 // Draw the polygon


 imagepolygon($image, $values, 4, $image_color);

 // Output the picture to the browser


 header('Content-type: image/png');

 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);

You might also like