Re: [PHP] concatenating

2011-08-11 Thread Andre Polykanine

Hello Chris,

  

CS Is it possible to concatenate a string and an element from a
CS mysql_fetch_assoc array? I haven't had much luck searching google.

CS Such as concatenating results with ' . $posts_row['store_tptest'] .
CS ' so that if there are no elements returned nothing will be displayed?

if (!empty($posts_row['store_tptest'])) $str=results 
.$posts_rows['store_tptest'];
-- 
With best regards from Ukraine,
Andre
Skype: Francophile
My blog: http://oire.org/menelion (mostly in Russian)
Twitter: http://twitter.com/m_elensule
Facebook: http://facebook.com/menelion


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] concatenating

2011-08-10 Thread Negin Nickparsa
read the manual
http://www.php.net/manual/en/ref.strings.php
A comprehensive concatenation function, that works with array and strings

?php
function str_cat() {
  $args = func_get_args() ;

  // Asserts that every array given as argument is $dim-size.
  // Keys in arrays are stripped off.
  // If no array is found, $dim stays unset.
  foreach($args as $key = $arg) {
if(is_array($arg)) {
  if(!isset($dim))
$dim = count($arg) ;
  elseif($dim != count($arg))
return FALSE ;
  $args[$key] = array_values($arg) ;
}
  }

  // Concatenation
  if(isset($dim)) {
$result = array() ;
for($i=0;$i$dim;$i++) {
  $result[$i] = '' ;
  foreach($args as $arg)
$result[$i] .= ( is_array($arg) ? $arg[$i] : $arg ) ;
}
return $result ;
  } else {
return implode($args) ;
  }
}
?

A simple example :

?php
str_cat(array(1,2,3), '-', array('foo' = 'foo', 'bar' = 'bar', 'noop' =
'noop')) ;
?

will return :
Array (
  [0] = 1-foo
  [1] = 2-bar
  [2] = 3-noop
)

More usefull :

?php
$myget = $_GET ; // retrieving previous $_GET values
$myget['foo'] = 'b a r' ; // changing one value
$myget = str_cat(array_keys($myget), '=', array_map('rawurlencode',
array_values($myget))) ;
$querystring = implode(ini_get('arg_separator.output'), $myget)) ;
?

will return a valid querystring with some values changed.

Note that ?php str_cat('foo', '', 'bar') ; ? will return 'foobar',
while ?php str_cat(array('foo'), '', 'bar') ; ? will return array(0 =
foobar)
*t0russ at gmail dot com* 14-Jun-2005
05:38http://www.php.net/manual/en/ref.strings.php#53834
to kristin at greenaple dot on dot ca:
thanx for sharing.
your function in recursive form proved to be slightly faster and it returns
false (as it should) when the character is not found instead of number 0:
?php
function strnposr($haystack, $needle, $occurance, $pos = 0) {
return ($occurance2)?strpos($haystack, $needle,$pos):strnposr($haystack
,$needle,$occurance-1,strpos($haystack, $needle, $pos) + 1);
}
?


Re: [PHP] concatenating

2011-08-10 Thread Ken Robinson

At 12:03 AM 8/11/2011, Chris Stinemetz wrote:

Is it possible to concatenate a string and an element from a
mysql_fetch_assoc array? I haven't had much luck searching google.

Such as concatenating results with ' . $posts_row['store_tptest'] .
' so that if there are no elements returned nothing will be displayed?


Sure, do something like this:

?php
  echo ($posts_row['store_tptest'] != '')?results 
{$posts_row['stor_tptest']}:'';

?

Ken 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Concatenating PDF using FPDI

2008-09-29 Thread giga501

Bastien  - 

Thanks for the tip. 

I tried setting auto_detect_line_endings=ON on my PHP.ini file (I am on a
shared host - siteground), but the problem persists. The
auto_detect_line_endings parameter on my local machine is OFF. 



Bastien Koert-3 wrote:
 
 On Sun, Sep 28, 2008 at 3:33 AM, giga501 wrote:
 

 Hi -

 I am trying to attach a pre-defined PDF to a file generated at runtime
 (invoice.pdf).
 I have attached the test.php that I used to concatenate 2 pdfs.
 http://www.nabble.com/file/p19709464/test.php test.php

 I have also verified that I have the latest version of FPDF and FPDI.
 However, here is the error I get on executing the file on my server
 (shared
 host using CPanel) :
 FPDF error: Unable to find xref table - Maybe a Problem with
 'auto_detect_line_endings'

 The functionality works fine on my localhost (WAMPServer, WinXP), so I am
 wondering if there are any other server parameters to look at ?

 Any ideas on what is wrong here? Thanks in advance.
 --
 View this message in context:
 http://www.nabble.com/Concatenating-PDF-using-FPDI-tp19709464p19709464.html
 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


 Its a setting in the php.ini file that may need to be changed. Line
 endings
 change from Winblows to Unix/Linux servers, so it may need to be reset
 
 
 

