Re: [PHP] string concatenation with fgets

2009-11-30 Thread Ashley Sheridan
On Mon, 2009-11-30 at 09:40 -0800, aurfal...@gmail.com wrote:

> Hi Ash,
> 
> Actually I need the if because the code will print out an empty line  
> and add "sometext" to it.
> 
> So without the if check for an empty line, at the end of the loop I'll  
> get sometext.  For example, if the file I am processing called  
> somename.txt has
> 
> a
> b
> c
> 
> in it.  I'll have;
> 
> asometext
> bsometext
> csometext
> 
> but w/o the if check, I'll also have
> 
> sometext
> 
> as well.
> 
> 
> 
> On Nov 30, 2009, at 9:24 AM, Ashley Sheridan wrote:
> 
> > On Mon, 2009-11-30 at 09:04 -0800, aurfal...@gmail.com wrote:
> >>
> >> Hi Shawn,
> >>
> >> Your code looks cleaner then mine so i tried it and got the last  
> >> entry
> >> in the txt file printed twice.
> >>
> >>
> >> On Nov 30, 2009, at 7:07 AM, Shawn McKenzie wrote:
> >>
> >> > aurfal...@gmail.com wrote:
> >> >> So here is my final test code, notice the check for ' ' in the if.
> >> >>
> >> >> Since I'm on Linux, this has to do with whats between the last  
> >> LF and
> >> >> EOF which is nothing but this nothing will get printed out.
> >> >>
> >> >> $file = fopen("somefile.txt", "r");
> >> >> while (! feof($file))
> >> >>{
> >> >  $tmp = trim(fgets($file));
> >> >  if ($tmp != '')
> >> >>{
> >> >  $names = $tmp;
> >> >>}
> >> >>print $names."sometext\n";
> >> >>}
> >> >> fclose($file);
> >> >>
> >> >>
> >> >
> >> > --
> >> > Thanks!
> >> > -Shawn
> >> > http://www.spidean.com
> >>
> >>
> >
> > Remove the if statement and just print out $tmp. The while loop is  
> > going over one extra time than you need, and on that final  
> > iteration, $tmp is an empty string. The if statement only changes  
> > $name if $tmp is empty, so it leaves it as it was, hence you getting  
> > the last line printed twice. Printing out an empty string in this  
> > example won't do anything, and the if statement is also pretty  
> > useless as it just copies the value to another variable on a  
> > condition that will only result in the side-effect you've noticed.
> >
> > Thanks,
> > Ash
> > http://www.ashleysheridan.co.uk
> >
> >
> 


Then put the print statement inside the if, not the assignation,
otherwise you will always get that last line!

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] string concatenation with fgets

2009-11-30 Thread aurfalien

Hi Ash,

Actually I need the if because the code will print out an empty line  
and add "sometext" to it.


So without the if check for an empty line, at the end of the loop I'll  
get sometext.  For example, if the file I am processing called  
somename.txt has


a
b
c

in it.  I'll have;

asometext
bsometext
csometext

but w/o the if check, I'll also have

sometext

as well.



On Nov 30, 2009, at 9:24 AM, Ashley Sheridan wrote:


On Mon, 2009-11-30 at 09:04 -0800, aurfal...@gmail.com wrote:


Hi Shawn,

Your code looks cleaner then mine so i tried it and got the last  
entry

in the txt file printed twice.


On Nov 30, 2009, at 7:07 AM, Shawn McKenzie wrote:

> aurfal...@gmail.com wrote:
>> So here is my final test code, notice the check for ' ' in the if.
>>
>> Since I'm on Linux, this has to do with whats between the last  
LF and

>> EOF which is nothing but this nothing will get printed out.
>>
>> $file = fopen("somefile.txt", "r");
>> while (! feof($file))
>>{
>  $tmp = trim(fgets($file));
>  if ($tmp != '')
>>{
>  $names = $tmp;
>>}
>>print $names."sometext\n";
>>}
>> fclose($file);
>>
>>
>
> --
> Thanks!
> -Shawn
> http://www.spidean.com




