Logo Tutorials, Ebooks, Source Codes, Question Bank
Submit your Email ID & receive intimation about New/Updated Contents :
Advertise with us             CONTACT US
Android MobilesHTC MobilesMicromax MobilesMobile ArticlesMobile TermsNokia MobilesSamsung MobilesSony MobilesTablets
108 Names of GodBhajans CHALISA CollectionDevi Maa Ki AartiyanGanesh Ji Ki AartiyanHanuman Ji Ki AartiyanRadha Krishan Ji Ki AartiyanRam Ji Ki AartiyanSai Baba Ji Ki AartiyanShiv Ji Ki AartiyanTemples in IndiaVishnu Ji Ki Aartiyan
Wallpapers Pack
Bollywood FlashsFestival FlashsFlash GamesFlash MessagesFunny FlashsPatriotic FlashsPolitical FlashsSpiritual Flashs
FunStuffJokesRajnikanth JokesWhats App JokesWhats App Messages
About IndiaGeneral Knowledge Hindi RhymesMythological StoriesNursery RhymesPatriotic SongsRiddlesShort StoriesTongue Twisters
Funny SlideshowsInteresting SlideshowsMessage SlideshowsNice SlideshowsPatriotic SlideshowsSpiritual Slideshows
BirthDay SMSChristmas SMSClassic SMSFathers Day SMSFestivals SMSFriendship SMSFunny SMSHoli SMSHusbandWife SMSIndependenceDay SMSLohri SMSLove SMSMorning SMSMothers Day SMSNew Year SMSNight SMSPoetry SMSPunjabi SMSRakhi SMSSanta Banta SmSTeachers Day SMSTimePass SMSValentine Day SMS
3D WallpapersAbstract_WallpapersAnimated_WallpapersApple_Mac_WallpapersBaby_WallpapersBackGroundsBeach WallpapersBirds WallpapersCars WallpapersCartoon_WallpapersChristmas WallpapersColorFul_WallpapersColoringSheetsCool_WallpapersFish_WallpapersFlagsFlash TattoosFlowersFunny WallpapersGalleryGodsGreen_ScenesHD_High_ResolutioniPhone WallPapersLinux_WallpapersMobile_WallpapersMortality WallpapersMountain_WallpapersNatureOptical_IllusionsRosesSea_WallpapersShips WallpapersSports_GamesUltraBeautiful WallpaperValentine WallpapersVehiclesWideScreen WallpapersWildLife WallpapersWindows VistaWindowsXPWindows_7_Wallpapers
AJAX ASP.Net 2.0/3.5 C# / C-Sharp C/C++ Cryptography Data Compression Data Structures FLASH Foxpro/VFP HTML JAVA Java Scripts JSP LINUX Microsoft Office Microsoft Windows MS XNA PHP/MySQL Silverlight Software Engineering SQL SQL Server 2005 UNIX VB.Net 2005 VBScript XML
Home Search

PHP - Working with Variables in PHP

As with any other programming languages, PHP allows to define variables. In PHP there are many variable types,but the most common among them is a String variable.

String Variable
A String variable holds text and numbers. All strings begin with a symbol "$". To assign some text to the string you can use the following code:
$welcome_text = "Hello and welcome to AllFree-Stuff.com";
Strings are case sensetive so the string variable $Welcome_Text is not the same as $welcome_text A string name can contain letters, underscores and numbers. but it should not begin with a number or underscore. When assigning numbers to the string variables you need not include the quotes so:
$user_id = 987
would be allowed.

How to display the Variable.
We use exactly the same code to display a variable on the screen, as we used to display the text. But slightly different form. The following code would display the welcome text:
$welcome_text = "Hello and welcome to AllFree-Stuff.com ";
As you can see, the only major difference is that you need not put the quotation marks if you are printing a variable.

How to format the Text?
Output from your PHP programs is quite boring unfortunately. All the content is just output in the browser's default font. It is easy, to format your text using HTML. This is because, as we know that the PHP is a server side scripting language, code is been executed before the page is sent to browser. This means, only the resulting information from script is sent, so in the above example, the browser would just sent the text:
Hello and welcome to AllFree-Stuff.com
This means, that you can include standard HTML markup in your strings and scripts. The problem with this is that many HTML tags require the " symbol. You may notice that this symbol will clash with the quotation marks used to print the text. To overcome this confusion you must tell the script which quotes to be used (those at the beginning and end of the output) and which to be ignored (those of the HTML code).

How to solve this problem?
To illustrate this let us consider the example, Change the font of the text to the Arial font in red. The code for this is as follows.

As you can see this code contains 4 quotation marks so can confuse the script. To solve this you must add a backslash before each quotation mark to make the PHP script ignore it. Then the code would look like.

Now you can include this in your print statement,which will make the browser display it.
print("Hello and welcome to AllFree-Stuff.com ");
Output:Hello and welcome to AllFree-Stuff.com

allfree-stuff.com - Free Education for ALL - for any queries contact @ webmaster@allfree-stuff.com