Home   Help Login Register  
Welcome, Guest. Please login or register.

Login with username, password and session length

Search
Free Website WooThemes - Quality Themes, Great Support
Pages: [1]   Go Down
Print
Topic: PHP Strings  (Read 1111 times)
« on: August 30, 2007, 01:24:27 PM »
Tech Offline
Newbie

View Profile
*

iTrader: 1
Posts: 183



In programming, a string is a sequence of letters, symbols, characters and arithmetic values or combination of all tied together in single or double quotes. For example, "I Love PHP", "10", '100.01', "", etc are all examples of strings.

Declaring String Variable in PHP

An example:

$my_name = "John";

In PHP, a variable must start with $ sign followed by variable name. The string value must be wrapped in double or single quotes.

Concatenate / Join Strings in PHP

Sometimes while working with strings in our code, we need to join two strings. In PHP, you can use '.' to concatenate two or more strings together to form a single string.

An Example:

$my_first_name = "John";

$my_last_name = "Doe";

//concatenate my first and last name

$my_full_name = $my_first_name. " " . $my_last_name;

echo $my_full_name;

The above example with output "John Doe".

Single and Double Quotes PHP Strings

Double Quotes:

Strings in PHP can be wrapped in double or singles quotes. Using double quotes is the primary method. Double quotes allow us to escape specials characters in our string. For example, when you use the $ sign within double quotes it is treated as php variable and will not show up in the output

An Example:

$str = "hello";

echo "$str everyone!";

Notice in the above code, we wrapped the $str variable in double quoted string. The above example will output "hello everyone" NOT "$str everyone"

Single Quotes:

Single quotes can be used to do things like...

An example:

$quote_of_the_day = '"To be or not to be. That is the question"';

echo $quote_of_the_day;

Notice, we used double quotes around the text. The code will output "To be or not to be. That is the question".

Single Quotes vs. Double Quotes in PHP Strings

It is good practice when working PHP code to wrap stings in double quotes. Single quotes should be used when writing HTML code within PHP code since attribute values of HTML tags should be wrapped in double quotes as good coding practice.

See more examples of PHP Strings or go to Learn PHP for more tutorials.

Have fun coding!

Article Source: http://EzineArticles.com/?expert=Gagand ... gh_Tathgar

Share this topic on AskShare this topic on BlinkbitsShare this topic on BlinklistShare this topic on BloglinesShare this topic on BmarksShare this topic on Del.icio.usShare this topic on DiggShare this topic on DzoneShare this topic on FacebookShare this topic on Feed Me LinksShare this topic on FurlShare this topic on GoogleShare this topic on LiveShare this topic on MagnoliaShare this topic on MySpaceShare this topic on NetvouzShare this topic on NewsvineShare this topic on OneviewShare this topic on RedditShare this topic on RojoShare this topic on ScuttleShare this topic on ShadowsShare this topic on SlashdotShare this topic on SpurlShare this topic on SquidooShare this topic on StumbleUponShare this topic on TechnoratiShare this topic on TwitterShare this topic on TipdShare this topic on YahooShare this topic on Google buzz
« Last Edit: December 31, 1969, 05:00:00 PM by Tech » Logged

« Reply #1 on: April 30, 2010, 04:13:27 AM »
polardjohn Offline
Newbie

View Profile
*

iTrader: 0
Posts: 2



Here some basic examples of the concating a string,
Example 1 - Concatenating PHP Strings

<?php
$str1 = "I Love PHP.";
$str2 = "PHP is fun to learn.";
echo $str1." ".$str2;
?>
Logged

[
« Reply #2 on: December 22, 2011, 05:25:11 AM »
wilsondavid Offline
Newbie

View Profile
*

iTrader: 0
Posts: 5



There is no alternative way to create a string variable in PHP. Same like you have to create a variable ans assign it to string.

$str=" wel come to PHP ";

print(" $str ");
Logged

Pages: [1]   Go Up
Print
Jump to:  

Untitled Document
(c) 2010 HELM, WHM, cPanel, ASP, .Net development, PHP, MySQL, MSSQL Server, SEO support forum
Powered by SMF 1.1.16 | SMF © 2011, Simple Machines | Forum style designed by PixelSlot
Web Hosting - Sitemap - XML Sitemap