473,554 Members | 3,624 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 8115
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
9806
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...
13
11376
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...
9
2927
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
1892
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
6877
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
4844
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?...
9
3590
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...
3
6811
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
7464
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...
0
7539
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...
1
7581
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...
0
7897
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...
0
6170
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...
1
5446
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5165
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...
0
3589
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...
0
3566
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2030
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.