Remove the if statement and just print out $tmp. The while loop is  
going over one extra time than you need, and on that final  
iteration, $tmp is an empty string. The if statement only changes  
$name if $tmp is empty, so it leaves it as it was, hence you getting  
the last line printed twice. Printing out an empty string in this  
example won't do anything, and the if statement is also pretty  
useless as it just copies the value to another variable on a  
condition that will only result in the side-effect you've noticed.


Thanks,
Ash
http://www.ashleysheridan.co.uk






Re: [PHP] string concatenation with fgets

2009-11-30 Thread Ashley Sheridan
On Mon, 2009-11-30 at 09:04 -0800, aurfal...@gmail.com wrote:

> Hi Shawn,
> 
> Your code looks cleaner then mine so i tried it and got the last entry  
> in the txt file printed twice.
> 
> 
> On Nov 30, 2009, at 7:07 AM, Shawn McKenzie wrote:
> 
> > aurfal...@gmail.com wrote:
> >> So here is my final test code, notice the check for ' ' in the if.
> >>
> >> Since I'm on Linux, this has to do with whats between the last LF and
> >> EOF which is nothing but this nothing will get printed out.
> >>
> >> $file = fopen("somefile.txt", "r");
> >> while (! feof($file))
> >>{
> >  $tmp = trim(fgets($file));
> >  if ($tmp != '')
> >>{
> >  $names = $tmp;
> >>}
> >>print $names."sometext\n";
> >>}
> >> fclose($file);
> >>
> >>
> >
> > -- 
> > Thanks!
> > -Shawn
> > http://www.spidean.com
> 
> 


Remove the if statement and just print out $tmp. The while loop is going
over one extra time than you need, and on that final iteration, $tmp is
an empty string. The if statement only changes $name if $tmp is empty,
so it leaves it as it was, hence you getting the last line printed
twice. Printing out an empty string in this example won't do anything,
and the if statement is also pretty useless as it just copies the value
to another variable on a condition that will only result in the
side-effect you've noticed.

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] string concatenation with fgets

2009-11-30 Thread aurfalien

Hi Shawn,

Your code looks cleaner then mine so i tried it and got the last entry  
in the txt file printed twice.



On Nov 30, 2009, at 7:07 AM, Shawn McKenzie wrote:


aurfal...@gmail.com wrote:

So here is my final test code, notice the check for ' ' in the if.

Since I'm on Linux, this has to do with whats between the last LF and
EOF which is nothing but this nothing will get printed out.

$file = fopen("somefile.txt", "r");
while (! feof($file))
   {

 $tmp = trim(fgets($file));
 if ($tmp != '')

   {

 $names = $tmp;

   }
   print $names."sometext\n";
   }
fclose($file);




--
Thanks!
-Shawn
http://www.spidean.com



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



Re: [PHP] string concatenation with fgets

2009-11-30 Thread Shawn McKenzie
aurfal...@gmail.com wrote:
> So here is my final test code, notice the check for ' ' in the if.
> 
> Since I'm on Linux, this has to do with whats between the last LF and
> EOF which is nothing but this nothing will get printed out.
> 
> $file = fopen("somefile.txt", "r");
> while (! feof($file))
> {
  $tmp = trim(fgets($file));
  if ($tmp != '')
> {
  $names = $tmp;
> }
> print $names."sometext\n";
> }
> fclose($file);
> 
> 

-- 
Thanks!
-Shawn
http://www.spidean.com

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



Re: [PHP] string concatenation with fgets

2009-11-26 Thread aurfalien

So here is my final test code, notice the check for ' ' in the if.

Since I'm on Linux, this has to do with whats between the last LF and  
EOF which is nothing but this nothing will get printed out.


$file = fopen("somefile.txt", "r");
while (! feof($file))
{
$names = trim(fgets($file));
if ($names == '')
{
break;
}
print $names."sometext\n";
}
fclose($file);


- aurf

