Use of backslash in php (Chapter 4) of Getting started with php

No Comments

php.net describes use of backslash perfectly

To specify a literal single quote, escape it with a backslash (\). To specify a literal backslash, double it (\\). All other instances of backslash will be treated as a literal backslash: this means that the other escape sequences you might be used to, such as \r or \n, will be output literally as specified rather than having any special meaning.

In between if you are interested in php learning check this post on php training in delhi. We provide both online and offline classes on php, drupal, wordpress training, SEO and HTML/CSS.

<?php
echo 'this is a simple string';

//output : You can also have embedded newlines in strings this way as it is okay to do but it wont add any line breaks.
echo 'You can also have embedded newlines in 
strings this way as it is
okay to do but it wont add any line breaks.';

// Outputs: Arnold once said: "I'll be back"
echo 'Arnold once said: "I\'ll be back"';

// Outputs: You deleted C:\*.*?
echo 'You deleted C:\\*.*?';

// Outputs: You deleted C:\*.*?
echo 'You deleted C:\*.*?';

// Outputs: This will not expand: \n a newline
echo 'This will not expand: \n a newline';

// Outputs: Variables do not $expand $either
echo 'Variables do not $expand $either';
?>

One more example on where to use \ in php. Actually I love posting quotes on my Websites and at the same time I love to read quotes by famous writers. Napoleon Hill Once Said

“what your mind can conceive and believe it can achieve”

What if i want to echo this in php

<?php

//Output : what your mind can conceive and believe it can achieve

echo "what your mind can conceive and believe it can achieve";


//Output : "what your mind can conceive and believe it can achieve"

echo "\"what your mind can conceive and believe it can achieve\"";

?>

A website developer, loves #wordpress #drupal #php. Love posting about wordpress, php, bootstrap and SEO. Also provide online/offline training on wordpress, drupal, php and SEO. I am available on Twitter @ anibabbar , Skype @anibabbar , gmail @anibabbar !! facebook @thinkncode.com

About us and this blog

We are a digital marketing company with a focus on helping our customers achieve great results across several key areas.

Request a free quote

We offer professional SEO services that help websites increase their organic search score drastically in order to compete for the highest rankings even when it comes to highly competitive keywords.

Subscribe to our newsletter!

Fields marked with an * are required
November 2019
M T W T F S S
« Sep    
 123
45678910
11121314151617
18192021222324
252627282930  

More from our blog

See all posts
No Comments