-- 
View this message in context: 
http://www.nabble.com/Concatenating-PDF-using-FPDI-tp19709464p19722844.html
Sent from the PHP - General mailing list archive at Nabble.com.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Concatenating PDF using FPDI

2008-09-28 Thread Bastien Koert
On Sun, Sep 28, 2008 at 3:33 AM, giga501 [EMAIL PROTECTED] wrote:


 Hi -

 I am trying to attach a pre-defined PDF to a file generated at runtime
 (invoice.pdf).
 I have attached the test.php that I used to concatenate 2 pdfs.
 http://www.nabble.com/file/p19709464/test.php test.php

 I have also verified that I have the latest version of FPDF and FPDI.
 However, here is the error I get on executing the file on my server (shared
 host using CPanel) :
 FPDF error: Unable to find xref table - Maybe a Problem with
 'auto_detect_line_endings'

 The functionality works fine on my localhost (WAMPServer, WinXP), so I am
 wondering if there are any other server parameters to look at ?

 Any ideas on what is wrong here? Thanks in advance.
 --
 View this message in context:
 http://www.nabble.com/Concatenating-PDF-using-FPDI-tp19709464p19709464.html
 Sent from the PHP - General mailing list archive at Nabble.com.


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


Its a setting in the php.ini file that may need to be changed. Line endings
change from Winblows to Unix/Linux servers, so it may need to be reset

-- 

Bastien

Cat, the other other white meat


Re: [PHP] concatenating with . or ,

2008-08-27 Thread Bernhard Kohl
tedd wrote:
 There are significant orders of magnitude difference between your results
 and mine.
 For example, it didn't make any difference if you used a comma or
 concatenation, but in my system concatenation was 15 times faster than using
 a comma. Interesting, I would have guessed it would have been the other way
 around.

I refined the test, so that it is more random and therefore maybe more accurate.

Test Results
Results for 2048 cycles of echoing a 32-character string with a random
32-character string 2048 times:
comma Method

Number of Echoes: 536

Total time: 1.57938525391 milliseconds

Average time: 0.00294661427968 milliseconds
concat Method

Number of Echoes: 537

Total time: 2.64919824219 milliseconds

Average time: 0.0049005994 milliseconds
interpol Method

Number of Echoes: 480

Total time: 4.38319873047 milliseconds

Average time: 0.00913166402181 milliseconds
heredoc Method

Number of Echoes: 495

Total time: 3.66322021484 milliseconds

Average time: 0.00740044487847 milliseconds
Results for echoing 128 random 32-character string 2048 times:
comma Method

Number of Echoes: 536

Total time: 817.227 milliseconds

Average time: 1.52467723881 milliseconds
concat Method

Number of Echoes: 537

Total time: 826.971 milliseconds

Average time: 1.53998324022 milliseconds
interpol Method

Number of Echoes: 480

Total time: 3764.781 milliseconds

Average time: 7.84329375 milliseconds
heredoc Method

Number of Echoes: 495

Total time: 540.391 milliseconds

Average time: 1.0916989899 milliseconds

--
For all those who want to try it out, here is the code:
--

!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd;
html xmlns=http://www.w3.org/1999/xhtml;
head
meta http-equiv=Content-Type content=text/html; charset=utf-8 /
titleTest for Tedd/title
/head
body style=font-size: small;
h1Test Results/h1
?php
global $iterations, $results, $test_string;
$iterations = 2048;
$iterations2 = 128; // iterations for 2nd test
$results1 = array(
  comma = array(total_time = 0, count = 0),
  concat = array(total_time = 0, count = 0),
  interpol = array(total_time = 0, count = 0),
  heredoc = array(total_time = 0, count = 0)

);
$results2 = $results1;
$test_array = array();
$test_string = md5(time()); // a 32 character string
$eval_strings = create_eval_strings();
for ($i = 0; $i  $iterations; ++$i) $test_array[] =
str_shuffle($test_string); // random strings
for ($i = 0; $i  $iterations; ++$i) test_method(rand(0,3));