On Nov 24, 2009, at 5:52 PM, ryan wrote:


Is this what you want

$file = fopen("test.txt", "r");
while (!feof($file)) {
  $line = trim(fgets($file));
  print $line."sometext\n";
  }
fclose($file);

outputs
asometext
bsometext
csometext

Ref to http://us3.php.net/manual/en/function.fgets.php. "Reading  
ends when /length/ - 1 bytes have been read, on a newline (which is  
included in the return value), or on EOF (whichever comes first). If  
no length is specified, it will keep reading from the stream until  
it reaches the end of the line. "



aurfal...@gmail.com wrote:

Hi all,

I'm trying to append some text to what I read from a file.

My code;

$file = fopen("foo.txt", "r");
while (!feof($file)) {
   $line = fgets($file);
   print $line."sometext";
   }
fclose($file);

foo,txt;
a
b
c
d
e
f
g

And when I run the script, it looks like;
a
sometextb
sometextc
sometextd
...


Any ideas?

Thanks in advance,
- aurf






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



Re: [PHP] string concatenation with fgets

2009-11-24 Thread aurfalien

On Nov 24, 2009, at 5:52 PM, ryan wrote:


Is this what you want

$file = fopen("test.txt", "r");
while (!feof($file)) {
  $line = trim(fgets($file));
  print $line."sometext\n";
  }
fclose($file);

outputs
asometext
bsometext
csometext

Ref to http://us3.php.net/manual/en/function.fgets.php. "Reading  
ends when /length/ - 1 bytes have been read, on a newline (which is  
included in the return value), or on EOF (whichever comes first). If  
no length is specified, it will keep reading from the stream until  
it reaches the end of the line. "



aurfal...@gmail.com wrote:

Hi all,

I'm trying to append some text to what I read from a file.

My code;

$file = fopen("foo.txt", "r");
while (!feof($file)) {
   $line = fgets($file);
   print $line."sometext";
   }
fclose($file);

foo,txt;
a
b
c
d
e
f
g

And when I run the script, it looks like;
a
sometextb
sometextc
sometextd
...


Any ideas?

Thanks in advance,
- aurf






OMG, very very cool, thanks Ryan.

- aurf


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



Re: [PHP] string concatenation with fgets

2009-11-24 Thread aurfalien

On Nov 24, 2009, at 5:55 PM, Nirmalya Lahiri wrote:


--- On Wed, 11/25/09, aurfal...@gmail.com  wrote:


From: aurfal...@gmail.com 
Subject: [PHP] string concatenation with fgets
To: php-general@lists.php.net
Date: Wednesday, November 25, 2009, 7:00 AM
Hi all,

I'm trying to append some text to what I read from a file.

My code;

$file = fopen("foo.txt", "r");
while (!feof($file)) {
$line = fgets($file);
print $line."sometext";
}
fclose($file);

foo,txt;
a
b
c
d
e
f
g

And when I run the script, it looks like;
a
sometextb
sometextc
sometextd
...


Any ideas?




So, what output you actually wants from your program?

Is it like this
asometextbsometextcsometext..

or, like this
asometext
bsometext
csometext




Hi,

Sorry, I was incomplete :)

I would like;

asometext
bsometext
csometext

Basically, I would like to add whatever text to the end of what I find  
in the file.


So if the file contains

a
b
c

I would like;

asometext
bsometext
csometext...

- aurf


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



Re: [PHP] string concatenation with fgets

2009-11-24 Thread Nirmalya Lahiri
--- On Wed, 11/25/09, aurfal...@gmail.com  wrote:

> From: aurfal...@gmail.com 
> Subject: [PHP] string concatenation with fgets
> To: php-general@lists.php.net
> Date: Wednesday, November 25, 2009, 7:00 AM
> Hi all,
> 
> I'm trying to append some text to what I read from a file.
> 
> My code;
> 
> $file = fopen("foo.txt", "r");
> while (!feof($file)) {
>     $line = fgets($file);
>     print $line."sometext";
>     }
> fclose($file);
> 
> foo,txt;
> a
> b
> c
> d
> e
> f
> g
> 
> And when I run the script, it looks like;
> a
> sometextb
> sometextc
> sometextd
> ...
> 
> 
> Any ideas?
> 


