Home Tutorial Php PHP Variables and Strings

 
 

Share on Google+Share on Google+
PHP Variables and Strings
Posted on: January 9, 2010 at 12:00 AM
Advertisement
We use variables to store values and we use string variables to store the values that includes the characters.

php variables and strings

We use variables to store values and we use string variables to store the values that includes the characters. We can use the php string directly in our coding but it is more time consuming than saving the php strings into one variable and use it again and again. For example :

<?php

$msg = "I love my country !";

echo $msg;

?>

Here, we store the string value in $msg variable. We can also concatenate two or more string variables. For example :

<?php

    $msg = "I love my country";

    $msg1 = "We should care our country.";

    $msg2 = "We should follow the rules and regulations of the country !";

      echo $msg . " ," . " " . $msg1 . " " ." and " . $msg2;

?>

Here, we concatenate different-2 messages in one.

In PHP we have also some pre-defined string functions which is very useful to learn. For example :

(1) Strlen ( )  function which counts the characters in the string.

<?php

echo strlen("I love my country");

?>

The output is : 17.

 

(2) Strpos ( ) function is to find the character in the string. It finds the length of the particular character.

<?php

echo strpos("I love my country","country");

?>

The output is : 7 or sometime it will take the value of blanks, space or commas and soon.

Apart from these two functions strings contains several more functions to save your time.

 

Advertisement

Related Tags for PHP Variables and Strings:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: January 9, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com