function test_method($method) {
  $start_time = $end_time = 0;
  $test_array = $GLOBALS['test_array'];
  $test_string = $GLOBALS['test_string'];
  $eval_strings = $GLOBALS['eval_strings'];
  for ($i = 0; $i  10; ++$i) {
$j = rand(0, $GLOBALS['iterations']);
$test_array[$j] = str_shuffle($test_array[$j]); // change some arr
vals to outsmart any php speedup/cache
  }
  $arr2 = array(); // array for 2nd test
  for ($i = 0; $i  $GLOBALS['iterations2']; ++$i) $arr2[] =
$test_array[rand(0, $GLOBALS['iterations'])];
  # 1st test will output # of iterations random strings
  # 2nd test will output a sequence of #iterations2 random strings
  switch ($method) {
case 0: // comma
  # - TEST 1 -
  ob_start();
  $start_time = microtime(true);
  foreach ($test_array as $array_value) {
 echo $test_string, $array_value;
  }
  $end_time = microtime(true);
  ob_end_clean();
  $GLOBALS[results1][comma][total_time] += abs($end_time -
$start_time)*1000/$GLOBALS[iterations];
  ++$GLOBALS[results1][comma][count];
  # - TEST 2 -
  ob_start();
  $start_time = microtime(true);
  eval($eval_strings['comma']);
  $end_time = microtime(true);
  ob_end_clean();
  $GLOBALS[results2][comma][total_time] += abs($end_time -
$start_time)*1000;
  ++$GLOBALS[results2][comma][count];
  break 1;
case 1: // concatenation
  # - TEST 1 -
  ob_start();
  $start_time = microtime(true);
  foreach ($test_array as $array_value) {
 echo $test_string.$array_value;
  }
  $end_time = microtime(true);
  ob_end_clean();
  $GLOBALS[results1][concat][total_time] += abs($end_time -
$start_time)*1000/$GLOBALS[iterations];
  ++$GLOBALS[results1][concat][count];
  # - TEST 2 -
  ob_start();
  $start_time = microtime(true);
  eval($eval_strings['concat']);
  $end_time = microtime(true);
  ob_end_clean();
  echo $eval_string.\n;
  $GLOBALS[results2][concat][total_time] += abs($end_time -
$start_time)*1000;
  ++$GLOBALS[results2][concat][count];
  break 1;
case 2: // interpolation
  # - TEST 1 -
  ob_start();
  $start_time = microtime(true);
  foreach ($test_array as $array_value) {
 echo 

Re: [PHP] concatenating with . or ,

2008-08-27 Thread tedd

At 7:56 PM -0600 8/26/08, Govinda wrote:
I never thanked all the people who answered my Q in so many helpful 
ways and on so many levels.I see that this list if chock full of 
really quality people with loads of expertise and many other fine 
qualities (tedd sperling's broad perspective, for one) ...  I would 
be tempted to thank people all the time for so many things.  What to 
do?


-G


Hey guys!

We fooled another one.  :-)

Cheers,

tedd

PS: As for me -- thanks, but I'm not the smart one on this list -- 
just the best looking. :-)


--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] concatenating with . or ,

2008-08-27 Thread Robert Cummings
On Wed, 2008-08-27 at 12:27 +0200, Bernhard Kohl wrote:
 tedd wrote:
  There are significant orders of magnitude difference between your results
  and mine.
  For example, it didn't make any difference if you used a comma or
  concatenation, but in my system concatenation was 15 times faster than using
  a comma. Interesting, I would have guessed it would have been the other way
  around.
 
 I refined the test, so that it is more random and therefore maybe more 
 accurate.

What does random have to do with the echo, concatenaton, interpolation,
or heredoc functionality? I would presume these to be mutually
exclusive. As such your test adds noise to the problem and is more than
likely less accurate.

 --
 For all those who want to try it out, here is the code:
 --
 
 !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN
 http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd;
 html xmlns=http://www.w3.org/1999/xhtml;
 head
 meta http-equiv=Content-Type content=text/html; charset=utf-8 /
 titleTest for Tedd/title
 /head
 body style=font-size: small;
 h1Test Results/h1
 ?php
 global $iterations, $results, $test_string;
 $iterations = 2048;
 $iterations2 = 128; // iterations for 2nd test
 $results1 = array(
   comma = array(total_time = 0, count = 0),
   concat = array(total_time = 0, count = 0),
   interpol = array(total_time = 0, count = 0),
   heredoc = array(total_time = 0, count = 0)
 
 );

An array? You do realize that arrays are stored as some kind of tree
with O( lg n ) lookup? This means that it WILL take longer to access
some of those entries than it does for others. They can't all be sitting
at the root node of the tree. These tests shoul dhave been run
individually.

 $results2 = $results1;
 $test_array = array();
 $test_string = md5(time()); // a 32 character string
 $eval_strings = create_eval_strings();
 for ($i = 0; $i  $iterations; ++$i) $test_array[] =
 str_shuffle($test_string); // random strings

Aggain I'd like to point out that randomizing the string more than
likely does nothing for the benchmark.

 for ($i = 0; $i  $iterations; ++$i) test_method(rand(0,3));

A function call... to a less than simplistic function (yes simple
logically, complex when benchmarks should normally be run on the
simplest representation of the problem).

 function test_method($method) {
   $start_time = $end_time = 0;
   $test_array = $GLOBALS['test_array'];
   $test_string = $GLOBALS['test_string'];
   $eval_strings = $GLOBALS['eval_strings'];
   for ($i = 0; $i  10; ++$i) {
 $j = rand(0, $GLOBALS['iterations']);
 $test_array[$j] = str_shuffle($test_array[$j]); // change some arr
 vals to outsmart any php speedup/cache
   }
   $arr2 = array(); // array for 2nd test
   for ($i = 0; $i  $GLOBALS['iterations2']; ++$i) $arr2[] =
 $test_array[rand(0, $GLOBALS['iterations'])];
   # 1st test will output # of iterations random strings
   # 2nd test will output a sequence of #iterations2 random strings
   switch ($method) {
 case 0: // comma
   # - TEST 1 -
   ob_start();
   $start_time = microtime(true);
   foreach ($test_array as $array_value) {
echo $test_string, $array_value;
   }
   $end_time = microtime(true);
   ob_end_clean();
   $GLOBALS[results1][comma][total_time] += abs($end_time -
 $start_time)*1000/$GLOBALS[iterations];
   ++$GLOBALS[results1][comma][count];
   # - TEST 2 -
   ob_start();
   $start_time = microtime(true);
   eval($eval_strings['comma']);
   $end_time = microtime(true);
   ob_end_clean();
   $GLOBALS[results2][comma][total_time] += abs($end_time -
 $start_time)*1000;
   ++$GLOBALS[results2][comma][count];
   break 1;

Do you mind if I scream here... output buffering, eval, internal
microtime function to measure the efficiency of multiple different
approaches? These are all going to add to the noise. You should use the
system's time command to determine actual time spent on the process.


 case 1: // concatenation
   # - TEST 1 -
   ob_start();
   $start_time = microtime(true);
   foreach ($test_array as $array_value) {
echo $test_string.$array_value;
   }
   $end_time = microtime(true);
   ob_end_clean();
   $GLOBALS[results1][concat][total_time] += abs($end_time -
 $start_time)*1000/$GLOBALS[iterations];
   ++$GLOBALS[results1][concat][count];
   # - TEST 2 -
   ob_start();
   $start_time = microtime(true);
   eval($eval_strings['concat']);
   $end_time = microtime(true);
   ob_end_clean();
   echo $eval_string.\n;
   $GLOBALS[results2][concat][total_time] += abs($end_time -
 $start_time)*1000;
   ++$GLOBALS[results2][concat][count];
   break 1;
 case 2: // interpolation
   # - TEST 1 -
   

Re: [PHP] concatenating with . or ,

2008-08-27 Thread tedd

At 12:17 PM -0400 8/27/08, Robert Cummings wrote:

What does random have to do with


Oh no!

Someone mentioned the R word in front of Rob.

We should put this in a list of things not to do on this list.

Cheers,

tedd


--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] concatenating with . or ,

2008-08-27 Thread Robert Cummings
On Wed, 2008-08-27 at 13:13 -0400, tedd wrote:
 At 12:17 PM -0400 8/27/08, Robert Cummings wrote:
 What does random have to do with
 
 Oh no!
 
 Someone mentioned the R word in front of Rob.
 
 We should put this in a list of things not to do on this list.

*heheh* well in the above I'm not so concerned about the issue of random
itself, but more about how it doesn't benefit the particular issue being
benchmarked. Random (or pretend random depending on your randomly
religious views ;) is certainly useful in some benchmarks... for
instance testing the speed of a new sorting algorithm, or tree
algorithm, etc when a broad data sample is necessary.

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] concatenating with . or ,

2008-08-26 Thread tedd

At 10:37 PM +0200 8/25/08, Bernhard Kohl wrote:

# Ok tedd, if you insist ..


Bernhard:

I wasn't insisting, but it's nice you picked up the Gauntlet.

Good work and it validates (but of course, you didn't think I would check?).

Your results:

Comma took: 0.0191585 milliseconds on average.
Concatenation: 0.0195376 milliseconds on average.
Interpolation: 0.0279227 milliseconds on average.
Heredoc: 0.0247411 milliseconds on average.

My results:

Comma took: 0.017329251766205 milliseconds on average.
Concatenation: 0.0011050462722778 milliseconds on average.
Interpolation: 0.0017022013664246 milliseconds on average.
Heredoc: 0.0035961031913757 milliseconds on average.

There are significant orders of magnitude difference between your 
results and mine.


For example, it didn't make any difference if you used a comma or 
concatenation, but in my system concatenation was 15 times faster 
than using a comma. Interesting, I would have guessed it would have 
been the other way around.


However in both, the end-user will never notice any difference unless 
we are showing them over 50,000 commas and then the time it would 
take the browser to show 50,000 commas will completely mask the one 
second of server-side time required to provide that.


I predict in the near future, considering that cpu speed is 
increasing and storage v cost is deceasing almost exponentially, 
newer programmers will not even concern themselves with speed/storage 
issues.


Similarity, current programmers in their 20's when reaching 50 will 
be hearing younger programmers ask What's caching?


The cycle of programming continues.

Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] concatenating with . or ,

2008-08-26 Thread Lupus Michaelis

tedd a écrit :


The cycle of programming continues.


  And the algorithm era crunch down ;) The test isn't accurate because 