So, what output you actually wants from your program?

Is it like this
asometextbsometextcsometext..

or, like this
asometext
bsometext
csometext


---
নির্মাল্য লাহিড়ী [Nirmalya Lahiri]
+৯১-৯৪৩৩১১৩৫৩৬ [+91-9433113536]






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



Re: [PHP] string concatenation with fgets

2009-11-24 Thread ryan

Is this what you want

$file = fopen("test.txt", "r");
while (!feof($file)) {
   $line = trim(fgets($file));
   print $line."sometext\n";
   }
fclose($file);

outputs
asometext
bsometext
csometext

Ref to http://us3.php.net/manual/en/function.fgets.php. "Reading ends 
when /length/ - 1 bytes have been read, on a newline (which is included 
in the return value), or on EOF (whichever comes first). If no length is 
specified, it will keep reading from the stream until it reaches the end 
of the line. "



aurfal...@gmail.com wrote:

Hi all,

I'm trying to append some text to what I read from a file.

My code;

$file = fopen("foo.txt", "r");
while (!feof($file)) {
$line = fgets($file);
print $line."sometext";
}
fclose($file);

foo,txt;
a
b
c
d
e
f
g

And when I run the script, it looks like;
a
sometextb
sometextc
sometextd
...


Any ideas?

Thanks in advance,
- aurf




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



[PHP] string concatenation with fgets

2009-11-24 Thread aurfalien

Hi all,

I'm trying to append some text to what I read from a file.

My code;

$file = fopen("foo.txt", "r");
while (!feof($file)) {
$line = fgets($file);
print $line."sometext";
}
fclose($file);

foo,txt;
a
b
c
d
e
f
g

And when I run the script, it looks like;
a
sometextb
sometextc
sometextd
...


Any ideas?

Thanks in advance,
- aurf

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



Re: [PHP] string concatenation from array

2003-08-14 Thread Peter James
My personal favourite is to use an array.  It's much cleaner syntax IMO...it
is very easy to miss a '.' on a '.=', and introduce a nasty bug.

$wresult = array();

foreach ($search_string as $word_result) {
  $wresult[] = $word_result;
}
echo join('', $wresult);

or in php 4.3

echo join($wresult);

--
Peter James
Editor-in-Chief, php|architect Magazine
[EMAIL PROTECTED]

php|architect
The Magazine for PHP Professionals
http://www.phparch.com


- Original Message - 
From: "Matt Giddings" <[EMAIL PROTECTED]>
To: "'Micah Montoy'" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Tuesday, August 12, 2003 2:00 PM
Subject: RE: [PHP] string concatenation from array


> Use the "." concatenation operator.  : )
>
>
> $wresult = "";
>
> foreach ($search_string as $word_result) {
>   $wresult = $wresult . " " . $word_result;
> }
> echo $wresult;
>
>
> Matt
>
> > -----Original Message-
> > From: Micah Montoy [mailto:[EMAIL PROTECTED]
> > Sent: Tuesday, August 12, 2003 3:58 PM
> > To: [EMAIL PROTECTED]
> > Subject: [PHP] string concatenation from array
> >
> > I'm having a bit of difficulty getting a string to attach to itself
> from
> > an
> > array.  Here is the bit of code I'm working on.
> >
> > $wresult = "";
> >
> >  foreach ($search_string as $word_result){
> >   $wresult = $wresult & " " & $word_result;
> >  }
> >
> > echo ("$wresult");
> >
> > Anyone see why when I run through each part of the array, it won't
> attach
> > the next string and so on?
> >
> > thanks
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> > ---
> > Incoming mail is certified Virus Free.
> > Checked by AVG anti-virus system (http://www.grisoft.com).
> > Version: 6.0.507 / Virus Database: 304 - Release Date: 8/4/2003
> >
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.507 / Virus Database: 304 - Release Date: 8/4/2003
>
>
>
> -- 
> 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] string concatenation from array

2003-08-14 Thread Matt Giddings
Use the "." concatenation operator.  : )


