473,788 Members | 2,784 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Difference between quotation and apostrophe in PHP

Difference between quotation and apostrophe in PHP

I wonder is there any difference between strings wrapped into
quotation marks or into apostrophes and if so is there any situation
when one is preferable to the other?
-R.
Dec 18 '07 #1
3 8123
On Dec 18, 9:50 am, Royan <romayan...@gma il.comwrote:
Difference between quotation and apostrophe in PHP

I wonder is there any difference between strings wrapped into
quotation marks or into apostrophes and if so is there any situation
when one is preferable to the other?
-R.
The difference is that you can use variables directly in double quoted
strings.

Try this, for example.

<?php

$rand = mt_rand (1, 1000000);

echo ('The random number value is $rand<br />');
echo ("The random number value is $rand<br />");

You can also use \n in a double quoted string to insert a newline, \t
to insert a tab, etc. You can't do this with single quoted strings.

This doesn't mean that single quoted strings are inferior. They don't
have the overhead associated with variable insertion so if you're
doing huge amounts of string manipulation then single quoted is
faster. Also, you don't have to escape the " character in single
quoted strings, and given that attributes in HTML and XML are meant to
be surrounded by " characters this can be a quite significant
advantage.
Dec 18 '07 #2
Royan wrote:
I wonder is there any difference between strings wrapped into quotation
marks or into apostrophes and if so is there any situation when one is
preferable to the other?
<?php

$greeting = 'Hello';

echo "$greeting World\n";
echo '$greeting World\n';

// Run this and note the difference.

?>

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 10 days, 21:14.]

Sharing Music with Apple iTunes
http://tobyinkster.co.uk/blog/2007/1...tunes-sharing/
Dec 18 '07 #3
On 18 Dec, 09:50, Royan <romayan...@gma il.comwrote:
Difference between quotation and apostrophe in PHP

I wonder is there any difference between strings wrapped into
quotation marks or into apostrophes and if so is there any situation
when one is preferable to the other?
-R.
But you didn't wonder quite enough to type:
php single double quote
into Google huh?

http://uk3.php.net/manual/en/language.types.string.php
Dec 18 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
9834
by: James Foreman | last post by:
I've got a set of emails in a table, where sometimes they've failed to input the @ properly. Eg james.foreman'abcmail.co.uk How do I write a replace to deal with that? Also, I've got a set of names in a table, all in lower case. I can easily capitalise the first letter of each name, but if it's somebody like O'Brien, I'd like to get that right too (so need to be able to
13
11440
by: Richard Hollenbeck | last post by:
To prevent future apostrophe bugs and errors, isn't it just simpler to forbid an apostrophe from being entered into a text field? For example, couldn't "Alice's Restaurant" be changed to "Alices Restaurant" etc. automatically and programmatically during data entry? This would eliminate my concatinated strings from producing errors when I base the string on a query. Think this is an example of the "Dreaded Apostrophe Bug." If I enter a...
9
2935
by: M P | last post by:
Hi! I am looking for a way that I can trap the single quotation mark. If an encoder uses single quotation mark on a textbox field, it always give me an error because I use single quotes on the SQL statement. Can you help trap this character not to produce error? Me
2
1896
by: VB Programmer | last post by:
In my dev environment the single quote/apostrophe shows up fine. When I publish the site all the single quotes are missing. Any ideas why? Is there a special character I have to use for the single quote?
9
6896
by: dajava | last post by:
Hi, Sorry for this beginner's question. I do not know PHP and write for my friend. He has never been a professional programmer. He studied C and PHP with some books and made a bulletin board for his hobby homepage. (He uses MS-Windows XP)
31
4894
by: The Bicycling Guitarist | last post by:
Hi. For many years I have been using &quot; for double quotation marks in the HTML code, but the opening and closing quotation marks render the same in my browser. I'm considering going through and using &ldquo; and &rdquo; (in pairs as needed) instead. Are there any *disadvantages* to doing so, besides the time it will take to make the change? Thanks.
9
3599
by: Thomas 'PointedEars' Lahn | last post by:
Jukka K. Korpela wrote: IBTD. For example, in English it is customary (and AIUI expected) to use the character that ’ represents should be used to delimit a quotation within direct speech (which itself should be delimited by “ and ”. (I gathered that from reading several English books.) I think you would agree that it would make especially English text with quotations in direct speech (say, in a novel where one person tells another...
3
6820
by: Alan Mailer | last post by:
Ok, I've looked for an answer for this, because I'm sure it's been asked a thousand times... but no luck... so here goes. Imagine I want to create a NodeList based on an XPath statement. The 'query' portion of that statement wants to search for the following value: Joe's Garage ....now please note the APOSTROPHE in the above string.
3
7479
by: Aisya | last post by:
Hye, I need help to overcome the problem mention above. My application needs user to key in their details, but when it comes to name some names has an apostrophe, somehow it's okay to save the data with apostrophe because through my observation, the system read from the database not the one that was keyed in by the user. For example, in the database already has a name "Alex" ... The one that just keyed in (edit) by the user " Alex'is" ......
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10177
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10118
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9969
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8995
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5403
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5538
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.