By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,462 Members | 799 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,462 IT Pros & Developers. It's quick & easy.

Function Evaluation inside a literal.

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.