$wresult = "";

foreach ($search_string as $word_result) {
  $wresult = $wresult . " " . $word_result;
}
echo $wresult;


Matt

> -Original Message-
> From: Micah Montoy [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, August 12, 2003 3:58 PM
> To: [EMAIL PROTECTED]
> Subject: [PHP] string concatenation from array
> 
> I'm having a bit of difficulty getting a string to attach to itself
from
> an
> array.  Here is the bit of code I'm working on.
> 
> $wresult = "";
> 
>  foreach ($search_string as $word_result){
>   $wresult = $wresult & " " & $word_result;
>  }
> 
> echo ("$wresult");
> 
> Anyone see why when I run through each part of the array, it won't
attach
> the next string and so on?
> 
> thanks
> 
> 
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 
> ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.507 / Virus Database: 304 - Release Date: 8/4/2003
>

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.507 / Virus Database: 304 - Release Date: 8/4/2003
 


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



[PHP] string concatenation from array

2003-08-14 Thread Micah Montoy
I'm having a bit of difficulty getting a string to attach to itself from an
array.  Here is the bit of code I'm working on.

$wresult = "";

 foreach ($search_string as $word_result){
  $wresult = $wresult & " " & $word_result;
 }

echo ("$wresult");

Anyone see why when I run through each part of the array, it won't attach
the next string and so on?

thanks



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



Re: [PHP] string concatenation from array

2003-08-14 Thread CPT John W. Holmes
From: "Jonathan Pitcher" <[EMAIL PROTECTED]>
> The & sign in PHP (to the best of my knowledge) does not concatenate.

Correct, it's a bitwise AND operator. 

http://us2.php.net/manual/en/language.operators.bitwise.php

---John Holmes...

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



RE: [PHP] string concatenation from array

2003-08-14 Thread Chris W. Parker
Analysis & Solutions 
on Tuesday, August 12, 2003 1:02 PM said:

> OR you can do...
> $wresult .= $word_result;

Don't forget the space:

$wresult .= " ".$word_result;


c.

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



Re: [PHP] string concatenation from array

2003-08-14 Thread Peter James
Of course, in this case, it would be much easier replace all of the above
with

echo join(' ', $search_string);

and be done with it. :-)

--
Peter James
Editor-in-Chief, php|architect Magazine
[EMAIL PROTECTED]

php|architect
The Magazine for PHP Professionals
http://www.phparch.com


- Original Message - 
From: "Peter James" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, August 12, 2003 2:18 PM
Subject: Re: [PHP] string concatenation from array


