473,396 Members | 2,109 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Function Evaluation inside a literal.

Is there a way to have a function inside a literal string evaluated
similar to variable or array evaluation?

something similar to this?

$dt = "The order was sent ${date('F j, Y')}. Please make a note of it"

or do I have to create a variable first or concatenate the string.

Jun 26 '06 #1
3 1228
ImOk wrote:
or do I have to create a variable first or concatenate the string.


Besides creating a variable first, you have the following options:

$dt = 'The order was sent ' . date('F j, Y') . '. Please make a note of
it';

$dt = sprintf('The order was sent %s. Please make a note of it', date('F j,
Y'));
JW
Jun 26 '06 #2
Hmm..instead use sprintf or concatenate the string its better you
creating variable first.

$date_order = date ("F j, Y");
$dt = "The order was sent $date_order. Please make a note of it";

The concatenate method is faster then other methods but its difficult
to maintain.
The sprintf() function is slowest among this methods.. its better use
sprintf() if you want format complex string.

Read this : http://www.zend.com/zend/art/mistake.php

---
http://blog.deshot.com
http://www.mastervb.net
Janwillem Borleffs wrote:
ImOk wrote:
or do I have to create a variable first or concatenate the string.


Besides creating a variable first, you have the following options:

$dt = 'The order was sent ' . date('F j, Y') . '. Please make a note of
it';

$dt = sprintf('The order was sent %s. Please make a note of it', date('F j,
Y'));
JW


Jun 26 '06 #3
lorento wrote:
The sprintf() function is slowest among this methods.. its better use
sprintf() if you want format complex string.


True, although (s)printf is sometimes used in cases where readability is
preferred before performance (per example, when dynamically constructing a
complex SQL statement with a lot of variables) .
JW
Jun 26 '06 #4

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

Similar topics

1
by: David Furey | last post by:
Hi I have an XML documnet and a XSLT document as shown below THe XSLT document brings back a filtered docmument that has the VendorName that starts with a particular sub-string This works as...
18
by: Bryan Parkoff | last post by:
"#define" can only be inside the global scope before main() function. "#if" can be tested after "#define" is executed. The problem is that "#define" can't be inside main() function. I do not wish...
15
by: Jens.Toerring | last post by:
Hi, I have a possibly rather stupid question about the order of evaluation in a statement like this: result = foo( x ) - bar( y ); How can I make 100% sure that foo(x) is evaluated before...
14
by: emailscotta | last post by:
Some of the object properties in the Dojo Toolkit are set to objects but they are using syntax like this: object.property = new function() { this.property = someValue; this.property =...
3
by: Ben Voigt | last post by:
This smells like a bug to me, since literals are substituted at compile time. I'm using VS2005 SP1 beta. // literal_unmanaged.cpp : main project file. ref class TheClass { literal int...
28
by: Larax | last post by:
Best explanation of my question will be an example, look below at this simple function: function SetEventHandler(element) { // some operations on element element.onclick = function(event) {
7
by: VK | last post by:
I was getting this effect N times but each time I was in rush to just make it work, and later I coudn't recall anymore what was the original state I was working around. This time I nailed the...
5
by: Joakim Hove | last post by:
Hello, I have a function like this: /* It actually does something else .... */ void func (int size, const char ** string_list) { int i; for (i=0; i < size; i++) printf("String number %d:...
3
by: from.future.import | last post by:
Hi, I encountered garbage collection behaviour that I didn't expect when using a recursive function inside another function: the definition of the inner function seems to contain a circular...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
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,...

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.