PHP Tutorial



PHP STRING AND NUMBERS


🧡 PHP Strings and Numbers

In PHP, strings and numbers are two of the most commonly used data types. Let’s explore how to work with both effectively.

πŸ“˜ PHP Strings

A string is a series of characters, like "Hello World!" or "Technorank".

Examples of strings:

<?php
  $text1 = "Hello World!";
  $text2 = 'Technorank Solutions';
  echo $text1;
?>
  

✨ String Functions

  • strlen() – Returns the length of a string
  • strtoupper() – Converts to uppercase
  • strtolower() – Converts to lowercase
  • str_replace() – Replaces text within a string
  • strpos() – Finds the position of text in a string
$text = "Technorank is cool!";
echo strlen($text);       // Output: 20
echo strtoupper($text);   // Output: TECHNORANK IS COOL!
  

πŸ”’ PHP Numbers

PHP supports integers (whole numbers) and floats (decimal numbers).

Examples of numbers:

<?php
  $x = 10;      // Integer
  $y = 5.5;     // Float
  echo $x + $y; // Output: 15.5
?>
  

πŸ“ Number Functions

  • is_int() – Checks if value is an integer
  • is_float() – Checks if value is a float
  • round() – Rounds a number
  • number_format() – Formats a number with grouped thousands
$num = 1234.567;
echo round($num);              // Output: 1235
echo number_format($num, 2);   // Output: 1,234.57
  
πŸ’‘ Tip: PHP automatically converts string numbers to numeric values when needed.
βœ… Summary:
  • Strings are text values enclosed in quotes.
  • Numbers can be integers or floats.
  • PHP provides many functions to manipulate both types.

🌟 Enjoyed Learning with Us?

Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!

Leave a Google Review