> My personal favourite is to use an array.  It's much cleaner syntax
IMO...it
> is very easy to miss a '.' on a '.=', and introduce a nasty bug.
>
> $wresult = array();
>
> foreach ($search_string as $word_result) {
>   $wresult[] = $word_result;
> }
> echo join('', $wresult);
>
> or in php 4.3
>
> echo join($wresult);
>
> --
> Peter James
> Editor-in-Chief, php|architect Magazine
> [EMAIL PROTECTED]
>
> php|architect
> The Magazine for PHP Professionals
> http://www.phparch.com
>
>
> - Original Message - 
> From: "Matt Giddings" <[EMAIL PROTECTED]>
> To: "'Micah Montoy'" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
> Sent: Tuesday, August 12, 2003 2:00 PM
> Subject: RE: [PHP] string concatenation from array
>
>
> > Use the "." concatenation operator.  : )
> >
> >
> > $wresult = "";
> >
> > foreach ($search_string as $word_result) {
> >   $wresult = $wresult . " " . $word_result;
> > }
> > echo $wresult;
> >
> >
> > Matt
> >
> > > -Original Message-
> > > From: Micah Montoy [mailto:[EMAIL PROTECTED]
> > > Sent: Tuesday, August 12, 2003 3:58 PM
> > > To: [EMAIL PROTECTED]
> > > Subject: [PHP] string concatenation from array
> > >
> > > I'm having a bit of difficulty getting a string to attach to itself
> > from
> > > an
> > > array.  Here is the bit of code I'm working on.
> > >
> > > $wresult = "";
> > >
> > >  foreach ($search_string as $word_result){
> > >   $wresult = $wresult & " " & $word_result;
> > >  }
> > >
> > > echo ("$wresult");
> > >
> > > Anyone see why when I run through each part of the array, it won't
> > attach
> > > the next string and so on?
> > >
> > > thanks
> > >
> > >
> > >
> > > --
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> > >
> > >
> > > ---
> > > Incoming mail is certified Virus Free.
> > > Checked by AVG anti-virus system (http://www.grisoft.com).
> > > Version: 6.0.507 / Virus Database: 304 - Release Date: 8/4/2003
> > >
> >
> > ---
> > Outgoing mail is certified Virus Free.
> > Checked by AVG anti-virus system (http://www.grisoft.com).
> > Version: 6.0.507 / Virus Database: 304 - Release Date: 8/4/2003
> >
> >
> >
> > -- 
> > 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
>


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



Re: [PHP] string concatenation from array

2003-08-14 Thread Jonathan Pitcher
Micah,

The & sign in PHP (to the best of my knowledge) does not concatenate.

Use a . instead.   See below.

$wresult = "";

foreach ($search_string as $word_result){
$wresult .= $word_result;
}
That should work for you.



Jonathan Pitcher

On Tuesday, August 12, 2003, at 02:58  PM, Micah Montoy wrote:

I'm having a bit of difficulty getting a string to attach to itself 
from an
array.  Here is the bit of code I'm working on.

$wresult = "";

 foreach ($search_string as $word_result){
  $wresult = $wresult & " " & $word_result;
 }
echo ("$wresult");

Anyone see why when I run through each part of the array, it won't 
attach
the next string and so on?

thanks



--
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] string concatenation from array

2003-08-14 Thread Analysis & Solutions
On Tue, Aug 12, 2003 at 01:58:21PM -0600, Micah Montoy wrote:
> I'm having a bit of difficulty getting a string to attach to itself from an
> array.  Here is the bit of code I'm working on.
> 


A bunch of simplifications, efficiency tweaks on this approach...

> $wresult = "";
  $wresult = '';


> 
>  foreach ($search_string as $word_result){
>   $wresult = $wresult & " " & $word_result;
$wresult = $wresult . ' ' . $word_result;
OR you can do...
$wresult .= $word_result;
>  }
> 
> echo ("$wresult");
echo $wresult;


BUT, the far far far better way to do this just takes one line:

   echo implode(' ', $search_string);

--Dan

-- 
 FREE scripts that make web and database programming easier
   http://www.analysisandsolutions.com/software/
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
 4015 7th Ave #4AJ, Brooklyn NYv: 718-854-0335   f: 718-854-0409

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



RE: [PHP] string concatenation

2001-07-25 Thread Seb Frost

Whoops meant to delete the old message.  Doh.  Variable variables eh?  A
topic I've always wondered about and never found in a manual for any of the
languages I've used before.  Will go and have a look now, cheers.

- seb

-Original Message-
From: David Robley [mailto:[EMAIL PROTECTED]]
Sent: 26 July 2001 02:10
To: Seb Frost; PHP
Subject: Re: [PHP] string concatenation


On Thu, 26 Jul 2001 06:54, Seb Frost wrote:
> OK let's say in variable $search I have the string "color" (without the
> quote marks).
>
> now I want to be able to refer to the variable $color in my code.
>
> How in gods name do I do this.  I guess somehow I have to combine a "$"
> with the contents of £search or something...?
>
> - seb

Feel free to trim all the ireelevant stuff from your posts :-)