it focuses on two strings of the same length. And all programmers know 
that some algorithms depends on the size of the data handled, and the 
number of it.


  Obviously, parameters method of echo must be faster than 
concatenation method. If it isn't, we are in the window that is better, 
or they are a problem, or an optimization ;)
  The reason is PHP make an allocation of a new string when concat that 
equal to the size of the two strings, and copy strings content into the 
new allocate memory zone. So if you just echo, it allocates the memory 
just needed to copy in the echoed string.


  So said, benchmarks must be make with a good knoledge of what you're 
handling, although you can't do a good one. For example, I can't make a 
benchmark on english as you can see ;)

--
Mickaël Wolff aka Lupus Michaelis
http://lupusmic.org

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] concatenating with . or ,

2008-08-26 Thread Robert Cummings
On Tue, 2008-08-26 at 12:07 -0400, tedd wrote:
 At 10:37 PM +0200 8/25/08, Bernhard Kohl wrote:
 # Ok tedd, if you insist ..
 
 Bernhard:
 
 I wasn't insisting, but it's nice you picked up the Gauntlet.
 
 Good work and it validates (but of course, you didn't think I would check?).
 
 Your results:
 
 Comma took: 0.0191585 milliseconds on average.
 Concatenation: 0.0195376 milliseconds on average.
 Interpolation: 0.0279227 milliseconds on average.
 Heredoc: 0.0247411 milliseconds on average.
 
 My results:
 
 Comma took: 0.017329251766205 milliseconds on average.
 Concatenation: 0.0011050462722778 milliseconds on average.
 Interpolation: 0.0017022013664246 milliseconds on average.
 Heredoc: 0.0035961031913757 milliseconds on average.

Did you echo the resulting concatenation? Concatenation is surely going
to be faster than output... but we're talking about output of data via
argument list versus output of data that is first concatenated. It was
already ascertained earlier that commas are ONLY useful for echo and
print situations... so bearing that in mind did you echo your
concatenated result when benchmarking concatenation?

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] concatenating with . or ,

