Advertisement
Guest User

Untitled

a guest
Mar 19th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. <?php
  2.  
  3. //Length of String
  4. $OpeningLine = "Africa and Asia face some of the world’s greatest health challenges, but their research capacity is not yet sufficient to meet them.";
  5. $length = strlen($OpeningLine);
  6. echo $OpeningLine, PHP_EOL;
  7. echo "This opening line is $length characters", PHP_EOL;
  8.  
  9. echo"--------------------------", PHP_EOL;
  10.  
  11. //String manipulation - upper case
  12. echo "1. String manipulation", PHP_EOL;
  13. echo "Our key programme partners are " . strtoupper('India Alliance and African Academy of Sciences'), PHP_EOL;
  14.  
  15. //Position of Africa within a string (no of characters into the string)
  16. echo "2. Postion within a string", PHP_EOL;
  17. echo strpos ("We’re taking coordinated action to transform the research ecosystems in Africa and Asia.", "Africa"), PHP_EOL;
  18.  
  19. //String manipulation, replacement of 'Asia' with 'India'
  20. echo "3. String manipulation", PHP_EOL;
  21. $str = "Africa and Asia face some of the world’s greatest health challenges,";
  22. echo str_replace('Asia','India', $str). PHP_EOL;
  23.  
  24. //Printf - formating the number 4.13578 , indenting by 40 characters
  25. $ExampleNumber = 4.13578;
  26. $ExampleText = "Playing with Printf";
  27. $format = "%d. %40s \n";
  28. printf($format, $ExampleNumber, $ExampleText);
  29.  
  30. //Sprintf - formatting to 2 decimal places, taking the result and rounding to 8 decimal places
  31. $ExampleNumber = 5.00004;
  32. $ExampleText = "Playing with sprintf";
  33. $format = "%0.2f";
  34. $Result = sprintf($format, $ExampleNumber);
  35. echo $Result, PHP_EOL;
  36. $Finaloutput = sprintf("%0.8f %40s", $Result, $ExampleText);
  37. echo $Finaloutput;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement