© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Hidaya Institu...
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
String Functio...
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
What Is String...
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
PHP chr() Func...
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
PHP ord() Func...
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
PHP strlen() F...
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
PHP substr() F...
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
PHP trim() Fun...
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Assignment # 1...
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Assignment # 2...
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Assignment # 3...
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Assignment # 4...
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Assignment # 5...
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Assignment # 5...
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Assignment # 6...
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Assignment # 6...
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Assignment # 7...
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
PHP rand() Fun...
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
• PHP rand() F...
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
• PHP rand() F...
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
• PHP round() ...
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
• PHP round() ...
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
• PHP ceil() f...
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
• PHP floor() ...
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
PHP explode() ...
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
PHP implode() ...
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Assignment # 8...
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Assignment # 9...
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Assignment # 1...
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
• PHP ucfirst(...
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
• PHP ucwords(...
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
• PHP strtolow...
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
• PHP strtoupp...
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Assignment # 1...
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
PHP hash_algos...
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
PHP md5() Func...
Upcoming SlideShare
Loading in …5
×

8- String functions and operations in php

399 views
361 views

Published on

Published in: Education, Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
399
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

8- String functions and operations in php

  1. 1. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org Hidaya Institute of Science & Technology www.histpk.org A Division of Hidaya Trust, Pakistan
  2. 2. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org String Functions and Operations
  3. 3. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org What Is String? A string is a data type used in programming, such as an integer and floating point unit, but is used to represent text rather than numbers. It is comprised of a set of characters that can also contain spaces and numbers. For example, the word "hamburger" and the phrase "I ate 3 hamburgers" are both strings. Even "12345" could be considered a string, if specified correctly. Typically, programmers must enclose strings in quotation marks for the data to recognized as a string and not a number or variable name. •String is a collection of characters. •String is a collection of ASCII characters.
  4. 4. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org PHP chr() Function The chr() function returns a character from the specified ASCII value. Syntax chr(ascii) Example <?php echo chr(65); echo chr(122); ?>
  5. 5. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org PHP ord() Function The ord() function returns the ASCII value of the first character of a string. Syntax ord(string) Example <?php echo ord(“h”).”<br />”; echo ord(“hello”).”<br />”; ?>
  6. 6. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org PHP strlen() Function The strlen() function is used to return the length of a string. Syntax strlen(string) Example <?php echo strlen("Hello world!"); ?>
  7. 7. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org PHP substr() Function The substr() function returns a part of a string. Syntax substr(string,start,length) Example <?php echo substr("Hello world!",6); echo substr("Hello world!",6,5); ?>
  8. 8. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org PHP trim() Function The trim() function removes whitespaces from both sides of a string. Syntax trim(string) Example <?php echo trim(“ Hello World ”); ?>
  9. 9. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org Assignment # 1 Enter String Text Click Output
  10. 10. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org Assignment # 2 Enter String Text Click Output
  11. 11. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org Assignment # 3 Enter String Text Click Output
  12. 12. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org Assignment # 4 Enter some text here Find character Replace character Click Output
  13. 13. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org Assignment # 5 Enter Text Click
  14. 14. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org Assignment # 5 Output
  15. 15. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org Assignment # 6 Characte r Output Click
  16. 16. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org Assignment # 6 Characte r Output Click
  17. 17. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org Assignment # 7 Enter Text Click Output
  18. 18. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org PHP rand() Function The rand() function generates a random integer. If this function is called without parameters, it returns a random integer between 0 and RAND_MAX. If you want a random number between 10 and 100 (inclusive), use rand (10,100). Note: On some platforms (such as Windows) RAND_MAX is only 32768. So, if you require a range larger than 32768, you can specify min and max, or use the mt_rand() function instead. The other random function, mt_rand() function generates a better random value than this function .
  19. 19. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org • PHP rand() Function continue…… • Syntax rand(min,max) Example 1 <?php echo(rand() . "<br />"); echo(getrandmax(). "<br />"); echo(rand(10,100)); ?>
  20. 20. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org • PHP rand() Function continue…… • Example 2 <?php echo "<hr> mt_rand = ".mt_rand()."<hr>"; echo "<hr>rand = ".rand()."<hr>"; echo "<hr> mt_rand with range = ".mt_rand(1,100)."<hr>"; echo "<hr> rand with range = ".rand(1,100)."<hr>"; ?>
  21. 21. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org • PHP round() function • The round() function rounds a number to the nearest integer. • Syntax: • round(x,prec) Parameter Description x Required. The number to be round prec Optional. The number of digits after the decimal point
  22. 22. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org • PHP round() function continued…. • Example 1 • <?php • echo round(1.68) ; • ?> • Example 2 • <?php • echo round(1.68,1) ; • ?>
  23. 23. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org • PHP ceil() function • The ceil() function returns the value of a number rounded UPWARDS to the nearest integer. Syntax Ceil(x) Example: <?php echo ceil(0.60); ?>
  24. 24. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org • PHP floor() Function • The floor() function returns the value of a number rounded DOWNWARDS to the nearest integer. Syntax floor(x) Example: <?php echo floor(0.60); ?>
  25. 25. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org PHP explode() Function The explode() function breaks a string into an array. Syntax explode(separator,string) Example <?php $string = "Hello world. It's a beautiful day."; print_r (explode(" ",$string)); ?>
  26. 26. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org PHP implode() Function The implode() function returns a string from the elements of an array. Syntax implode(separator,array) Example <?php $array = array('Hello','World!','Beautiful','Day!'); echo implode(" ",$array); ?>
  27. 27. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org Assignment # 8 Disabled Textbox Click Generate Password Output
  28. 28. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org Assignment # 9 Enter Word Click Output
  29. 29. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org Assignment # 10 Enter Text Click Output
  30. 30. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org • PHP ucfirst() Function • The ucfirst() function converts the first character of a string to uppercase. • Syntax ucfirst(string) • Example <?php echo ucfirst("hello world"); ?>
  31. 31. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org • PHP ucwords() Function • The ucwords() function converts the first character of each word in a string to uppercase • Syntax: • ucwords(string) • Example: <?php echo ucwords("hello world"); ?>
  32. 32. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org • PHP strtolower() Function • The strtolower() function converts a string to lowercase. • Syntax: strtolower(string) Example: <?php echo strtolower("Hello WORLD."); ?>
  33. 33. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org • PHP strtoupper() Function • The strtoupper() function converts a string to lowercase. • Syntax: strtoupper(string) Example: <?php echo strtoupper(“hello world."); ?>
  34. 34. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org Assignment # 11 Enter Text Encrypt Text Encrypted Data Decrypt Text Output
  35. 35. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org PHP hash_algos() Function hash_algos — Return a list of registered hashing algorithms Syntax array hash_algos () Example <?php print_r(hash_algos()); ?>
  36. 36. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org PHP md5() Function The md5() function calculates the MD5 hash of a string. This function returns the calculated MD5 hash on success, or FALSE on failure. Syntax md5(string) Example <?php $string = "Hello"; echo md5($string); ?>

×