2008-08-26 Thread Yeti
 Bernhard wrote:
 echo $test_string, $array_value;

It seems like they echoed them

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] concatenating with . or ,

2008-08-26 Thread Govinda


I never thanked all the people who answered my Q in so many helpful  
ways and on so many levels.I see that this list if chock full of  
really quality people with loads of expertise and many other fine  
qualities (tedd sperling's broad perspective, for one) ...  I would be  
tempted to thank people all the time for so many things.  What to do?


-G
for 'gratitude'  and Govinda

Oone is a concatenated string, the other is arguments. Arguments are  
executed and output in order, whereas the concatenation causes the  
function calls to be executed first and then the echo to display the  
return values concatenated into a single string.



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] concatenating with . or ,

2008-08-26 Thread Robert Cummings
On Tue, 2008-08-26 at 19:56 -0600, Govinda wrote:
 
 I never thanked all the people who answered my Q in so many helpful  
 ways and on so many levels.I see that this list if chock full of  
 really quality people with loads of expertise and many other fine  
 qualities (tedd sperling's broad perspective, for one) ...  I would be  
 tempted to thank people all the time for so many things.  What to do?

I take cheques :B

But seriously, I think you'll find many are happy enough to see
something like this response itself.

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] concatenating with . or ,

2008-08-25 Thread Thiago Melo de Paula
Govinda,

please, consider the following code:

?php
$brandA = 'Porshe';
$brandB = 'Jaguar';

$testA = $branA . $brandB; //testA will have the value PorsheJaguar

$testB = $branA , $brandB; //Returns a Parse error: syntax error, unexpected
',' in /test.php on line 7
?

With that, you can see that the comma isn't a concatenation symbol as the
period.

When you use it with echo, you're actually passing more than one argument to
the echo construct (why construct and not function? please, refer to
http://us.php.net/manual/en/function.echo.php to get more details).

My 2 cents on this great list.

Regards from Brazil.

Thiago Melo de Paula

On Mon, Aug 25, 2008 at 1:27 AM, Govinda wrote:

 easy to find our about concatenating with . in the docs...
 but not so with ,

 what is the difference?



Re: [PHP] concatenating with . or ,

2008-08-25 Thread Andreas J.

hi,
here it is described in detail:
http://blog.libssh2.org/index.php?/archives/28-How-long-is-a-piece-of-string.html

Govinda schrieb:

easy to find our about concatenating with . in the docs...
but not so with ,

what is the difference?



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] concatenating with . or ,