Try $$search or ${color} depending on exactly what you want to do. You
might want to have another read through the Variable variables section of
the documentation to clarify this.

--
David Robley  Techno-JoaT, Web Maintainer, Mail List Admin, etc
CENTRE FOR INJURY STUDIES  Flinders University, SOUTH AUSTRALIA

   I tried switching to gum but couldn't keep it lit.

--
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]



-- 
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] string concatenation

2001-07-25 Thread David Robley

On Thu, 26 Jul 2001 06:54, Seb Frost wrote:
> OK let's say in variable $search I have the string "color" (without the
> quote marks).
>
> now I want to be able to refer to the variable $color in my code.
>
> How in gods name do I do this.  I guess somehow I have to combine a "$"
> with the contents of £search or something...?
>
> - seb

Feel free to trim all the ireelevant stuff from your posts :-)

Try $$search or ${color} depending on exactly what you want to do. You 
might want to have another read through the Variable variables section of 
the documentation to clarify this.

-- 
David Robley  Techno-JoaT, Web Maintainer, Mail List Admin, etc
CENTRE FOR INJURY STUDIES  Flinders University, SOUTH AUSTRALIA  

   I tried switching to gum but couldn't keep it lit.

-- 
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]




[PHP] string concatenation

2001-07-25 Thread Seb Frost

OK let's say in variable $search I have the string "color" (without the
quote marks).

now I want to be able to refer to the variable $color in my code.

How in gods name do I do this.  I guess somehow I have to combine a "$" with
the contents of £search or something...?

- seb

-Original Message-
From: Jeff Oien [mailto:[EMAIL PROTECTED]]
Sent: 25 July 2001 22:05
To: PHP
Subject: RE: [PHP] Regular Expression Question


Aren't the trims just for white space?
Jeff Oien

> since you know exactly which 4 characters you want to keep you can use a
> simple string trimming routine.  I forget the name of the function in php
> but it's there and it'll be something like
>
> trimstring($string,1,5);
>
> or something like that.  No need for complicated regular expressions
either
> way.
>
> - seb
>
> -Original Message-
> From: Jeff Oien [mailto:[EMAIL PROTECTED]]
> Sent: 25 July 2001 21:47
> To: PHP
> Subject: [PHP] Regular Expression Question
>
>
> I want to replace a string like this 1B335-2G with this B335. So for all
the
> strings I want to remove the first character and the last three
characters.
> I'm not sure which replace function to use or how to go about it. Thanks.
> Jeff Oien
>
> --
> 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]
>

--
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]



-- 
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]




[PHP] String concatenation problems

2001-03-07 Thread [EMAIL PROTECTED]

I posted a related question yesterday with no response.  I've done some more 
investigating and think I can lay some of the blame on the string concatentation 
operation.  If anyone can tell me what might be causing this behavoir I would greatly 
appreciate it.

the following code shows the rough form of what I am doing
for ($i=0;$i<100;$i++)
{
   $returnVal = "\t\n";
   $returnVal .= "\t\t\n";
   $returnVal .= "\t\t\t  \n";

   $returnVal .= "\t";
   $returnValArray[$i]=$returnVal;
}
return $returnValArray;

--- Problem description:
Some rows are corrupted.
The type of corruption that occur are
a) an incomplete row is in $returnVal before assignment to the array, the incomplete 
row is always stopped partway through the addition of a string, ie "ABC"."DEF"->"ABCD" 
sometimes
b) a doubled row.  The initial $returnVal assignment is skipped causing two iterations 
throuhg the for loop to build up on the returnVal variable.
c) unknown. in some cases, after the assignment of $returnVal to $returnValArray[$i] 
the array version will be corrupted while the originl is not.

What is happening here?  As mentioned this problem only materializes on an older 
machine (P133 with 64MB ram) not on the development machine (PIII700 with 128MB).  The 
productio server runs AOLServer while the development server runs Apache.

Eric Nielsen




Mail2Web - Check your email from the web at
http://www.mail2web.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]