-4

Possible Duplicate:
PHP String concatenation - “$a $b” vs $a . “ ” . $b - performance

<?php
    $url = 'http://www.google.com/';

    //case 1
    $case1 = 'The URL is '.$url.'.';

    //case 2
    $case2 = "The URL is $url.";

    //case 3
    $case3 = 'The URL is {url}.';
    $case3 = str_replace('{url}', $url, $case3);
?>

Thank you!

Community
  • 1
  • 1
BRAVO
  • 233
  • 1
  • 4
  • 12
  • It would be nearly trivial to try and find out yourself. – JJJ Jul 20 '11 at 09:26
  • 4
    *We should forget about small efficiencies, say about 97% of the time:* ***premature optimization is the root of all evil***. *Yet we should not pass up our opportunities in that critical 3%. A good programmer will not be lulled into complacency by such reasoning, he will be wise to* ***look carefully at the critical code; but only after that code has been identified”*** *- Donald Knuth* – Gordon Jul 20 '11 at 09:27

1 Answers1

2

case 1 and 2 are basically the same (don't worry about your 2 nanoseconds lost) – i think there are questions on SO covering this issue. case 3 is probably slower due to string search and replacement. if you really want to know, profile all three cases.

knittl
  • 246,190
  • 53
  • 318
  • 364