2008-08-25 Thread Govinda

Good, understood.

To deepen (for me):

why does this:
echo 'p$_POST[\'SNGstep\']='.var_dump($_POST['SNGstep']).'^/p'.\n;
spit out:
NULL
p$_POST['SNGstep']=^/p

while this:
echo 'p$_POST[\'SNGstep\']=',var_dump($_POST['SNGstep']),'^/p'.\n;
spits out:
p$_POST['SNGstep']=NULL
^/p

?

I think it must be related to something Maciek was showing in his  
excellent example, but I am too green to see.



On Aug 25, 2008, at 7:48 AM, Thiago Melo de Paula wrote:


Govinda,

please, consider the following code:

?php
$brandA = 'Porshe';
$brandB = 'Jaguar';

$testA = $branA . $brandB; //testA will have the value PorsheJaguar

$testB = $branA , $brandB; //Returns a Parse error: syntax error,  
unexpected

',' in /test.php on line 7
?



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] concatenating with . or ,

2008-08-25 Thread Stut

On 25 Aug 2008, at 16:09, Govinda wrote:

Good, understood.

To deepen (for me):

why does this:
echo 'p$_POST[\'SNGstep\']='.var_dump($_POST['SNGstep']).'^/ 
p'.\n;

spit out:
NULL
p$_POST['SNGstep']=^/p

while this:
echo 'p$_POST[\'SNGstep\']=',var_dump($_POST['SNGstep']),'^/ 
p'.\n;

spits out:
p$_POST['SNGstep']=NULL
^/p

?

I think it must be related to something Maciek was showing in his  
excellent example, but I am too green to see.


Oone is a concatenated string, the other is arguments. Arguments are  
executed and output in order, whereas the concatenation causes the  
function calls to be executed first and then the echo to display the  
return values concatenated into a single string.


Because var_dump *outputs* stuff rather than returning it, in the  
concatenation version the NULL outputs before the rest of the string.


Hope that clears it up.

-Stut

--
http://stut.net/


On Aug 25, 2008, at 7:48 AM, Thiago Melo de Paula wrote:


Govinda,

please, consider the following code:

?php
$brandA = 'Porshe';
$brandB = 'Jaguar';

$testA = $branA . $brandB; //testA will have the value PorsheJaguar

$testB = $branA , $brandB; //Returns a Parse error: syntax error,  
unexpected

',' in /test.php on line 7
?



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] concatenating with . or ,

2008-08-25 Thread Yeti
That is why i love this list. Always something new to learn.
What I am still wondering about is if it is faster to use commas or
the {} brackets? ( I don't know how that technique is called, since
I'm not a walking dictionary)

Example:

$var = blah blah;
echo $var,test;
echo {$var}test;

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] concatenating with . or ,

2008-08-25 Thread Robert Cummings
On Mon, 2008-08-25 at 17:34 +0200, Yeti wrote:
 That is why i love this list. Always something new to learn.
 What I am still wondering about is if it is faster to use commas or
 the {} brackets? ( I don't know how that technique is called, since
 I'm not a walking dictionary)

Here is the order of speed from fastest to slowest:

commas  - only useful if using echo or print
.   - concatenation
{$foo}- interpolation of variables via double quotes
 - heredoc

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] concatenating with . or ,

2008-08-25 Thread tedd

At 5:34 PM +0200 8/25/08, Yeti wrote:

That is why i love this list. Always something new to learn.
What I am still wondering about is if it is faster to use commas or
the {} brackets? ( I don't know how that technique is called, since
I'm not a walking dictionary)

Example:

$var = blah blah;
echo $var,test;
echo {$var}test;


One of the other things about this list is that sometimes people 
actually test their ideas.


It's not that big of a deal to set up a test to show which is faster. 
So, if you would like to know, then write a test for it.


Cheers,

tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] concatenating with . or ,

2008-08-25 Thread Bernhard Kohl
!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd;
html xmlns=http://www.w3.org/1999/xhtml;
head
meta http-equiv=Content-Type content=text/html; charset=utf-8 /
titleTest for Tedd/title
/head
body
?php

# Ok tedd, if you insist ..

$iterations = 2;
$test_string = md5('test'); // a 32 character string
$test_array = array();
for ($i = 0; $i  $iterations; ++$i) $test_array[] = str_shuffle($test_string);
# - Comma
ob_start();
$s_t = microtime(true);
foreach ($test_array as $array_value) {
echo $test_string, $array_value;
}
$e_t = microtime(true);
ob_end_clean();
echo 'pComma took: strong'.(abs($e_t -
$s_t)*1000/$iterations).'/strong milliseconds on average./p';
# -- Concatenation
ob_start();
$s_t = microtime(true);
foreach ($test_array as $array_value) {
echo $test_string.$array_value;
}
$e_t = microtime(true);
ob_end_clean();
echo 'pConcatenation: strong'.(abs($e_t -
$s_t)*1000/$iterations).'/strong milliseconds on average./p';
# -- Interpolation
ob_start();
$s_t = microtime(true);
foreach ($test_array as $array_value) {
echo {$test_string}{$array_value};
}
$e_t = microtime(true);
ob_end_clean();
echo 'pInterpolation: strong'.(abs($e_t -
$s_t)*1000/$iterations).'/strong milliseconds on average./p';
# -- HereDoc
ob_start();
$s_t = microtime(true);
foreach ($test_array as $array_value) {
   echo TEST
$test_string$array_value
TEST;
}
$e_t = microtime(true);
ob_end_clean();
echo 'pHeredoc: strong'.(abs($e_t -
$s_t)*1000/$iterations).'/strong milliseconds on average./p';
/*
I usually get results similar to these ones:

Comma took: 0.0191585 milliseconds on average.
Concatenation: 0.0195376 milliseconds on average.
Interpolation: 0.0279227 milliseconds on average.
Heredoc: 0.0247411 milliseconds on average.

*/
?
/body
/html

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] concatenating strings

2004-05-22 Thread Richard Davey
Hello Bill,

Saturday, May 22, 2004, 11:43:17 AM, you wrote:

BF how do I add newline commands in the middle of a text string?

BF How do I write it so the email message text is on two lines,
BF My name is BILL
BF My favorite color is RED

$message = My name is  . $myname . \nMy favorite color is  . $color;

\n = new line

-- 
Best regards,
 Richard Davey
 http://www.launchcode.co.uk / PHP Development Services
 http://www.phpcommunity.org/wiki/296.html / PHP Community

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] concatenating strings

2004-05-22 Thread Matt
 From: Richard Davey [EMAIL PROTECTED]  Saturday, May 22, 2004 6:46
AM
 Subject: Re: [PHP] concatenating strings

 BF how do I add newline commands in the middle of a text string?

 $message = My name is  . $myname . \nMy favorite color is  . $color;

 \n = new line

Also \n only works in double quotes.  If you use single quotes you need to
break out and concatenate \n in double quotes.

$message = 'My name is ' . $myname . \n . 'My favorite color is ' .
$color;



---
The future will be better tomorrow
---
http://www.spiceplace.com/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] concatenating 2 resultsets

2004-03-15 Thread Marek Kilimajer
Angelo Zanetti wrote:

Hi all, is it possible to concatenate two resultsets, to form a big
resultset.
What database are you using?

both resultsets will return the same columns.

eg query 1 returns NAME| ADDRESS| EMAIL
   query 2 returns NAME| ADDRESS| EMAIL
but they have different data however the column count is the same (in fact
they are the same column)
Look at UNION syntax

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP] concatenating 2 resultsets [SOLVED]

2004-03-15 Thread Angelo Zanetti
solved guys

-Original Message-
From: Angelo Zanetti [mailto:[EMAIL PROTECTED]
Sent: Monday, March 15, 2004 12:30 PM
To: [EMAIL PROTECTED]
Subject: [PHP] concatenating 2 resultsets


Hi all, is it possible to concatenate two resultsets, to form a big
resultset.

both resultsets will return the same columns.

eg query 1 returns NAME| ADDRESS| EMAIL
   query 2 returns NAME| ADDRESS| EMAIL

but they have different data however the column count is the same (in fact
they are the same column)

thanx in advance
Angelo


Disclaimer 
This e-mail transmission contains confidential information,
which is the property of the sender.
The information in this e-mail or attachments thereto is 
intended for the attention and use only of the addressee. 
Should you have received this e-mail in error, please delete 
and destroy it and any attachments thereto immediately. 
Under no circumstances will the Cape Technikon or the sender 
of this e-mail be liable to any party for any direct, indirect, 
special or other consequential damages for any use of this e-mail.
For the detailed e-mail disclaimer please refer to 
http://www.ctech.ac.za/polic or call +27 (0)21 460 3911

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Disclaimer 
This e-mail transmission contains confidential information,
which is the property of the sender.
The information in this e-mail or attachments thereto is 
intended for the attention and use only of the addressee. 
Should you have received this e-mail in error, please delete 
and destroy it and any attachments thereto immediately. 
Under no circumstances will the Cape Technikon or the sender 
of this e-mail be liable to any party for any direct, indirect, 
special or other consequential damages for any use of this e-mail.
For the detailed e-mail disclaimer please refer to 
http://www.ctech.ac.za/polic or call +27 (0)21 460 3911

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] concatenating strings and \n's for mail...

2001-02-14 Thread Christian Cresante

You need to use "\n" for interpolation.

--- Larry Rosenman [EMAIL PROTECTED] wrote:
 Greetings,
 I was trying to build up a multi-line body to
 use with the mail
 command, using code similar to:
  $mailbody = $mailbody . '\n' .
 $HTTP_POST_VARS["somefield"];
 
   when I sent the mail, the \n showed up, not as a
 new line, but a
 literal \n.  How do I fix this? 
 
 This is with 4.0.4pl1. 
 
 LER
 
 
 -- 
 Larry Rosenman
 http://www.lerctr.org/~ler
 Phone: +1 972-414-9812 E-Mail:
 [EMAIL PROTECTED]
 US Mail: 1905 Steamboat Springs Drive, Garland, TX
 75044-6749
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail:
 [EMAIL PROTECTED]
 For additional commands, e-mail:
 [EMAIL PROTECTED]
 To contact the list administrators, e-mail:
 [EMAIL PROTECTED]
 


__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] concatenating strings and \n's for mail...

2001-02-14 Thread Larry Rosenman

* Christian Cresante [EMAIL PROTECTED] [010214 13:27]:
 You need to use "\n" for interpolation.
Tried that too...  Didn't work for me...
 
 --- Larry Rosenman [EMAIL PROTECTED] wrote:
  Greetings,
  I was trying to build up a multi-line body to
  use with the mail
  command, using code similar to:
   $mailbody = $mailbody . '\n' .
  $HTTP_POST_VARS["somefield"];
  
when I sent the mail, the \n showed up, not as a
  new line, but a
  literal \n.  How do I fix this? 
  
  This is with 4.0.4pl1. 
  
  LER
  
  
  -- 
  Larry Rosenman
  http://www.lerctr.org/~ler
  Phone: +1 972-414-9812 E-Mail:
  [EMAIL PROTECTED]
  US Mail: 1905 Steamboat Springs Drive, Garland, TX
  75044-6749
  
  -- 
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, e-mail:
  [EMAIL PROTECTED]
  For additional commands, e-mail:
  [EMAIL PROTECTED]
  To contact the list administrators, e-mail:
  [EMAIL PROTECTED]
  
 
 
 __
 Do You Yahoo!?
 Get personalized email addresses from Yahoo! Mail - only $35 
 a year!  http://personal.mail.yahoo.com/
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]

-- 
Larry Rosenman http://www.lerctr.org/~ler
Phone: +1 972-414-9812 E-Mail: [EMAIL PROTECTED]
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] concatenating strings and \n's for mail...

2001-02-14 Thread Larry Rosenman

* Lewis Bergman [EMAIL PROTECTED] [010214 13:50]:
 On Wed, 14 Feb 2001, you wrote:
  Greetings,
  I was trying to build up a multi-line body to use with the mail
  command, using code similar to:
   $mailbody = $mailbody . '\n' . $HTTP_POST_VARS["somefield"];
  
when I sent the mail, the \n showed up, not as a new line, but a
  literal \n.  How do I fix this? 
 Did you try . "\r\n" .  ? I use it though in many places just as you have "\n"
Nope, will tonight though.
 ...
 
  --
 Lewis Bergman
 Texas Communications
 4309 Maple St.
 Abilene, TX 79602
 915-695-6962
-- 
Larry Rosenman http://www.lerctr.org/~ler
Phone: +1 972-414-9812 E-Mail: [EMAIL PROTECTED]
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] concatenating strings and \n's for mail...

2001-02-14 Thread CC Zona

[restored to bottom-posting, for clarity]

   I was trying to build up a multi-line body to use with the mail
   command, using code similar to:
$mailbody = $mailbody . '\n' . $HTTP_POST_VARS["somefield"];

snip

  I think you can do it like this:
  
  $mailbody="$varname\n$varname2";
 That works.  Hmm.  I wonder why the concatenation didn't?

Because '\n' is a string consisting of a backslash followed by the letter 
n, while "\n" is a newline character.  Gotta use double-quotes.

-- 
CC

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] concatenating strings and \n's for mail...

2001-02-14 Thread Larry Rosenman

* CC Zona [EMAIL PROTECTED] [010214 21:21]:
 [restored to bottom-posting, for clarity]
 
I was trying to build up a multi-line body to use with the mail
command, using code similar to:
 $mailbody = $mailbody . '\n' . $HTTP_POST_VARS["somefield"];
 
 snip
 
   I think you can do it like this:
   
   $mailbody="$varname\n$varname2";
  That works.  Hmm.  I wonder why the concatenation didn't?
 
 Because '\n' is a string consisting of a backslash followed by the letter 
 n, while "\n" is a newline character.  Gotta use double-quotes.
I even had trouble within double quotes with the concatenation.

LER

-- 
Larry Rosenman http://www.lerctr.org/~ler
Phone: +1 972-414-9812 E-Mail: [EMAIL PROTECTED]
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]