Re: [PHP] Explode Question

2011-05-17 Thread Marc Guay
 $one = array(0 ='golf', 1 = 'field');
 $two = array(0 = On the golf course or in the field of clover);
 $array_exp = explode($one, $two);

What's the desired result?

array('golf' = On the golf course or in the field of clover,
'field' =  On the golf course or in the field of clover)); ?


Marc

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



RE: [PHP] Explode Question

2011-05-17 Thread admin

The desired result is.

Array
(
[0] =  On the;
[1] =  course or in the;
[2] =  of colver;
);

I am just not sure the delimiter can be an array in the Explode function.






Richard L. Buskirk

-Original Message-
From: Marc Guay [mailto:marc.g...@gmail.com] 
Sent: Tuesday, May 17, 2011 7:52 PM
To: php-general@lists.php.net
Subject: Re: [PHP] Explode Question

 $one = array(0 ='golf', 1 = 'field');
 $two = array(0 = On the golf course or in the field of clover);
 $array_exp = explode($one, $two);

What's the desired result?

array('golf' = On the golf course or in the field of clover,
'field' =  On the golf course or in the field of clover)); ?


Marc

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

2011-05-17 Thread James Yerge
On 05/17/2011 07:53 PM, ad...@buskirkgraphics.com wrote:
 The desired result is.

 Array
 (
   [0] =  On the;
   [1] =  course or in the;
   [2] =  of colver;
 );

 I am just not sure the delimiter can be an array in the Explode function.






 Richard L. Buskirk

 -Original Message-
 From: Marc Guay [mailto:marc.g...@gmail.com] 
 Sent: Tuesday, May 17, 2011 7:52 PM
 To: php-general@lists.php.net
 Subject: Re: [PHP] Explode Question

 $one = array(0 ='golf', 1 = 'field');
 $two = array(0 = On the golf course or in the field of clover);
 $array_exp = explode($one, $two);
 What's the desired result?

 array('golf' = On the golf course or in the field of clover,
 'field' =  On the golf course or in the field of clover)); ?


 Marc


explode() takes three parameters; string, string, [int]. Where [int] is
optional.

Ex:
$ipList = '192.168.1.0,192.168.1.1,192.168.1.2';
$ipList = explode(',',$ipList);

Returns an array of strings:

Array
(
[0] = 192.168.1.0,
[1] = 192.168.1.1,
[2] = 192.168.1.2
);



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



Re: [PHP] Explode Question

2011-05-17 Thread James Yerge
On 05/17/2011 07:53 PM, ad...@buskirkgraphics.com wrote:
 The desired result is.

 Array
 (
   [0] =  On the;
   [1] =  course or in the;
   [2] =  of colver;
 );

 I am just not sure the delimiter can be an array in the Explode function.






 Richard L. Buskirk

 -Original Message-
 From: Marc Guay [mailto:marc.g...@gmail.com] 
 Sent: Tuesday, May 17, 2011 7:52 PM
 To: php-general@lists.php.net
 Subject: Re: [PHP] Explode Question

 $one = array(0 ='golf', 1 = 'field');
 $two = array(0 = On the golf course or in the field of clover);
 $array_exp = explode($one, $two);
 What's the desired result?

 array('golf' = On the golf course or in the field of clover,
 'field' =  On the golf course or in the field of clover)); ?


 Marc


Here's something to mess around with, to fit to your liking.

?php
$one = array('golf','field');
$two = array(On the golf course or in the field of clover);
$result = array_explode($one,$two);

print_r($result);

function array_explode($delimiters,$array)
{
if ( !is_array($delimiters) || !is_array($array) ) {
//bail
return;
}
$string = $array[0];
$regex = @(.implode('|',$delimiters).)@;
return preg_split($regex,$string);
}
?

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



RE: [PHP] Explode Question

2011-05-17 Thread admin
That is exactly it.
Thanks James I knew it was simple just forgot how it was done.





Richard L. Buskirk

-Original Message-
From: James Yerge [mailto:ja...@nixsecurity.org] 
Sent: Tuesday, May 17, 2011 8:51 PM
To: ad...@buskirkgraphics.com
Cc: 'Marc Guay'; php-general@lists.php.net
Subject: Re: [PHP] Explode Question

On 05/17/2011 07:53 PM, ad...@buskirkgraphics.com wrote:
 The desired result is.

 Array
 (
   [0] =  On the;
   [1] =  course or in the;
   [2] =  of colver;
 );

 I am just not sure the delimiter can be an array in the Explode function.






 Richard L. Buskirk

 -Original Message-
 From: Marc Guay [mailto:marc.g...@gmail.com] 
 Sent: Tuesday, May 17, 2011 7:52 PM
 To: php-general@lists.php.net
 Subject: Re: [PHP] Explode Question

 $one = array(0 ='golf', 1 = 'field');
 $two = array(0 = On the golf course or in the field of clover);
 $array_exp = explode($one, $two);
 What's the desired result?

 array('golf' = On the golf course or in the field of clover,
 'field' =  On the golf course or in the field of clover)); ?


 Marc


Here's something to mess around with, to fit to your liking.

?php
$one = array('golf','field');
$two = array(On the golf course or in the field of clover);
$result = array_explode($one,$two);

print_r($result);

function array_explode($delimiters,$array)
{
if ( !is_array($delimiters) || !is_array($array) ) {
//bail
return;
}
$string = $array[0];
$regex = @(.implode('|',$delimiters).)@;
return preg_split($regex,$string);
}
?


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



Re: [PHP] Explode Question

2011-05-17 Thread James Yerge
On 05/17/2011 09:09 PM, ad...@buskirkgraphics.com wrote:
 That is exactly it.
 Thanks James I knew it was simple just forgot how it was done.





 Richard L. Buskirk

 -Original Message-
 From: James Yerge [mailto:ja...@nixsecurity.org] 
 Sent: Tuesday, May 17, 2011 8:51 PM
 To: ad...@buskirkgraphics.com
 Cc: 'Marc Guay'; php-general@lists.php.net
 Subject: Re: [PHP] Explode Question

 On 05/17/2011 07:53 PM, ad...@buskirkgraphics.com wrote:
 The desired result is.

 Array
 (
  [0] =  On the;
  [1] =  course or in the;
  [2] =  of colver;
 );

 I am just not sure the delimiter can be an array in the Explode function.






 Richard L. Buskirk

 -Original Message-
 From: Marc Guay [mailto:marc.g...@gmail.com] 
 Sent: Tuesday, May 17, 2011 7:52 PM
 To: php-general@lists.php.net
 Subject: Re: [PHP] Explode Question

 $one = array(0 ='golf', 1 = 'field');
 $two = array(0 = On the golf course or in the field of clover);
 $array_exp = explode($one, $two);
 What's the desired result?

 array('golf' = On the golf course or in the field of clover,
 'field' =  On the golf course or in the field of clover)); ?


 Marc

 Here's something to mess around with, to fit to your liking.

 ?php
 $one = array('golf','field');
 $two = array(On the golf course or in the field of clover);
 $result = array_explode($one,$two);

 print_r($result);

 function array_explode($delimiters,$array)
 {
 if ( !is_array($delimiters) || !is_array($array) ) {
 //bail
 return;
 }
 $string = $array[0];
 $regex = @(.implode('|',$delimiters).)@;
 return preg_split($regex,$string);
 }
 ?




Not a problem, glad to be of help.


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



Re: [PHP] Explode-update-implode not working

2009-06-23 Thread Andrew Ballard
On Tue, Jun 23, 2009 at 12:11 PM, Bob McConnellr...@cbord.com wrote:
 At least not the way I expected it to. Apparently I am doing something
 wrong, but I can't find anything specific that explains it. This is in
 PHP 5.2.6.

 Here is the sequence I am trying to implement without the database
 portion. (This is typed in since the VNC I am using doesn't support
 pasting from a Linux client to a MS-Windows server.)

 -
 $buff = key1|value1~key2|value2;

 $lines = explode (~, $buff);

 foreach ($lines as $kvpair) {
   $line = explode (|, $kvpair);
   if ($line[0] == key1) {
      $line[1] = value3;
      $kvpair = implode (|, $line);
      break;
   }
 }
 $newbuff = implode (~, $lines);
 -

 $kvpair is modified, but that change is ignored by implode() with
 $newbuff still containing key1|value1.

 So why doesn't the change to $kvpair get brought in by implode? What
 should I do to update that value?

 Bob McConnell


See the second note at
http://www.php.net/manual/en/control-structures.foreach.php

Either of these should do what you want:

?php
$buff = key1|value1~key2|value2;

$lines = explode (~, $buff);

foreach ($lines as $kvpair) {
  $line = explode (|, $kvpair);
  if ($line[0] == key1) {
 $line[1] = value3;
 $kvpair = implode (|, $line);
 break;
  }
}
$newbuff = implode (~, $lines);
?

?php
$buff = key1|value1~key2|value2;

$lines = explode (~, $buff);

foreach ($lines as $key = $kvpair) {
  $line = explode (|, $kvpair);
  if ($line[0] == key1) {
 $line[1] = value3;
 $lines[$key] = implode (|, $line);
 break;
  }
}
$newbuff = implode (~, $lines);
?


Andrew

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



RE: [PHP] Explode-update-implode not working

2009-06-23 Thread Bob McConnell
Doh! I knew it would be something simple that I had overlooked. I recall 
reading that note last week and telling myself I would need to remember it. But 
that was then ...

Thank you, the code is working better now. I just wish I were.

Bob McConnell

-Original Message-
From: Andrew Ballard [mailto:aball...@gmail.com] 
Sent: Tuesday, June 23, 2009 12:25 PM
To: Bob McConnell
Cc: php-general@lists.php.net
Subject: Re: [PHP] Explode-update-implode not working

On Tue, Jun 23, 2009 at 12:11 PM, Bob McConnellr...@cbord.com wrote:
 At least not the way I expected it to. Apparently I am doing something
 wrong, but I can't find anything specific that explains it. This is in
 PHP 5.2.6.

 Here is the sequence I am trying to implement without the database
 portion. (This is typed in since the VNC I am using doesn't support
 pasting from a Linux client to a MS-Windows server.)

 -
 $buff = key1|value1~key2|value2;

 $lines = explode (~, $buff);

 foreach ($lines as $kvpair) {
   $line = explode (|, $kvpair);
   if ($line[0] == key1) {
      $line[1] = value3;
      $kvpair = implode (|, $line);
      break;
   }
 }
 $newbuff = implode (~, $lines);
 -

 $kvpair is modified, but that change is ignored by implode() with
 $newbuff still containing key1|value1.

 So why doesn't the change to $kvpair get brought in by implode? What
 should I do to update that value?

 Bob McConnell


See the second note at
http://www.php.net/manual/en/control-structures.foreach.php

Either of these should do what you want:

?php
$buff = key1|value1~key2|value2;

$lines = explode (~, $buff);

foreach ($lines as $kvpair) {
  $line = explode (|, $kvpair);
  if ($line[0] == key1) {
 $line[1] = value3;
 $kvpair = implode (|, $line);
 break;
  }
}
$newbuff = implode (~, $lines);
?

?php
$buff = key1|value1~key2|value2;

$lines = explode (~, $buff);

foreach ($lines as $key = $kvpair) {
  $line = explode (|, $kvpair);
  if ($line[0] == key1) {
 $line[1] = value3;
 $lines[$key] = implode (|, $line);
 break;
  }
}
$newbuff = implode (~, $lines);
?


Andrew

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



Re: [PHP] explode string at new line

2007-06-06 Thread Chris

Jim Lucas wrote:

Chris wrote:

Davi wrote:

Em Terça 05 Junho 2007 23:52, [EMAIL PROTECTED] escreveu:

That's exactly correct. Except I /think/ you should use \n instead of
'\n'.



Thank you for the reply... =)

I'll check this... BTW:

array explode ( string $delimiter, string $string [, int $limit] )

So, I was wrong...
The right way, probaly, is:

$str=explode(\n,$_POST[my_text]);


If it's coming from a textarea you'll want to use \r\n because a 
textarea uses both a carriage return (\r) and newline (\n) to separate.


Otherwise each element of the array will have a \r on the end which 
may end up causing you some issues later on.


I was wondering about this, I seem to recall that window/mac/*nix all do 
it differently.


With a little Google'ing I came across this.

http://www.sitepoint.com/forums/printthread.php?t=54074

This was written in 2002, so I am not sure about the Mac = \r.
Since they are using *nix now, it could be \n not sure

But the article had this to say:

Line breaks
People want to know how they can retain textarea line breaks in HTML. 
You should store text in the database in its original format (e.g. with 
just newlines) and then use nl2br() to convert newlines to HTML br / 
tags on display (thanks to the people here for teaching me that :)). 
That's all good, except for one problem with nl2br(): it doesn't seem to 
convert \r newlines (edit: this has now been fixed in PHP 4.2.0).


Windows uses \r\n newlines; *nix uses \n; Mac uses \r.

nl2br() works correctly on text from Windows/*nix because they contain 
\n. However, if you get text from a Mac, nl2br() will not convert its 
newlines (again, fixed in PHP 4.2.0). To remedy this, I use the 
following bit of code to convert \r\n or \r to \n before inserting it 
into the database. It won't hurt anything and ensures that nl2br() will 
work on the \n only newlines on display. Also, it has the side effect of 
saving 1 byte in the database per newline from Windows (by storing only 
\n instead of \r\n). :)


PHP Code:
$txt = preg_replace('/\r\n|\r/', \n, $txt);


Fair enough :)

I guess my thinking was since a textarea is a html 'standard' it would 
be consistent across all browsers/systems. I guess not :)


--
Postgresql  php tutorials
http://www.designmagick.com/

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



Re: [PHP] explode string at new line

2007-06-06 Thread Paul Novitski

At 6/5/2007 10:50 PM, Jim Lucas wrote:

Windows uses \r\n newlines; *nix uses \n; Mac uses \r.

...

PHP Code:
$txt = preg_replace('/\r\n|\r/', \n, $txt);



Another way to write that PCRE pattern is /\r\n?/ (one carriage 
return followed by zero or one linefeed).


I recall also running into \n\r although I can't recall which system uses it.

As an alternative to PCRE, we can pass arrays to PHP's replace functions, e.g.:

$txt = str_replace(array(\r\n, \n\r, \r), \n, $txt);

Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] explode string at new line

2007-06-06 Thread Davi
Em Quarta 06 Junho 2007 02:50, Jim Lucas escreveu:
 Chris wrote:
  Davi wrote:
  Em Terça 05 Junho 2007 23:52, [EMAIL PROTECTED] escreveu:
  That's exactly correct. Except I /think/ you should use \n instead of
  '\n'.
 
  array explode ( string $delimiter, string $string [, int $limit] )
 
  So, I was wrong...
  The right way, probaly, is:
 
  $str=explode(\n,$_POST[my_text]);
 
  If it's coming from a textarea you'll want to use \r\n because a
  textarea uses both a carriage return (\r) and newline (\n) to separate.
 
  Otherwise each element of the array will have a \r on the end which may
  end up causing you some issues later on.

 I was wondering about this, I seem to recall that window/mac/*nix all do
 it differently.

 http://www.sitepoint.com/forums/printthread.php?t=54074

 Line breaks
 People want to know how they can retain textarea line breaks in HTML.
 You should store text in the database in its original format (e.g. with
 just newlines) and then use nl2br() to convert newlines to HTML br /
 tags on display (thanks to the people here for teaching me that :)).
 That's all good, except for one problem with nl2br(): it doesn't seem to
 convert \r newlines (edit: this has now been fixed in PHP 4.2.0).

 PHP Code:
 $txt = preg_replace('/\r\n|\r/', \n, $txt);


Helped... =)

But... Why does it happen:

[code]

$object=mysql_fetch_object($result);

$texto = $object-texto;

$texto=preg_replace(/\r|\n/,,stripslashes($texto));
echo $texto;

[/code]

[output]

Teste
\r\nde formatação!
\r\nTudo funcionando...
\r\n

[/output]


I'm using stripslashse 'cause I'm getting the values from a DB.

Any kind of tip?

TIA


-- 
Davi Vidal
[EMAIL PROTECTED]
[EMAIL PROTECTED]
--
Religion, ideology, resources, land,
spite, love or just because...
No matter how pathetic the reason,
it's enough to start a war. 

Por favor não faça top-posting, coloque a sua resposta abaixo desta linha.
Please don't do top-posting, put your reply below the following line.



pgpXKjnY1odxa.pgp
Description: PGP signature


Re: [PHP] explode string at new line

2007-06-06 Thread Davi
Em Quarta 06 Junho 2007 10:54, Davi escreveu:
 But... Why does it happen:

 [code]

 $object=mysql_fetch_object($result);

 $texto = $object-texto;

 $texto=preg_replace(/\r|\n/,,stripslashes($texto));
 echo $texto;

 [/code]

 [output]

 Teste
 \r\nde formatação!
 \r\nTudo funcionando...
 \r\n

 [/output]


 I'm using stripslashse 'cause I'm getting the values from a DB.

 Any kind of tip?

 TIA

If I do:

[code]

echo \r\nJust testing... \r\n again...;

[/code]

The output is:

[output]

Just testing... again...

[/output]

And the source code (in browser) is:

[output]

Just testing...
again...

[/output]


Am I missing anything?

TIA

-- 
Davi Vidal
[EMAIL PROTECTED]
[EMAIL PROTECTED]
--
Religion, ideology, resources, land,
spite, love or just because...
No matter how pathetic the reason,
it's enough to start a war. 

Por favor não faça top-posting, coloque a sua resposta abaixo desta linha.
Please don't do top-posting, put your reply below the following line.



pgpCbBEc0rmeF.pgp
Description: PGP signature


Re: [PHP] explode string at new line

2007-06-06 Thread Jim Lucas

Davi wrote:

Em Quarta 06 Junho 2007 10:54, Davi escreveu:

But... Why does it happen:

[code]

$object=mysql_fetch_object($result);

$texto = $object-texto;

$texto=preg_replace(/\r|\n/,,stripslashes($texto));
echo $texto;

[/code]

[output]

Teste
\r\nde formatação!
\r\nTudo funcionando...
\r\n

[/output]


I'm using stripslashse 'cause I'm getting the values from a DB.

Any kind of tip?

TIA


If I do:

[code]

echo \r\nJust testing... \r\n again...;

[/code]

The output is:

how and where are you outputting this to?



[output]

Just testing... again...

[/output]

And the source code (in browser) is:

What OS?



[output]

Just testing...
again...

[/output]


Am I missing anything?

TIA




--
Jim Lucas

   Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them.

Twelfth Night, Act II, Scene V
by William Shakespeare

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



Re: [PHP] explode string at new line

2007-06-06 Thread Davi
Em Quarta 06 Junho 2007 13:20, Jim Lucas escreveu:
 Davi wrote:
  Em Quarta 06 Junho 2007 10:54, Davi escreveu:
  But... Why does it happen:
 
  [code]
 
  $object=mysql_fetch_object($result);
 
  $texto = $object-texto;
 
  $texto=preg_replace(/\r|\n/,,stripslashes($texto));
  echo $texto;
 
  [/code]
 
  [output]
 
  Teste
  \r\nde formatação!
  \r\nTudo funcionando...
  \r\n
 
  [/output]
 
 
  I'm using stripslashse 'cause I'm getting the values from a DB.
 
 
  If I do:
 
  [code]
 
  echo \r\nJust testing... \r\n again...;
 
  [/code]
 
  The output is:

 how and where are you outputting this to?


How: echo
Where: Firefox 2.0.0.3

  [output]
 
  Just testing... again...
 
  [/output]
 
  And the source code (in browser) is:

 What OS?


SuSE 9.3 (Server)

Gentoo Linux 1.12.9 [2007.0] (Desktop/Development)

  [output]
 
  Just testing...
  again...
 
  [/output]
 
 

-- 
Davi Vidal
[EMAIL PROTECTED]
[EMAIL PROTECTED]
--
Religion, ideology, resources, land,
spite, love or just because...
No matter how pathetic the reason,
it's enough to start a war. 

Por favor não faça top-posting, coloque a sua resposta abaixo desta linha.
Please don't do top-posting, put your reply below the following line.



pgpKvupfZO86S.pgp
Description: PGP signature


Re: [PHP] explode string at new line

2007-06-05 Thread heavyccasey

That's exactly correct. Except I /think/ you should use \n instead of '\n'.

On 6/5/07, Davi [EMAIL PROTECTED] wrote:


Hi all.

I've the fowlling string:

$_POST[my_text]=hi...\nthis is my multi-line\ntext;

Can I use explode to have something like:

$str[0]=hi...;
$str[1]=this is my multi-line;
$str[2]=text;

$str=explode($_POST[my_text],'\n');


TIA and sorry the *very* poor english.


--
Davi Vidal
[EMAIL PROTECTED]
[EMAIL PROTECTED]
--
Religion, ideology, resources, land,
spite, love or just because...
No matter how pathetic the reason,
it's enough to start a war. 

Por favor não faça top-posting, coloque a sua resposta abaixo desta linha.
Please don't do top-posting, put your reply below the following line.





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



Re: [PHP] explode string at new line

2007-06-05 Thread Davi
Em Terça 05 Junho 2007 23:52, [EMAIL PROTECTED] escreveu:
 That's exactly correct. Except I /think/ you should use \n instead of
 '\n'.


Thank you for the reply... =)

I'll check this... BTW:

array explode ( string $delimiter, string $string [, int $limit] )

So, I was wrong...
The right way, probaly, is:

$str=explode(\n,$_POST[my_text]);


Thank you very much.


-- 
Davi Vidal
[EMAIL PROTECTED]
[EMAIL PROTECTED]
--
Religion, ideology, resources, land,
spite, love or just because...
No matter how pathetic the reason,
it's enough to start a war. 

Por favor não faça top-posting, coloque a sua resposta abaixo desta linha.
Please don't do top-posting, put your reply below the following line.



pgpS3oEAG6jIw.pgp
Description: PGP signature


Re: [PHP] explode string at new line

2007-06-05 Thread Chris

Davi wrote:

Em Terça 05 Junho 2007 23:52, [EMAIL PROTECTED] escreveu:

That's exactly correct. Except I /think/ you should use \n instead of
'\n'.



Thank you for the reply... =)

I'll check this... BTW:

array explode ( string $delimiter, string $string [, int $limit] )

So, I was wrong...
The right way, probaly, is:

$str=explode(\n,$_POST[my_text]);


If it's coming from a textarea you'll want to use \r\n because a 
textarea uses both a carriage return (\r) and newline (\n) to separate.


Otherwise each element of the array will have a \r on the end which may 
end up causing you some issues later on.


--
Postgresql  php tutorials
http://www.designmagick.com/

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



Re: [PHP] explode string at new line

2007-06-05 Thread Davi
Em Quarta 06 Junho 2007 00:18, Chris escreveu:
 Davi wrote:
  Em Terça 05 Junho 2007 23:52, [EMAIL PROTECTED] escreveu:
  That's exactly correct. Except I /think/ you should use \n instead of
  '\n'.
 
  So, I was wrong...
  The right way, probaly, is:
 
  $str=explode(\n,$_POST[my_text]);

 If it's coming from a textarea you'll want to use \r\n because a
 textarea uses both a carriage return (\r) and newline (\n) to separate.

 Otherwise each element of the array will have a \r on the end which may
 end up causing you some issues later on.


Yes. Is a textarea. Thank you very much! =D


-- 
Davi Vidal
[EMAIL PROTECTED]
[EMAIL PROTECTED]
--
Religion, ideology, resources, land,
spite, love or just because...
No matter how pathetic the reason,
it's enough to start a war. 

Por favor não faça top-posting, coloque a sua resposta abaixo desta linha.
Please don't do top-posting, put your reply below the following line.



pgpctEzLbMQgx.pgp
Description: PGP signature


Re: [PHP] explode string at new line

2007-06-05 Thread Jim Lucas

Chris wrote:

Davi wrote:

Em Terça 05 Junho 2007 23:52, [EMAIL PROTECTED] escreveu:

That's exactly correct. Except I /think/ you should use \n instead of
'\n'.



Thank you for the reply... =)

I'll check this... BTW:

array explode ( string $delimiter, string $string [, int $limit] )

So, I was wrong...
The right way, probaly, is:

$str=explode(\n,$_POST[my_text]);


If it's coming from a textarea you'll want to use \r\n because a 
textarea uses both a carriage return (\r) and newline (\n) to separate.


Otherwise each element of the array will have a \r on the end which may 
end up causing you some issues later on.


I was wondering about this, I seem to recall that window/mac/*nix all do 
it differently.


With a little Google'ing I came across this.

http://www.sitepoint.com/forums/printthread.php?t=54074

This was written in 2002, so I am not sure about the Mac = \r.
Since they are using *nix now, it could be \n not sure

But the article had this to say:

Line breaks
People want to know how they can retain textarea line breaks in HTML. 
You should store text in the database in its original format (e.g. with 
just newlines) and then use nl2br() to convert newlines to HTML br / 
tags on display (thanks to the people here for teaching me that :)). 
That's all good, except for one problem with nl2br(): it doesn't seem to 
convert \r newlines (edit: this has now been fixed in PHP 4.2.0).


Windows uses \r\n newlines; *nix uses \n; Mac uses \r.

nl2br() works correctly on text from Windows/*nix because they contain 
\n. However, if you get text from a Mac, nl2br() will not convert its 
newlines (again, fixed in PHP 4.2.0). To remedy this, I use the 
following bit of code to convert \r\n or \r to \n before inserting it 
into the database. It won't hurt anything and ensures that nl2br() will 
work on the \n only newlines on display. Also, it has the side effect of 
saving 1 byte in the database per newline from Windows (by storing only 
\n instead of \r\n). :)


PHP Code:
$txt = preg_replace('/\r\n|\r/', \n, $txt);

Hope this helps

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



Re: [PHP] explode in mysql query

2007-04-27 Thread Zoltán Németh
2007. 04. 27, péntek keltezéssel 02.33-kor Sebe ezt írta:
 i have a mysql column that looks like this:
 
 groups
 ---
 12,7,10,6,14,11,2
 
 is it possible to select the row if `groups` contain 7 or 14?

you'd better put the groups info in a separate table, referenced by this
table. then you can simply

SELECT t1.* FROM whatever t1, groups t2 WHERE t1.id=t2.whatever_id AND
(t2.group=7 OR t2.group=14);

greets
Zoltán Németh

 trying to avoid running two queries and running explode() on it.
 
 i don't remember but i thought there was a way to use explode() on 
 something like this within a single query.
 

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



Re: [PHP] explode in mysql query

2007-04-27 Thread Paul Novitski

At 4/26/2007 11:33 PM, Sebe wrote:

i have a mysql column that looks like this:

groups
---
12,7,10,6,14,11,2

is it possible to select the row if `groups` contain 7 or 14?
trying to avoid running two queries and running explode() on it.



I would think a more efficient strategy would be a simple string 
search.  If you append a comma to the beginning and the end of your 
list so it becomes:


,12,7,10,6,14,11,2,

then you can search for:

,#,

where # is the desired integer.

Therefore you could use the MySQL syntax:

WHERE CONCAT(',', `groups`, ',') LIKE '%,7,%'
   OR CONCAT(',', `groups`, ',') LIKE '%,14,%'

Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] explode in mysql query

2007-04-27 Thread Sebe

Paul Novitski wrote:

At 4/26/2007 11:33 PM, Sebe wrote:

i have a mysql column that looks like this:

groups
---
12,7,10,6,14,11,2

is it possible to select the row if `groups` contain 7 or 14?
trying to avoid running two queries and running explode() on it.



I would think a more efficient strategy would be a simple string 
search.  If you append a comma to the beginning and the end of your 
list so it becomes:


,12,7,10,6,14,11,2,

then you can search for:

,#,

where # is the desired integer.

Therefore you could use the MySQL syntax:

WHERE CONCAT(',', `groups`, ',') LIKE '%,7,%'
   OR CONCAT(',', `groups`, ',') LIKE '%,14,%'

Regards,

Paul


thanks for the idea.. i also just came up with a solution using mysql 
FIND_IN_SET


eg: FIND_IN_SET('7', groups) OR FIND_IN_SET('14', groups)

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



RE: [PHP] explode in mysql query

2007-04-27 Thread Buesching, Logan J

 -Original Message-
 From: Paul Novitski [mailto:[EMAIL PROTECTED]
 Sent: Friday, April 27, 2007 3:01 AM
 To: php-general@lists.php.net
 Subject: Re: [PHP] explode in mysql query
 
 At 4/26/2007 11:33 PM, Sebe wrote:
 i have a mysql column that looks like this:
 
 groups
 ---
 12,7,10,6,14,11,2
You should never have tables that look like this.  If this is early in
the application development, look into 3rd normal form for SQL tables
(don't worry about 4th or 5th).  In a nutshell, here is what you should
be doing: you have a many to many relationship (big thing to note).
Whatever holds groups (lets call it foo) to groups.

So you should do something like this:

===
Foo --A table
===
Id -- columns
groups
Coln

===
Groups
===
Id
Col1
Col2
Col3

So then you create a 3rd table named

===
Foo_has_groups (or groups_has_foo, whichever sounds best)
===
Fooid
groupsid

So then, you can do much more powerful queries, with much less overhead.

Such as: 
SELECT t1.* FROM foo t1, groups t2 WHERE t1.id=t2.whatever_id AND
(t2.group=7 OR t2.group=14);

If you are reluctant to do any of these optimizations to your database,
then you better not worry about anywhere in your PHP code to do _ANY_
optimizations.  This will be your system bottleneck!  99% of the time
(maybe less) when you get a slow application, your bottlenecks will
be in your sql queries/design. 

Hopefully that all made sense

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



Re: [PHP] explode in mysql query

2007-04-27 Thread Richard Lynch
On Fri, April 27, 2007 1:33 am, Sebe wrote:
 i have a mysql column that looks like this:

 groups
 ---
 12,7,10,6,14,11,2

 is it possible to select the row if `groups` contain 7 or 14?
 trying to avoid running two queries and running explode() on it.

 i don't remember but i thought there was a way to use explode() on
 something like this within a single query.

It's a MySQL question, but I suspect that the REGEXP operator in MySQL
would let you find these with something like:

groups REGEXP '\\b7\\b' or groups REGEXP '\\b14\\b'

The \\b being a word boundary, if I remember correctly...

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] explode a string

2005-04-20 Thread Jochem Maas
Richard Lynch wrote:
On Tue, April 19, 2005 7:03 am, Jochem Maas said:
The 'other' guy mentioned that while() is faster than foreach,
is this true?

Don't know ; Don't care.
You should never loop through so many things in PHP that it matters in the
first place :-)

I read a few days ago somewhere on php.net that foreach() is the
recommended (by php devs) way of iterating over arrays

[shrug]
That's probably because they're tired of people not understanding the
internal pointer array, and asking FAQs about it.  Or maybe not.  Ask them
why they prefer it.  I sure don't know.

also, compare these 2 lines:
while (list(, $idcat) = each($idcats)){ /* ... */ }
foreach ($idcats as $idcat){ /* ... */ }
now its seems to me that the foreach version is 'up' 2 function calls

None of those are function calls.
They are all language constructs.  Okay, each() *might* be a function...
I'm not sure how much difference there is in the number of language
constructs used, nor if they are even comparable in sheer numbers the way
functions are.
ah yes, lang constructs rather than function calls.
foreach is probably slower, I think, because it creates a *copy* of the
array to work on, so it won't mess up the original and its internal
pointer.
unless I'm mistaken its a copy-on-change, so unless you are changing the
the array inside the loop you don't suffer the actuall copy penalty - can anyone
knowledgable on php internals confirm or deny this?
actually now I think of it you can use references in a foreach statement:
php -r '
$arr = array(1,2,3);
foreach($arr as $k = $v) {
$v++;
}
var_dump($arr);
'
which suggests that a copy is not (always?) being made...
Again, with 200 bytes, you are wasting your time to worry about any of this.
true, It's purely a theoretical interest - deeper understanding is alway 
nice :-)
...its not even my 200 bytes we're talking about ;-)

on the while loop, all else being equal the foreach loop has to be faster
(given that calling functions is relatively very expensive)...
or is foreach() _really_ heavy when compared to while()?

Why don't you just benchmark it on your own machine and find out?
because I don't have the skills to write a test/benchmark that I _know_ is
kosher (and not skewed by a million of my misconceptions, besides I run so much
stuff on my machine that speed can be severely affected by things like
apache or firebird running in the background
that and I lazy ;-) (or I just don't care enough to invest time investigating 
this)

not that I care too much, I find foreach() more pleasing to the eye and
there is
less to type (in the given example).

I'm an old dog, and I don't quite understand for sure how this new-fangled
foreach thingie works.  I'd spend more time looking it up and reading
about it than just typing what I *know* works. [shrug]



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


Re: [PHP] explode a string

2005-04-20 Thread Saswat Praharaj
explode by ,
$output1 = explode(,,$string);

use a loop and explode  array $output1 by : 

Hope this helps.

Saswat

On 4/18/05, Sebastian [EMAIL PROTECTED] wrote:
 $string = '4:gaming,5:hardware,3:software,8:security';
 
 what is the best way to explode then loop this string after its taken apart.
 
 output should be something like:
 
 $id = 4
 $cat = gaming
 
 etc..
 
 im just looking for the best/fastest way to do this. the string can grow to
 200 or so bytes, maybe more.
 
 should i list(), while(), explode it, or should i explode it and foreach it?
 or..?
 
 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] explode a string

2005-04-19 Thread Jochem Maas
Richard Lynch wrote:
On Mon, April 18, 2005 4:34 am, Sebastian said:
$string = '4:gaming,5:hardware,3:software,8:security';

$idcats = explode(',', $string);
while (list(, $idcat) = each($idcats)){
  list($id, $cat) = explode(':', $idcat);
  echo \$id = $idbr /\n;
  echo \$cat = $catbr /\n;
}
The 'other' guy mentioned that while() is faster than foreach,
is this true?
I read a few days ago somewhere on php.net that foreach() is the
recommended (by php devs) way of iterating over arrays
also, compare these 2 lines:
while (list(, $idcat) = each($idcats)){ /* ... */ }
foreach ($idcats as $idcat){ /* ... */ }
now its seems to me that the foreach version is 'up' 2 function calls
on the while loop, all else being equal the foreach loop has to be faster
(given that calling functions is relatively very expensive)...
or is foreach() _really_ heavy when compared to while()?
not that I care too much, I find foreach() more pleasing to the eye and there is
less to type (in the given example).
:-)
rgds,
Jochem

what is the best way to explode then loop this string after its taken
apart.
output should be something like:
$id = 4
$cat = gaming
etc..
im just looking for the best/fastest way to do this. the string can grow
to
200 or so bytes, maybe more.

200 bytes is chump-change.
It really doesn't matter how you do this, within reason.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] explode a string

2005-04-19 Thread Petar Nedyalkov
On Tuesday 19 April 2005 17:03, Jochem Maas wrote:
 Richard Lynch wrote:
  On Mon, April 18, 2005 4:34 am, Sebastian said:
 $string = '4:gaming,5:hardware,3:software,8:security';
 
  $idcats = explode(',', $string);
  while (list(, $idcat) = each($idcats)){
list($id, $cat) = explode(':', $idcat);
echo \$id = $idbr /\n;
echo \$cat = $catbr /\n;
  }

 The 'other' guy mentioned that while() is faster than foreach,
 is this true?

http://www.sitepoint.com/article/php5-standard-library

Note that the crude benchmarks I've performed suggest that calling the 
methods directly is faster than using foreach, because the latter introduces 
another layer of redirection that must be resolved at runtime by PHP.


 I read a few days ago somewhere on php.net that foreach() is the
 recommended (by php devs) way of iterating over arrays

 also, compare these 2 lines:

 while (list(, $idcat) = each($idcats)){ /* ... */ }
 foreach ($idcats as $idcat){ /* ... */ }

 now its seems to me that the foreach version is 'up' 2 function calls
 on the while loop, all else being equal the foreach loop has to be faster
 (given that calling functions is relatively very expensive)...
 or is foreach() _really_ heavy when compared to while()?

 not that I care too much, I find foreach() more pleasing to the eye and
 there is less to type (in the given example).

 :-)

 rgds,
 Jochem

 what is the best way to explode then loop this string after its taken
 apart.
 
 output should be something like:
 
 $id = 4
 $cat = gaming
 
 etc..
 
 im just looking for the best/fastest way to do this. the string can grow
 to
 200 or so bytes, maybe more.
 
  200 bytes is chump-change.
 
  It really doesn't matter how you do this, within reason.

-- 

Cyberly yours,
Petar Nedyalkov
Devoted Orbitel Fan :-)

PGP ID: 7AE45436
PGP Public Key: http://bu.orbitel.bg/pgp/bu.asc
PGP Fingerprint: 7923 8D52 B145 02E8 6F63 8BDA 2D3F 7C0B 7AE4 5436


pgpFE7VCEyn7m.pgp
Description: PGP signature


Re: [PHP] explode a string

2005-04-19 Thread Jochem Maas
Petar Nedyalkov wrote:
On Tuesday 19 April 2005 17:03, Jochem Maas wrote:
Richard Lynch wrote:
On Mon, April 18, 2005 4:34 am, Sebastian said:
$string = '4:gaming,5:hardware,3:software,8:security';
$idcats = explode(',', $string);
while (list(, $idcat) = each($idcats)){
 list($id, $cat) = explode(':', $idcat);
 echo \$id = $idbr /\n;
 echo \$cat = $catbr /\n;
}
The 'other' guy mentioned that while() is faster than foreach,
is this true?

sorry to call you the 'other' guy, Petar - I was being lazy.
http://www.sitepoint.com/article/php5-standard-library
Note that the crude benchmarks I've performed suggest that calling the 
methods directly is faster than using foreach, because the latter introduces 
another layer of redirection that must be resolved at runtime by PHP.
are we talking about iterating over an Iterator or an array()?
Harry Fuecks is talking about iterating over a php5 object..., your
question/example features a straight array.

I read a few days ago somewhere on php.net that foreach() is the
recommended (by php devs) way of iterating over arrays
also, compare these 2 lines:
while (list(, $idcat) = each($idcats)){ /* ... */ }
foreach ($idcats as $idcat){ /* ... */ }
now its seems to me that the foreach version is 'up' 2 function calls
on the while loop, all else being equal the foreach loop has to be faster
(given that calling functions is relatively very expensive)...
or is foreach() _really_ heavy when compared to while()?
not that I care too much, I find foreach() more pleasing to the eye and
there is less to type (in the given example).
:-)
rgds,
Jochem

what is the best way to explode then loop this string after its taken
apart.
output should be something like:
$id = 4
$cat = gaming
etc..
im just looking for the best/fastest way to do this. the string can grow
to
200 or so bytes, maybe more.
200 bytes is chump-change.
It really doesn't matter how you do this, within reason.

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


Re: [PHP] explode a string

2005-04-19 Thread Richard Lynch
On Tue, April 19, 2005 7:03 am, Jochem Maas said:
 The 'other' guy mentioned that while() is faster than foreach,
 is this true?

Don't know ; Don't care.

You should never loop through so many things in PHP that it matters in the
first place :-)

 I read a few days ago somewhere on php.net that foreach() is the
 recommended (by php devs) way of iterating over arrays

[shrug]

That's probably because they're tired of people not understanding the
internal pointer array, and asking FAQs about it.  Or maybe not.  Ask them
why they prefer it.  I sure don't know.

 also, compare these 2 lines:

 while (list(, $idcat) = each($idcats)){ /* ... */ }
 foreach ($idcats as $idcat){ /* ... */ }

 now its seems to me that the foreach version is 'up' 2 function calls

None of those are function calls.

They are all language constructs.  Okay, each() *might* be a function...

I'm not sure how much difference there is in the number of language
constructs used, nor if they are even comparable in sheer numbers the way
functions are.

foreach is probably slower, I think, because it creates a *copy* of the
array to work on, so it won't mess up the original and its internal
pointer.

Again, with 200 bytes, you are wasting your time to worry about any of this.

 on the while loop, all else being equal the foreach loop has to be faster
 (given that calling functions is relatively very expensive)...
 or is foreach() _really_ heavy when compared to while()?

Why don't you just benchmark it on your own machine and find out?

 not that I care too much, I find foreach() more pleasing to the eye and
 there is
 less to type (in the given example).

I'm an old dog, and I don't quite understand for sure how this new-fangled
foreach thingie works.  I'd spend more time looking it up and reading
about it than just typing what I *know* works. [shrug]

-- 
Like Music?
http://l-i-e.com/artists.htm

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



Re: [PHP] explode a string

2005-04-18 Thread Petar Nedyalkov
On Monday 18 April 2005 14:34, Sebastian wrote:
 $string = '4:gaming,5:hardware,3:software,8:security';

 what is the best way to explode then loop this string after its taken
 apart.

 output should be something like:

 $id = 4
 $cat = gaming

 etc..

 im just looking for the best/fastest way to do this. the string can grow to
 200 or so bytes, maybe more.

 should i list(), while(), explode it, or should i explode it and foreach
 it? or..?

while is faster than foreach. check the iterator section in SPL for details.


 thanks.

-- 

Cyberly yours,
Petar Nedyalkov
Devoted Orbitel Fan :-)

PGP ID: 7AE45436
PGP Public Key: http://bu.orbitel.bg/pgp/bu.asc
PGP Fingerprint: 7923 8D52 B145 02E8 6F63 8BDA 2D3F 7C0B 7AE4 5436


pgpa0VNdMvmfC.pgp
Description: PGP signature


Re: [PHP] explode a string

2005-04-18 Thread Richard Lynch
On Mon, April 18, 2005 4:34 am, Sebastian said:
 $string = '4:gaming,5:hardware,3:software,8:security';

$idcats = explode(',', $string);
while (list(, $idcat) = each($idcats)){
  list($id, $cat) = explode(':', $idcat);
  echo \$id = $idbr /\n;
  echo \$cat = $catbr /\n;
}

 what is the best way to explode then loop this string after its taken
 apart.

 output should be something like:

 $id = 4
 $cat = gaming

 etc..

 im just looking for the best/fastest way to do this. the string can grow
 to
 200 or so bytes, maybe more.

200 bytes is chump-change.

It really doesn't matter how you do this, within reason.

-- 
Like Music?
http://l-i-e.com/artists.htm

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



RE: [PHP] explode and PATH_SEPARATOR

2004-11-15 Thread Araceli Pulido
This constant is part of the directory functions.

See: http://www.php.net/manual/en/ref.dir.php

Araceli.

-Original Message-
From: Francisco M. Marzoa Alonso [mailto:[EMAIL PROTECTED]
Sent: Monday, November 15, 2004 5:18 PM
To: PHP-General
Subject: [PHP] explode and PATH_SEPARATOR


Taking this code:

pre
?php

define (PATH_SEPARATOR, /);

$String=Root/One/Two/Three/Last;

$arr = explode ( PATH_SEPARATOR, $String );
var_dump ( $arr );

$arr = explode ( /, $String );
var_dump ( $arr );
?
/pre

It works fine in second case returing a five elements array, but in the 
first one it returns an array with just one elemen that's the source 
string itself. I've test it also changing PATH_SEPARATOR by SEPARATOR in 
both cases, and it works nice... Is PATH_SEPARATOR any kind of reserved 
word or so?

Thx.

-- 
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] explode and PATH_SEPARATOR

2004-11-15 Thread Ryan King
On Nov 15, 2004, at 10:17 AM, Francisco M. Marzoa Alonso wrote:
Taking this code:
pre
?php
define (PATH_SEPARATOR, /);
$String=Root/One/Two/Three/Last;
$arr = explode ( PATH_SEPARATOR, $String );
var_dump ( $arr );
$arr = explode ( /, $String );
var_dump ( $arr );
?
/pre
PATH_SEPARATOR is is a predefined constant, so you'll need to use 
something else, but you still need to put quotes around it:

define('NOT_PATH_SEPARATOR', '/');
-ryan
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Explode, Arrays and Checkboxes

2004-09-08 Thread zareef ahmed
HI,

--- Matt Winslow [EMAIL PROTECTED] wrote:

 I'm not new to PHP, but I have very little
 experience with arrays.  I have comma separated
 values in a database, that I need to pull out,
 explode into an array, then check certain checkboxes
 if they exist.
 
 I have two variables:
 
 $x = 2,10,34
 $y = 28,15,16
 
 I need to explode them both, so that the values of
 $x are they keys, and the values of $y are the
 values.  Is that possible?

yes see array_combine function

http://www.php.net/array_combine


 I have a form, with checkboxes that are named
 $product[1] through [40].  Next to them are
 textboxes labeled $price[1] through [40].  How would
 make the form, when it loads, have $product[2],
 [10], [34] checked, with $price[2], [10], and [34]
 equal to 28, 15, and 16 respecively.

a sensible use of foreach and if can easily do so.

zareef ahmed

=
Homepage :: http://www.zasaifi.com



___
Do you Yahoo!?
Win 1 of 4,000 free domain names from Yahoo! Enter now.
http://promotions.yahoo.com/goldrush

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



Re: [PHP] Explode, Arrays and Checkboxes

2004-09-08 Thread Curt Zirzow
* Thus wrote Matt Winslow:
 I'm not new to PHP, but I have very little experience with arrays.  I have comma 
 separated values in a database, that I need to pull out, explode into an array, then 
 check certain checkboxes if they exist.
 
 I have two variables:
 
 $x = 2,10,34
 $y = 28,15,16
 
 I need to explode them both, so that the values of $x are they keys, and the values 
 of $y are the values.  Is that possible?

$final = array();
$Y = explode(',', $y);

foreach(explode(',', $x) as $key = $val ) {
  $final[$val] = $Y[$key];
}

var_dump($final);

 
 I have a form, with checkboxes that are named $product[1] through [40].  Next to 
 them are textboxes labeled $price[1] through [40].  How would make the form, when it 
 loads, have $product[2], [10], [34] checked, with $price[2], [10], and [34] equal to 
 28, 15, and 16 respecively.
 

What is the relationship between the $x,$y and $product,$price?
I'm not sure I quite grasp what your trying to do.

If I understand correctly, the situation you describe ends up not
being a one-one relationship. So a user could select 4 prices with
3 products or vice versa. Which will make things difficult to match
up products/prices.


Curt
-- 
The above comments may offend you. flame at will.

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



Re: [PHP] Explode, Arrays and Checkboxes

2004-09-08 Thread Curt Zirzow
* Thus wrote zareef ahmed:
 HI,
 
  
  I have two variables:
  
  $x = 2,10,34
  $y = 28,15,16
  
  I need to explode them both, so that the values of
  $x are they keys, and the values of $y are the
  values.  Is that possible?
 
 yes see array_combine function
 
 http://www.php.net/array_combine

heh.. there are so many array_* functions i forgot about that one.
Sometimes that array documentation can be so overwhelming.


Curt
-- 
The above comments may offend you. flame at will.

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



Re: [PHP] explode() an array and grep out a string

2004-02-07 Thread Adam Bregenzer
On Sat, 2004-02-07 at 03:09, Bobby R.Cox wrote:
 Is it possible to explode an array and have it exclude a certain 
 string.   I currently have an array that is an ldapsearch that returns 
 sub-accounts of a parent account. These accounts are then displayed so 
 customer can either change the passwd or delete them.Thing is 
 ldapsearch returns everymatch which includes the parent account, which 
 is already listed on the page as the parent account.  I would like to 
 eliminate the second listing of the parent account where the 
 sub-accounts are listed.

Try this:

$parent_account = 'parent_name';
$ldap_results = array('account1','account2','parent_name');
$results = array_diff($ldap_results, array($parent_account));

$results will now have only account1 and account2.

-- 
Adam Bregenzer
[EMAIL PROTECTED]
http://adam.bregenzer.net/

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



RE: [PHP] explode separate lines

2004-02-04 Thread Vail, Warren
$result = explode(\n, $orignalvalue);

Beware, there are several caveats with line feeds.  Depending on where the
data originated, it could be \r\n or \r.

Warren Vail


-Original Message-
From: Diana Castillo [mailto:[EMAIL PROTECTED]
Sent: Wednesday, February 04, 2004 8:50 AM
To: [EMAIL PROTECTED]
Subject: [PHP] explode separate lines


does anyone know how to do an explode where the separator is a linefeed?

--
Diana Castillo

-- 
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] explode separate lines

2004-02-04 Thread Burhan Khalid
Diana Castillo wrote:
 does anyone know how to do an explode where the separator is a
 linefeed? 
 

You could try explode(\n, $stuff);, but if you are wanting to read
information from a file and store each line in an array, the file() function
does exactly that.


-- 
Burhan Khalid
phplist[at]meidomus[dot]com

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



[PHP] [ERR] RE: [PHP] explode separate lines

2004-02-04 Thread postmaster
Transmit Report:

 To: [EMAIL PROTECTED], 402 Local User Inbox Full ([EMAIL PROTECTED])
---BeginMessage---
Diana Castillo wrote:
 does anyone know how to do an explode where the separator is a
 linefeed? 
 

You could try explode(\n, $stuff);, but if you are wanting to read
information from a file and store each line in an array, the file() function
does exactly that.


-- 
Burhan Khalid
phplist[at]meidomus[dot]com

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

---End Message---


RE: [PHP] explode()

2003-11-17 Thread Jay Blanchard
[snip]
I am having a user enter a phrase into a textbox, and then I need to 
seperate the words he has typed into variables so I can use each one 
in an sql statement.  I know I will use the explode() function to do
this, 
but how will I know how many variables I've created.  For instance, if a

user types in 3 words seperated by spaces, how will I know i'll have 
var[0] through var[2]?  how about when they type in 2 words or 4 words?

How will I know how many words they have typed in?  The only way I can 
think of to do this is:
[/snip]

Use count() http://www.php.net/count

Counts the array ...

$arrayFoo = explode( , $theLine);
$countFoo = count($arrayFoo);

for($i = 0; $i  $countFoo; $i++){
   echo $arrayFoo[$i];
}

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



RE: [PHP] Explode a string

2003-11-12 Thread Jay Blanchard
[snip]
Any ideas how to do this,

I have a string

734088+3+734132+9+734138+80+781007+1+

I need to place the string into a multi-array like so

array[0][0] = 734088
array[0][1] = 3

etc...

Now ive tried everything i know any ideas?
[/snip]

start with explode 

$arrString = explode(+, $stringYouAreWorkingWith);

Then loop through it, placing the pairs into two-dimensional array you
mention above

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



RE: [PHP] Explode a string

2003-11-12 Thread Chris W. Parker
Erin mailto:[EMAIL PROTECTED]
on Wednesday, November 12, 2003 9:13 AM said:

 734088+3+734132+9+734138+80+781007+1+
 
 I need to place the string into a multi-array like so
 
 array[0][0] = 734088
 array[0][1] = 3
[snip]
 Now ive tried everything i know any ideas?

Yes. You need to somehow differentiate between the different columns and
rows. What I suggest you do is change every other + to something else
like a ; and then split on that.

Without knowing any other way to do this I would use a regex to skip the
first + and change second one, repeating this until the end of the
string.

Then you can explode() on + and ;.


hth,
Chris.
--
Don't like reformatting your Outlook replies? Now there's relief!
http://home.in.tum.de/~jain/software/outlook-quotefix/

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



RE: [PHP] Explode a string

2003-11-12 Thread Chris W. Parker
Chris W. Parker 
on Wednesday, November 12, 2003 9:19 AM said:

 Without knowing any other way to do this I would use a regex to skip
 the first + and change second one, repeating this until the end of the
 string.

Considering Jay's answer for this question, do I always do things the
hard way or what??

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



RE: [PHP] Explode a string

2003-11-12 Thread Jay Blanchard
[snip]
Considering Jay's answer for this question, do I always do things the
hard way or what??
[/snip]

Young Grasshopper...there is more than one way to do things, a lot of
them are rightsome are just harder than others. 

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



RE: [PHP] Explode a string

2003-11-12 Thread Wouter van Vliet
Jay Blanchard wrote:
 [snip]
 Considering Jay's answer for this question, do I always do things the
 hard way or what?? [/snip]
 
 Young Grasshopper...there is more than one way to do things,
 a lot of them are rightsome are just harder than others.

Isn't that the diplomatic equivalent of yes, sometimes you tend to do the
hard way?

hehe

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



Re: [PHP] explode () question

2003-11-10 Thread Chris Hayes

$rint1= rtrim($rintydata);
 echo $rint1;
 $rint2= explode(:, $rint1);
  The data starts like this (from and email, there are many) ;

 Time: November 9th 2003, 10:37AM - PST
 IP Address: xx.xx.xxx.xxx
 Browser Type: Opera/7.20 (Windows NT 5.1; U)  [en]
 Referer:
  The problem is that when I do this ;

while( $res=each($rint2) )
{
  echo br$res[1]br;
};
the colon in Time messes things up.

 here is the result ;

Time
November 8th 2003, 07
15PM - PST IP Address
xx.xx.xx.xxx Browser Type
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) Referer
when what I really want is ;

Time - November 8th 2003, 07:15PM - PST
IP - Address xx.xx.xx.xxx
Browser Type - Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
Referer -
  I can't figure out how to do an ereg that will replace just the colon 
in Time nor can I find a way to make explode ignore it.  This may even be 
a completely wrong approach, any help would be appreciated.
Do you first split the lines?
What about a simple strpos and substr?
$colon=strpos(':',$res) will get you the position of only the 1st colon.
then strpos ($res, 0, $colon-1) will get you the 1st part
and strpos ($res, $colon, strlen($res))  the second part.
disclaimers: not tested. not guaranteed to be working. just a suggestion. 
check the manual to fix it.

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


RE: [PHP] explode () question

2003-11-10 Thread Chris W. Parker
Malcolm mailto:[EMAIL PROTECTED]
on Monday, November 10, 2003 9:13 AM said:

I can't figure out how to do an ereg that will replace just the
 colon in Time nor can I find a way to make explode ignore it.  This
 may even be a completely wrong approach, any help would be
 appreciated. 

What you'll probably want to do is write a regex that changes the colon
you're trying to separate on into something else.

Go from:

Time: ...
Other Thing: ...
Different: ...

To:

Time% ...
Other Thing% ...
Different% ...

After you've done this you can easily explode() based on the %.

I'm not very good with regex's off the top of my head so I suggest you
get The Regex Coach (easily found via google) and experiment.


Chris.
--
Don't like reformatting your Outlook replies? Now there's relief!
http://home.in.tum.de/~jain/software/outlook-quotefix/

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



RE: [PHP] explode () question

2003-11-10 Thread Wouter van Vliet
(after more and more discussion, this will be my first non-top post) 

 
 $rint1= rtrim($rintydata);
   echo $rint1;
   $rint2= explode(:, $rint1);
 
The data starts like this (from and email, there are many) ;
 
   Time: November 9th 2003, 10:37AM - PST  IP Address: xx.xx.xxx.xxx  
  Browser Type: Opera/7.20 (Windows NT 5.1; U)  [en]
   Referer:
 
The problem is that when I do this ;
 
 
 while( $res=each($rint2) )
 {
echo br$res[1]br;
 };
 
 the colon in Time messes things up.
 
   here is the result ;
 
 Time
 November 8th 2003, 07
 15PM - PST IP Address
 xx.xx.xx.xxx Browser Type
 Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) Referer
 
 when what I really want is ;
 
 Time - November 8th 2003, 07:15PM - PST IP - Address xx.xx.xx.xxx 
 Browser Type - Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) 
 Referer -

I'd try something like:
  1 ?php
  2 $String = 'From: Wouter van Vliet [EMAIL PROTECTED]';
  3 preg_match('/^\s*([^:]*)\s*:\s*(.*)$/', $String, $Matches);
  4
  5 print_r($Matches);
  6
  7 ?

== OUTPUT:
Array
(
[0] = From: Wouter van Vliet [EMAIL PROTECTED]
[1] = From
[2] = Wouter van Vliet [EMAIL PROTECTED]
)

From here you'd be able to manipulate the things you want in any format
you'd want it to have. Or use preg_match_all() if you have all mail headers
in one variable.

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



Re: [PHP] explode () question

2003-11-10 Thread Malcolm
  Thanks to everyone who replied.  I have taken the short route and 
changed the source data.
I should have thought of that first I suppose.
 Now I have a few existing records to edit but from now on I'll be 
automagic.

On Mon, 10 Nov 2003 19:00:52 +0100, Wouter Van Vliet [EMAIL PROTECTED] 
wrote:

(after more and more discussion, this will be my first non-top post)

$rint1= rtrim($rintydata);
  echo $rint1;
  $rint2= explode(:, $rint1);

   The data starts like this (from and email, there are many) ;

  Time: November 9th 2003, 10:37AM - PST  IP Address: xx.xx.xxx.xxx
 Browser Type: Opera/7.20 (Windows NT 5.1; U)  [en]
  Referer:

   The problem is that when I do this ;


while( $res=each($rint2) )
{
   echo br$res[1]br;
};

the colon in Time messes things up.

  here is the result ;

Time
November 8th 2003, 07
15PM - PST IP Address
xx.xx.xx.xxx Browser Type
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) Referer

when what I really want is ;

Time - November 8th 2003, 07:15PM - PST IP - Address xx.xx.xx.xxx
Browser Type - Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
Referer -
I'd try something like:
  1 ?php
  2 $String = 'From: Wouter van Vliet [EMAIL PROTECTED]';
  3 preg_match('/^\s*([^:]*)\s*:\s*(.*)$/', $String, $Matches);
  4
  5 print_r($Matches);
  6
  7 ?
== OUTPUT:
Array
(
[0] = From: Wouter van Vliet [EMAIL PROTECTED]
[1] = From
[2] = Wouter van Vliet [EMAIL PROTECTED]
)
From here you'd be able to manipulate the things you want in any format
you'd want it to have. Or use preg_match_all() if you have all mail 
headers
in one variable.


--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] explode and escape character for string separator

2003-07-18 Thread Chris Shiflett
--- Reuben D. Budiardja [EMAIL PROTECTED] wrote:
 Suppose I have a long string like
 $myStr = $string1:$string2:$string3;
 
 I can obviously explode them using : as the separator. But what if 
 $string1 contains the character : by itself?

You should strive to make your delimiter unique. A delimiter that might
possibly appear within the items it is meant to delimit is no longer a
delimiter.

Chris

=
Become a better Web developer with the HTTP Developer's Handbook
http://httphandbook.org/

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



Re: [PHP] explode and escape character for string separator

2003-07-18 Thread Reuben D. Budiardja
On Friday 18 July 2003 02:42 pm, Chris Shiflett wrote:
 --- Reuben D. Budiardja [EMAIL PROTECTED] wrote:
  Suppose I have a long string like
  $myStr = $string1:$string2:$string3;
 
  I can obviously explode them using : as the separator. But what if
  $string1 contains the character : by itself?

 You should strive to make your delimiter unique. A delimiter that might
 possibly appear within the items it is meant to delimit is no longer a
 delimiter.

I did strive for that. But whatever character I choose, the problem remains 
that we can't guarantee that it's going ot be only used as deliminater, since 
the deliminated string is an input from user. So the problem remains.

RDB


-- 
-
/\  ASCII Ribbon Campaign against HTML
\ /  email and proprietary format
 X   attachments.
/ \
-
Have you been used by Microsoft today?
Choose your life. Choose freedom.
Choose LINUX.
-


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



Re: [PHP] explode and escape character for string separator

2003-07-18 Thread CPT John W. Holmes
 On Friday 18 July 2003 02:42 pm, Chris Shiflett wrote:
  --- Reuben D. Budiardja [EMAIL PROTECTED] wrote:
   Suppose I have a long string like
   $myStr = $string1:$string2:$string3;
  
   I can obviously explode them using : as the separator. But what if
   $string1 contains the character : by itself?
 
  You should strive to make your delimiter unique. A delimiter that might
  possibly appear within the items it is meant to delimit is no longer a
  delimiter.

 I did strive for that. But whatever character I choose, the problem
remains
 that we can't guarantee that it's going ot be only used as deliminater,
since
 the deliminated string is an input from user. So the problem remains.

So choose another method.

---John Holmes...


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



Re: [PHP] explode and escape character for string separator

2003-07-18 Thread Brad Pauly
Reuben D. Budiardja wrote:

I did strive for that. But whatever character I choose, the problem remains 
that we can't guarantee that it's going ot be only used as deliminater, since 
the deliminated string is an input from user. So the problem remains.
Are you adding the delimiter? If so, maybe you could escape that 
character in the users input when you add it.

- Brad



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


Re: [PHP] explode and escape character for string separator

2003-07-18 Thread Brent Baisley
One set of delimiters I often use for text files is ~~ or ^^. They are 
fairly unique. If they do appear in a file then there is probably 
garbage in the file and I want to know about. For my templates 
delimiter I use {::TagName::}. You could use }::{ as your delimiter. 
Don't limit yourself to just a single character. Although the upside 
down ! or ? are nice if you are not using Spanish.

On Friday, July 18, 2003, at 03:04 PM, Reuben D. Budiardja wrote:

I did strive for that. But whatever character I choose, the problem 
remains
that we can't guarantee that it's going ot be only used as 
deliminater, since
the deliminated string is an input from user. So the problem remains.
--
Brent Baisley
Systems Architect
Landover Associates, Inc.
Search  Advisory Services for Advanced Technology Environments
p: 212.759.6400/800.759.0577
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] explode and escape character for string separator

2003-07-18 Thread Reuben D. Budiardja
On Friday 18 July 2003 03:01 pm, you wrote:
  On Friday 18 July 2003 02:42 pm, Chris Shiflett wrote:
   --- Reuben D. Budiardja [EMAIL PROTECTED] wrote:
Suppose I have a long string like
$myStr = $string1:$string2:$string3;
   
I can obviously explode them using : as the separator. But what if
$string1 contains the character : by itself?
  
   You should strive to make your delimiter unique. A delimiter that might
   possibly appear within the items it is meant to delimit is no longer a
   delimiter.
 
  I did strive for that. But whatever character I choose, the problem

 remains

  that we can't guarantee that it's going ot be only used as deliminater,

 since

  the deliminated string is an input from user. So the problem remains.

 So choose another method.

I would if I can think of better method.

That answer does not help. 

RDB


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



Re: [PHP] explode and escape character for string separator

2003-07-18 Thread Jason Wong
On Saturday 19 July 2003 03:04, Reuben D. Budiardja wrote:

  You should strive to make your delimiter unique. A delimiter that might
  possibly appear within the items it is meant to delimit is no longer a
  delimiter.

 I did strive for that. But whatever character I choose, the problem remains
 that we can't guarantee that it's going ot be only used as deliminater,
 since the deliminated string is an input from user. So the problem remains.

Do note that your delimiter is not limited to a single character, it can be a 
sequence of characters.

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
Horner's Five Thumb Postulate:
Experience varies directly with equipment ruined.
*/


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



Re: [PHP] explode and escape character for string separator

2003-07-18 Thread Tyler
load a bunch of characters into an array. Do a loop
through that array and check all of your $strings for
the  current character in your loop.  If the current
array character does not exist in any of them, you
have your delimiter.

I could put together an example if you want me to.


__
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

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



Re: [PHP] explode and escape character for string separator

2003-07-18 Thread Chris Sherwood
After reading your problem

this is what I think you should do is dont let the user enter the string
predelimited
have them enter each individual string at which point you can safely search
for the delimiter and replace it with the character of your choice _ is a
favorite of mine.

then rebuild the string and delimit it yourself

Chris
- Original Message -
From: Reuben D. Budiardja [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Friday, July 18, 2003 11:47 AM
Subject: [PHP] explode and escape character for string separator



Hi all,
Suppose I have a long string like
$myStr = $string1:$string2:$string3;

I can obviously explode them using : as the separator. But what if
$string1 contains the character : by itself?

I was thinking, first I am gonna put an escaping character, so I can do
something like:
$string1 = str_replace(:, \:, $string1);

But that still won't work with explode. So, what can I use instead of
explode?
Anything simple, and fast?

This is a hypothetical situation. The real situation is that I am trying to
have a protocol for data sent by client using Flash. But the basic question
remains.

Thanks for any help.
RDB
--
-
/\  ASCII Ribbon Campaign against HTML
\ /  email and proprietary format
 X   attachments.
/ \
-
Have you been used by Microsoft today?
Choose your life. Choose freedom.
Choose LINUX.
-


--
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] explode and escape character for string separator

2003-07-18 Thread CPT John W. Holmes
From: Reuben D. Budiardja [EMAIL PROTECTED]

 This is a hypothetical situation. The real situation is that I am trying
to
 have a protocol for data sent by client using Flash. But the basic
question
 remains.

So FLASH is creating the string that you must decode in PHP? Is there any
way to URL encode things in flash? URL encode the data, separate with 
(just like a query string), and then it'll be easy to decode on the PHP
side.

---John Holmes...


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



Re: [PHP] explode and escape character for string separator

2003-07-18 Thread Reuben D. Budiardja
On Friday 18 July 2003 03:33 pm, Chris Sherwood wrote:
 After reading your problem

 this is what I think you should do is dont let the user enter the string
 predelimited
 have them enter each individual string at which point you can safely search
 for the delimiter and replace it with the character of your choice _ is a
 favorite of mine.

 then rebuild the string and delimit it yourself

I was thinking about that too, but that doesn't really solve the inherent 
problem. What if the user also have _  in the string? How then do I know 
which _ is my doing? Because in my case, it's faily conceivable that _ 
will get used.

RDB


 Chris
 - Original Message -
 From: Reuben D. Budiardja [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Friday, July 18, 2003 11:47 AM
 Subject: [PHP] explode and escape character for string separator



 Hi all,
 Suppose I have a long string like
 $myStr = $string1:$string2:$string3;

 I can obviously explode them using : as the separator. But what if
 $string1 contains the character : by itself?

 I was thinking, first I am gonna put an escaping character, so I can do
 something like:
 $string1 = str_replace(:, \:, $string1);

 But that still won't work with explode. So, what can I use instead of
 explode?
 Anything simple, and fast?

 This is a hypothetical situation. The real situation is that I am trying to
 have a protocol for data sent by client using Flash. But the basic question
 remains.

 Thanks for any help.
 RDB

-- 
-
/\  ASCII Ribbon Campaign against HTML
\ /  email and proprietary format
 X   attachments.
/ \
-
Have you been used by Microsoft today?
Choose your life. Choose freedom.
Choose LINUX.
-


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



Re: [PHP] explode and escape character for string separator

2003-07-18 Thread Chris Shiflett
--- Reuben D. Budiardja wrote:
 I did strive for that. But whatever character I choose, the problem
 remains that we can't guarantee that it's going ot be only used as
 deliminater, since the deliminated string is an input from user. So
 the problem remains.

Well, just to point out, your delimiter can be anything, including:

)[EMAIL PROTECTED]*(donotusethisstringofcharactersinanything(*[EMAIL PROTECTED])

Of course, at some point, that method of playing with probability becomes
unrealistic, and it is imperfect.

John's suggestion of URL encoding is likely your best bet. Given your string:

$foo:$bar:$blah

Make that instead:

urlencode($foo) . '' . urlencode($bar) . '' . urlencode($blah)

Then you can use  as your delimiter and be guaranteed that it does not exist
within each string. It is also easy to recover the original strings, and since
you are using PHP functions, there is less code to write (always a big plus).

Hope that helps.

Chris

=
Become a better Web developer with the HTTP Developer's Handbook
http://httphandbook.org/

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



Re: [PHP] explode and escape character for string separator

2003-07-18 Thread Reuben D. Budiardja
On Friday 18 July 2003 03:43 pm, CPT John W. Holmes wrote:
 From: Reuben D. Budiardja [EMAIL PROTECTED]

  This is a hypothetical situation. The real situation is that I am trying

 to

  have a protocol for data sent by client using Flash. But the basic

 question

  remains.

 So FLASH is creating the string that you must decode in PHP? Is there any
 way to URL encode things in flash? URL encode the data, separate with 
 (just like a query string), and then it'll be easy to decode on the PHP
 side.

Flash has its own built in method for sending/uploading data to a URL, using 
the GET or POST protocol, so that's taken care of.

What I am trying to do is to send a structured data set and create my own 
protocol for doing so. For example, when the Flash send this string

col1:[EMAIL PROTECTED]:col4

My PHP code will interpret it as a table, and construct a correspoding HTML 
table
--|--
col1  | col2
--|--
col3 | col 4

etc. We will try to send structured data of graph, multiple choice options and 
answer, etc using this method as well. That's why we have this problem.

RDB

-- 
-
/\  ASCII Ribbon Campaign against HTML
\ /  email and proprietary format
 X   attachments.
/ \
-
Have you been used by Microsoft today?
Choose your life. Choose freedom.
Choose LINUX.
-


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



Re: [PHP] explode and escape character for string separator

2003-07-18 Thread Grant Rutherford
Chris Shiflett wrote:

--- Reuben D. Budiardja wrote:
 

I did strive for that. But whatever character I choose, the problem
remains that we can't guarantee that it's going ot be only used as
deliminater, since the deliminated string is an input from user. So
the problem remains.
   

Well, just to point out, your delimiter can be anything, including:

)[EMAIL PROTECTED]*(donotusethisstringofcharactersinanything(*[EMAIL PROTECTED])

Of course, at some point, that method of playing with probability becomes
unrealistic, and it is imperfect.
John's suggestion of URL encoding is likely your best bet. Given your string:

$foo:$bar:$blah

Make that instead:

urlencode($foo) . '' . urlencode($bar) . '' . urlencode($blah)

Then you can use  as your delimiter and be guaranteed that it does not exist
within each string. It is also easy to recover the original strings, and since
you are using PHP functions, there is less code to write (always a big plus).
Hope that helps.

Chris

=
Become a better Web developer with the HTTP Developer's Handbook
http://httphandbook.org/
 

I like the way you encode things like $ in php.

$ = delimiter
/$ = $
//$ = /delimiter
///$ = /$
$ = //delimiter
/$ = //$
etc.
 = //
/$/$ = $$
etc.
To encode the input, just change every / to a // and every $ to a /$.  
Decoding is the opposite.  I don't think that there are any weird 
situations that can screw this up.  You can use the same escape 
character / for any special character, ie /@ or /: if necessary.

Grant





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


Re: [PHP] explode and escape character for string separator

2003-07-18 Thread Cesar Cordovez
Among other things, this is why XML exists.  Use XML.  FLASH can handle 
it, PHP can handle it, everything out there can handle it.  Use XML. 
Delimiters will sooner or later break down.  Use XML.

Over and out.



Grant Rutherford wrote:
Chris Shiflett wrote:

--- Reuben D. Budiardja wrote:
 

I did strive for that. But whatever character I choose, the problem
remains that we can't guarantee that it's going ot be only used as
deliminater, since the deliminated string is an input from user. So
the problem remains.
  


Well, just to point out, your delimiter can be anything, including:

)[EMAIL PROTECTED]*(donotusethisstringofcharactersinanything(*[EMAIL PROTECTED])

Of course, at some point, that method of playing with probability becomes
unrealistic, and it is imperfect.
John's suggestion of URL encoding is likely your best bet. Given your 
string:

$foo:$bar:$blah

Make that instead:

urlencode($foo) . '' . urlencode($bar) . '' . urlencode($blah)

Then you can use  as your delimiter and be guaranteed that it does 
not exist
within each string. It is also easy to recover the original strings, 
and since
you are using PHP functions, there is less code to write (always a big 
plus).

Hope that helps.

Chris

=
Become a better Web developer with the HTTP Developer's Handbook
http://httphandbook.org/
 

I like the way you encode things like $ in php.

$ = delimiter
/$ = $
//$ = /delimiter
///$ = /$
$ = //delimiter
/$ = //$
etc.
 = //
/$/$ = $$
etc.
To encode the input, just change every / to a // and every $ to a /$.  
Decoding is the opposite.  I don't think that there are any weird 
situations that can screw this up.  You can use the same escape 
character / for any special character, ie /@ or /: if necessary.

Grant









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


Re: [PHP] explode and escape character for string separator

2003-07-18 Thread Curt Zirzow
Reuben D. Budiardja [EMAIL PROTECTED] wrote:
 Anything simple, and fast?

xml is simple, and fast to implement.



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



RE: [PHP] explode, split, or what?

2003-06-19 Thread Sævar Öfjörð


why don't you just do this?

***
?php
if(file_exists(setup.txt)){
  $lines=file(setup.txt);
  echo stripslashes($lines[0]);
}
else echo Error opening \setup.txt\;
?
***

file() returns the file in an array, each line as new value, so line nr.
1 is $line[0], line nr. 2 is $line[1] etc...
I added stripslashes() on the output so that you won't get John\'s X
Log


Sævar - ICELAND


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



Re: [PHP] explode, split, or what?

2003-06-19 Thread Steve Keller
At 6/19/2003 10:41 PM, Kyle Babich wrote:

 Inside of another file I'm trying to read setup.txt into $rawSetupData 
and explode that with \r\n's
 into an array called $setupData.

Why on earth?

http://us4.php.net/file

 ?php

 if (file_exists(setup.txt)) {
$rawSetupData = readfile(setup.txt);
$setupData = explode(\r\n, $rawSetupData);
echo $setupData[0];
 }
 else echo Error opening \setup.txt\;

 ?
No no nonono

?
if ($file_exists(setup.txt)) {
$setupData = file(setup.txt);
}
else {
echo 'Error opening setup.txt';
}
?
--
S. Keller
UI Engineer
The Health TV Channel, Inc.
(a non - profit organization)
3820 Lake Otis Pkwy.
Anchorage, AK 99508
907.770.6200 ext.220
907.336.6205 (fax)
Email: [EMAIL PROTECTED]
Web: www.healthtvchannel.org
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] explode( , $pizza)

2003-02-25 Thread Sascha Braun
Hi,

i found something like:

var s = This,is,a,String;
lenght = s.lenght;
document.write(s.bold());
t = s.substring(2,4);
a = s.split(,); // This line is the most interesting one ;))

document.write(a[1]); // should write the word 'is'

Dont know if it works, i just looked in one of my old books.

The Book where i found the answer is from O'Reilly: Javascript
the defenetive reference or some like that, another very very good
book is Dynamic HTML from O'Reilly, you should find all infor-
mation you need there.

Good luck!

Sascha

- Original Message - 
From: John Taylor-Johnston [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Tuesday, February 25, 2003 7:21 AM
Subject: [PHP] explode( , $pizza)


 Off topic :) ?
 Anyone know how to explode using javascript?
 
 $pieces = explode( , $pizza);
 
 John
 
 
 -- 
 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] explode( , $pizza)

2003-02-25 Thread Tim
The following example illustrates the use of the split method.

function SplitDemo(){
   var s, ss;
   var s = The rain in Spain falls mainly in the plain.;
   // Split at each space character.
   ss = s.split( );
   return(ss);
}

HTH
t.


 -Message d'origine-
 De : John Taylor-Johnston [mailto:[EMAIL PROTECTED]
 Envoye : mardi 25 fevrier 2003 07:22
 A : [EMAIL PROTECTED]
 Objet : [PHP] explode( , $pizza)
 
 
 Off topic :) ?
 Anyone know how to explode using javascript?
 
 $pieces = explode( , $pizza);
 
 John
 
 
 -- 
 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] explode didn't work well

2002-10-31 Thread Rasmus Lerdorf
Because you can't spell pizza, I bet.

On Thu, 31 Oct 2002, ppf wrote:


 Hi all:
 I had tried to split the string into an array of
 string using explode but the result isn't displaying
 anything
 I tried the example from document its its not showing
 anything, pls point out where i went wrong
 **
 $pizaa=piece1 piece2 piece3 piece4 piece5 piece6;
 $pieces = explode(' ', $pizza);
 echo $pizaa;
 echo ($pieces [2]);
 
  Thanks in advance
   Prad

 __
 Do you Yahoo!?
 HotJobs - Search new jobs daily now
 http://hotjobs.yahoo.com/

 --
 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] explode didn't work well

2002-10-31 Thread Keith Vance
echo ($pieces[2]);
instead of
echo ($pieces [2]);



Keith Vance
Vance Consulting LLC
www.vanceconsulting.net
(206) 355-2399

Try U.M.A. at http://uma.sourceforge.net/


On Thu, 31 Oct 2002, ppf wrote:


 Hi all:
 I had tried to split the string into an array of
 string using explode but the result isn't displaying
 anything
 I tried the example from document its its not showing
 anything, pls point out where i went wrong
 **
 $pizaa=piece1 piece2 piece3 piece4 piece5 piece6;
 $pieces = explode(' ', $pizza);
 echo $pizaa;
 echo ($pieces [2]);
 
  Thanks in advance
   Prad

 __
 Do you Yahoo!?
 HotJobs - Search new jobs daily now
 http://hotjobs.yahoo.com/

 --
 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] explode didn't work well

2002-10-31 Thread Keith Vance
And that too.

Keith Vance
Vance Consulting LLC
www.vanceconsulting.net
(206) 355-2399

Try U.M.A. at http://uma.sourceforge.net/


On Thu, 31 Oct 2002, Rasmus Lerdorf wrote:

 Because you can't spell pizza, I bet.

 On Thu, 31 Oct 2002, ppf wrote:

 
  Hi all:
  I had tried to split the string into an array of
  string using explode but the result isn't displaying
  anything
  I tried the example from document its its not showing
  anything, pls point out where i went wrong
  **
  $pizaa=piece1 piece2 piece3 piece4 piece5 piece6;
  $pieces = explode(' ', $pizza);
  echo $pizaa;
  echo ($pieces [2]);
  
   Thanks in advance
Prad
 
  __
  Do you Yahoo!?
  HotJobs - Search new jobs daily now
  http://hotjobs.yahoo.com/
 
  --
  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] Explode and Trim

2002-04-05 Thread Joshua E Minnie

Unfortunately it doesn't.  That is why I am kind of puzzled by the
situation.


--
Joshua E Minnie
CIO
[EMAIL PROTECTED]

Don't work for recognition, but always do work worthy of recognition.

Maxim Maletsky [EMAIL PROTECTED] wrote

 I think what yo wrote should be working fine for you.

 My way of your code:




 foreach(file($storelist) as $line_num=$line_data) {
 foreach(explode(':', $line) as $key=$val) {
 $val = trim($val); // remove whitespaces around

 // now you are inside each element of your
 multidimentional array
 // combine your rest of the code and work it out the way
 you need it.

 }
 }



 Sincerely,

 Maxim Maletsky
 Founder, Chief Developer

 PHPBeginner.com (Where PHP Begins)
 [EMAIL PROTECTED]
 www.phpbeginner.com


  -Original Message-
  From: Joshua E Minnie [mailto:[EMAIL PROTECTED]]
  Sent: Friday, April 05, 2002 1:07 AM
  To: [EMAIL PROTECTED]
  Subject: [PHP] Explode and Trim
 
  I am parsing through a text file and using explode to convert the
 string to
  an array.  The problem seems to be at the end of the string, when I
 check to
  see if the last element in the array is empty it tells me that it is
 not.
  The problem comes because the last element should be empty because all
 that
  was after the separator was white space.
 
  ---Sample text file---
  AL:123 2nd Ave.:SomeCity:(123) 456-7890:(123) 456-1234:::
  MI:293 3rd St.:Another City:(123) 345-2839:(123) 384-0398:::
  MI:437 4th Ave.:Yet Another City:(123) 283-4839:(123) 458-4843:::
  ---End of text file---
 
  ---Code snippit---
  $stores = file($storelist);
  for($i=0; $icount($stores); $i++) {
//$stores[$i] = trim($stores[$i],\r);
//$stores[$i] = trim($stores[$i],\n);
//$stores[$i] = trim($stores[$i], :);
//$stores[$i] = rtrim($stores[$i]);
echo $stores[$i].brbr\n;
$stores[$i] = explode(:, $stores[$i]);
  }
 
  reset($states);
  while(current($states)  current($stores)) {
for($i=0; $icount($stores); $i++, next($stores)) {
  while($stores[$i][0] != key($states)) {
next($states);
$state = 0;
  }
  if($state==0) {
echo b.$states[$stores[$i][0]]./bbr\n;
$state = 1;
  }
  echo $stores[$i][1]., .$stores[$i][2].brPhone:
  .$stores[$i][3].brFax: .$stores[$i][4].br\n;
  if(!empty($stores[$i][5])) echo Email: .$stores[$i][5].br\n;
  if(!empty($stores[$i][6])) echo Web site:
 .$stores[$i][6].br\n;
  if(!empty($stores[$i][7])  $stores[$i][7] != ) echo
 Additional
  notes: .$stores[$i][7].br\n;
  echo br;
}
  }
  ---End of code snippit---
 
  Here is the URL of where the code is being used:
  www.wildwebtech.com/acs/nuven/stores.php.  The additional notes should
 only
  show up if there were additional notes.
 
  --
  Joshua E Minnie
  CIO
  [EMAIL PROTECTED]
 
  Don't work for recognition, but always do work worthy of
 recognition.
 
 
 
  --
  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] Explode and Trim

2002-04-05 Thread Joshua E Minnie

It works great using the foreach statements, but for some reason couldn't
make it work the other way.  Oh well, no one ever said there was only one
way to do things when programming.  Thanks for your help.

---
Joshua E Minnie
CIO
[EMAIL PROTECTED]

Don't work for recognition, but always do work worthy of recognition.

Maxim Maletsky [EMAIL PROTECTED] wrote:
 I think what yo wrote should be working fine for you.

 My way of your code:




 foreach(file($storelist) as $line_num=$line_data) {
 foreach(explode(':', $line) as $key=$val) {
 $val = trim($val); // remove whitespaces around

 // now you are inside each element of your
 multidimentional array
 // combine your rest of the code and work it out the way
 you need it.

 }
 }



 Sincerely,

 Maxim Maletsky
 Founder, Chief Developer

 PHPBeginner.com (Where PHP Begins)
 [EMAIL PROTECTED]
 www.phpbeginner.com


  -Original Message-
  From: Joshua E Minnie [mailto:[EMAIL PROTECTED]]
  Sent: Friday, April 05, 2002 1:07 AM
  To: [EMAIL PROTECTED]
  Subject: [PHP] Explode and Trim
 
  I am parsing through a text file and using explode to convert the
 string to
  an array.  The problem seems to be at the end of the string, when I
 check to
  see if the last element in the array is empty it tells me that it is
 not.
  The problem comes because the last element should be empty because all
 that
  was after the separator was white space.
 
  ---Sample text file---
  AL:123 2nd Ave.:SomeCity:(123) 456-7890:(123) 456-1234:::
  MI:293 3rd St.:Another City:(123) 345-2839:(123) 384-0398:::
  MI:437 4th Ave.:Yet Another City:(123) 283-4839:(123) 458-4843:::
  ---End of text file---
 
  ---Code snippit---
  $stores = file($storelist);
  for($i=0; $icount($stores); $i++) {
//$stores[$i] = trim($stores[$i],\r);
//$stores[$i] = trim($stores[$i],\n);
//$stores[$i] = trim($stores[$i], :);
//$stores[$i] = rtrim($stores[$i]);
echo $stores[$i].brbr\n;
$stores[$i] = explode(:, $stores[$i]);
  }
 
  reset($states);
  while(current($states)  current($stores)) {
for($i=0; $icount($stores); $i++, next($stores)) {
  while($stores[$i][0] != key($states)) {
next($states);
$state = 0;
  }
  if($state==0) {
echo b.$states[$stores[$i][0]]./bbr\n;
$state = 1;
  }
  echo $stores[$i][1]., .$stores[$i][2].brPhone:
  .$stores[$i][3].brFax: .$stores[$i][4].br\n;
  if(!empty($stores[$i][5])) echo Email: .$stores[$i][5].br\n;
  if(!empty($stores[$i][6])) echo Web site:
 .$stores[$i][6].br\n;
  if(!empty($stores[$i][7])  $stores[$i][7] != ) echo
 Additional
  notes: .$stores[$i][7].br\n;
  echo br;
}
  }
  ---End of code snippit---
 
  Here is the URL of where the code is being used:
  www.wildwebtech.com/acs/nuven/stores.php.  The additional notes should
 only
  show up if there were additional notes.
 
  --
  Joshua E Minnie
  CIO
  [EMAIL PROTECTED]
 
  Don't work for recognition, but always do work worthy of
 recognition.
 
 
 
  --
  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] Explode and Trim

2002-04-04 Thread Maxim Maletsky


I think what yo wrote should be working fine for you.

My way of your code:




foreach(file($storelist) as $line_num=$line_data) {
foreach(explode(':', $line) as $key=$val) {
$val = trim($val);  // remove whitespaces around

// now you are inside each element of your
multidimentional array
// combine your rest of the code and work it out the way
you need it.

}
}



Sincerely,

Maxim Maletsky
Founder, Chief Developer

PHPBeginner.com (Where PHP Begins)
[EMAIL PROTECTED]
www.phpbeginner.com


 -Original Message-
 From: Joshua E Minnie [mailto:[EMAIL PROTECTED]]
 Sent: Friday, April 05, 2002 1:07 AM
 To: [EMAIL PROTECTED]
 Subject: [PHP] Explode and Trim
 
 I am parsing through a text file and using explode to convert the
string to
 an array.  The problem seems to be at the end of the string, when I
check to
 see if the last element in the array is empty it tells me that it is
not.
 The problem comes because the last element should be empty because all
that
 was after the separator was white space.
 
 ---Sample text file---
 AL:123 2nd Ave.:SomeCity:(123) 456-7890:(123) 456-1234:::
 MI:293 3rd St.:Another City:(123) 345-2839:(123) 384-0398:::
 MI:437 4th Ave.:Yet Another City:(123) 283-4839:(123) 458-4843:::
 ---End of text file---
 
 ---Code snippit---
 $stores = file($storelist);
 for($i=0; $icount($stores); $i++) {
   //$stores[$i] = trim($stores[$i],\r);
   //$stores[$i] = trim($stores[$i],\n);
   //$stores[$i] = trim($stores[$i], :);
   //$stores[$i] = rtrim($stores[$i]);
   echo $stores[$i].brbr\n;
   $stores[$i] = explode(:, $stores[$i]);
 }
 
 reset($states);
 while(current($states)  current($stores)) {
   for($i=0; $icount($stores); $i++, next($stores)) {
 while($stores[$i][0] != key($states)) {
   next($states);
   $state = 0;
 }
 if($state==0) {
   echo b.$states[$stores[$i][0]]./bbr\n;
   $state = 1;
 }
 echo $stores[$i][1]., .$stores[$i][2].brPhone:
 .$stores[$i][3].brFax: .$stores[$i][4].br\n;
 if(!empty($stores[$i][5])) echo Email: .$stores[$i][5].br\n;
 if(!empty($stores[$i][6])) echo Web site:
.$stores[$i][6].br\n;
 if(!empty($stores[$i][7])  $stores[$i][7] != ) echo
Additional
 notes: .$stores[$i][7].br\n;
 echo br;
   }
 }
 ---End of code snippit---
 
 Here is the URL of where the code is being used:
 www.wildwebtech.com/acs/nuven/stores.php.  The additional notes should
only
 show up if there were additional notes.
 
 --
 Joshua E Minnie
 CIO
 [EMAIL PROTECTED]
 
 Don't work for recognition, but always do work worthy of
recognition.
 
 
 
 --
 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] explode() - quick question

2002-03-13 Thread Analysis Solutions

On Wed, Mar 13, 2002 at 10:06:01PM -0500, Phil Schwarzmann wrote:
 
 $array[0] = 'h'
 $array[1] = 'e'
 
 $character = explode('', $string) or

You need to explode the array:

  $character = explode('', $array);

--Dan

-- 
PHP scripts that make your job easier
  http://www.analysisandsolutions.com/code/
 SQL Solution  |  Layout Solution  |  Form Solution
 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

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




RE: [PHP] explode() - quick question

2002-03-13 Thread Martin Towell

just use $string{0} and $string{1} , etc.
note the type of brackets

-Original Message-
From: Phil Schwarzmann [mailto:[EMAIL PROTECTED]]
Sent: Thursday, March 14, 2002 2:06 PM
To: [EMAIL PROTECTED]
Subject: [PHP] explode() - quick question


Im trying to take this string, hello, and explode it into an array
with each cell in the array containing one character.

$array[0] = 'h'
$array[1] = 'e'
etc..

How does this work?  When is use...

$character = explode('', $string) or
$character = explode($string)

...it doesn't seem to work.  ANY HELP!?!?  THANKS!!

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




RE: [PHP] explode? (table field to a variable of same name)

2002-02-19 Thread Rick Emery

This isn't exactly what you want, but it is close:

list($user_id,$field2,$field3,$field4) = $row;

where $row was retrieved via mysql_fetch_array()
Just list each of the variable names in the list() function; include ALL
fields' names included in $row
-Original Message-
From: Baloo :0) [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, February 19, 2002 3:41 PM
To: [EMAIL PROTECTED]
Subject: [PHP] explode? (table field to a variable of same name)


How can I assign automatically all fields of a database to a variable of
the same name?

Instead of having to manually do
$user_id=$row[user_id];
etc

Then how could I know the number of fields in the table so I can do a
loop to print them all in html?

In advance, thanks for your help.

Alfredo


-- 
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] explode? (table field to a variable of same name)

2002-02-19 Thread Simon Willison

First grab an associative array of the variables from the database with 
mysql_fetch_array()

Then use extract($array); to extract all of the variables in the array 
to the symbol table:

www.php.net/extract

Simon

Baloo :0) wrote:

How can I assign automatically all fields of a database to a variable of
the same name?

Instead of having to manually do
$user_id=$row[user_id];
etc

Then how could I know the number of fields in the table so I can do a
loop to print them all in html?

In advance, thanks for your help.

Alfredo






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




Re: [PHP] explode? (table field to a variable of same name)

2002-02-19 Thread Christopher William Wesley

This may not be what you want to do, but should give you some hints.
(This is my code which I use to simply dump any SQL table into an HTML
 table I can view in a browser ... for small tables, of course.)

Using MySQL as an example:
// assuming you ran a query and stored results in $mysql_result_set

// Get the number of fields to work with
$num_fields = mysql_num_fields( $mysql_result_set );
// http://www.php.net/manual/en/function.mysql-num-fields.php

// Print out a row of column headers
print( tr );
for( $i = 0; $i  $num_fields; $i++ ){
$fieldName = mysql_fetch_field( $mysql_result_set, $i );
// http://www.php.net/manual/en/function.mysql-fetch-field.php
print( td . $fieldName-name . /td );
}
print( /tr );

// Print out the data from the result records
while( $record = mysql_fetch_row( $mysql_result_set ) ){
// http://www.php.net/manual/en/function.mysql-fetch-row.php
print( tr );
foreach( $record as $field ){
${$field} = $field;
// The above is unnecessary, but answers your question.
// It assigns a variable, named after a table column,
//the value of that column (in this record).
print( td${field}/td );
}
print( tr );
}

Hope that gives you something to work with.

g.luck,
~Chris

On Tue, 19 Feb 2002, Baloo :0) wrote:

 How can I assign automatically all fields of a database to a variable of
 the same name?

 Instead of having to manually do
 $user_id=$row[user_id];
 etc

 Then how could I know the number of fields in the table so I can do a
 loop to print them all in html?


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




Re: [PHP] explode? (table field to a variable of same name)

2002-02-19 Thread Rasmus Lerdorf

This creates all the variables you asked for and also prints each one in a
column of a table.

foreach($row as $key=$val) {
$$key = $val;
echo td$val/td;
}

-Rasmus

On Tue, 19 Feb 2002, Baloo :0) wrote:

 How can I assign automatically all fields of a database to a variable of
 the same name?

 Instead of having to manually do
 $user_id=$row[user_id];
 etc

 Then how could I know the number of fields in the table so I can do a
 loop to print them all in html?

 In advance, thanks for your help.

 Alfredo


 --
 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] explode? (table field to a variable of same name)

2002-02-19 Thread Christopher William Wesley

oi ... typo!  see below.  sorry :(

~Chris

On Tue, 19 Feb 2002, Christopher William Wesley wrote:

 This may not be what you want to do, but should give you some hints.
 (This is my code which I use to simply dump any SQL table into an HTML
  table I can view in a browser ... for small tables, of course.)

 Using MySQL as an example:
 // assuming you ran a query and stored results in $mysql_result_set

 // Get the number of fields to work with
 $num_fields = mysql_num_fields( $mysql_result_set );
 // http://www.php.net/manual/en/function.mysql-num-fields.php

 // Print out a row of column headers
 print( tr );
 for( $i = 0; $i  $num_fields; $i++ ){
   $fieldName = mysql_fetch_field( $mysql_result_set, $i );
   // http://www.php.net/manual/en/function.mysql-fetch-field.php
   print( td . $fieldName-name . /td );
 }
 print( /tr );

 // Print out the data from the result records
 while( $record = mysql_fetch_row( $mysql_result_set ) ){
 // http://www.php.net/manual/en/function.mysql-fetch-row.php
   print( tr );

I screwed it up here ... this foreach() loop should be as follows

   foreach( $record as $fieldName=$field ){
   ${$fieldName} = $field;
   // The above is unnecessary, but answers your question.
   // It assigns a variable, named after a table column,
   //the value of that column (in this record).
   print( td${field}/td );
   }
   print( tr );
 }

Again ... sorry about that.  Oi ... and I see that someone else, wrote
that bit of code correctly to the list just now :)  (thx, Rasmus).


 Hope that gives you something to work with.

   g.luck,
 ~Chris

 On Tue, 19 Feb 2002, Baloo :0) wrote:

  How can I assign automatically all fields of a database to a variable of
  the same name?
 
  Instead of having to manually do
  $user_id=$row[user_id];
  etc
 
  Then how could I know the number of fields in the table so I can do a
  loop to print them all in html?





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




Re: [PHP] explode()

2001-07-16 Thread Zak Greant

list (,$reqmonth) = explode ('-', $row[5]);

--zak

- Original Message -
From: Adam Plocher [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Monday, July 16, 2001 5:23 PM
Subject: [PHP] explode()


 $reqmonth = ${explode(-,$row[5])}[1];

 Is there anyway I can get that to work without having to use multiple
lines
 of code?



-- 
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] explode()

2001-07-16 Thread Mark Maggelet

On Mon, 16 Jul 2001 16:23:19 -0700, Adam Plocher
([EMAIL PROTECTED]) wrote:
$reqmonth = ${explode(-,$row[5])}[1];

Is there anyway I can get that to work without having to use
multiple lines
of code?

hmm... how about
$reqmonth = array_pop(explode(-,$row[5],2));




--
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] explode()

2001-07-16 Thread Brian White

$arr = explode(-,$row[5]); $reqmonth=$arr[1];

Well, it's all on one line.


At 16:23 16/07/2001 -0700, Adam Plocher wrote:
$reqmonth = ${}[1];

Is there anyway I can get that to work without having to use multiple lines
of code?

-
Brian White
Step Two Designs Pty Ltd - SGML, XML  HTML Consultancy
Phone: +612-93197901
Web:   http://www.steptwo.com.au/
Email: [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] explode

2001-06-24 Thread Jason Murray

   How come I get this it does not make since

Makes perfect sense:

a href=whatever.php?name=what+evertest/a

Web browsers url encode form elements. If you use a href link like this,
you need to do the URL encoding yourself. A + happens to be a space, in
URL encoding.

So, PHP receives name=what+ever and sets $name = what ever.

Jason

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

2001-06-24 Thread CC Zona

In article [EMAIL PROTECTED],
 [EMAIL PROTECTED] (Richard Kurth) wrote:

$name=what+ever;
 
 $name1=explode(+,$name);
   $fname=$name1[0] ;this has what
   $lname=$name1[0] ;this has ever
 
   But if I pass the info from another page like this
 
   a href=whatever.php?name=what+evertest/a
 
 $name1=explode(+,$name);
   $fname=$name1[0] ;   this has what ever
   $lname=$name1[0] ;   this has nothing in it

It's an HTTP issue.  You only think you're passing what+ever in the 
second example; the value actually being passed is what ever. See
http://php.net/urlencode  http://php.net/rawurlencode

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

2001-06-24 Thread Zak Greant

Richard Kurth wrote:
 
 Question about explode
 
 this work just perfect
$name=what+ever;
 
 $name1=explode(+,$name);
   $fname=$name1[0] ;this has what
   $lname=$name1[0] ;this has ever
 
   But if I pass the info from another page like this
 
   a href=whatever.php?name=what+evertest/a
 
 $name1=explode(+,$name);
   $fname=$name1[0] ;   this has what ever
   $lname=$name1[0] ;   this has nothing in it
 
   $fname has both names in it
 
   How come I get this it does not make since

Try echo()'ing $name on the page you passed it to.
Notice anything different? :)

Before you pass values around with a query string, you
should prepare them first by processing them with 
rawurlencode().

--zak


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

2001-06-24 Thread nicole


if you need to pass special characters (eg. +) in the url, you need to
use a url encoding function like rawurlencode().. or choose another
delimeter which can be passed in the url like these -_.

s

Richard Kurth wrote:
 
 Question about explode
 
 this work just perfect
$name=what+ever;
 
 $name1=explode(+,$name);
   $fname=$name1[0] ;this has what
   $lname=$name1[0] ;this has ever
 
   But if I pass the info from another page like this
 
   a href=whatever.php?name=what+evertest/a
 
 $name1=explode(+,$name);
   $fname=$name1[0] ;   this has what ever
   $lname=$name1[0] ;   this has nothing in it
 
   $fname has both names in it
 
   How come I get this it does not make since
 
 Best regards,
  Richard
 mailto:[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]




Re: [PHP] explode won't explode

2001-04-27 Thread jdwright



Hiya,

 I have the following code that doesn't seem to explode. I'm trying to make
 a field that looks like 21,23,25,27 or small,medium,large,x-large into a
 pulldown menu with the individual item broken out.

 if (($size != )  ($size != n/a)) {
$sizearry = explode(,, $size);
while (list($key,$value) = each($sizearry)) {
$size_option_block .= option value=\$value\$size/option\n;
 }

I think you've used the wrong varaible between option/option. You should
have $value, but you've put in the original variable: $size.

 The interesting thing (and probably the problem) is that I have very similar
 code just before it that works fine. Here's the code that appears just
 before and works.

 if (($color != )  ($color != n/a)) {
$colorarry = explode(,, $color);
while (list($key,$value) = each($colorarry)) {
$color_option_block .= option value=\$value\$value/option\n;
 }

 I'm not that familiar with explode. Are my $key and $value variables
 conflicting?


 .
 Tom Beidler
 Orbit Tech Services
 805.682.8972 (phone)
 805.682.5833 (fax)
 [EMAIL PROTECTED]
 http://www.orbittechservices.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] explode won't explode

2001-04-27 Thread Christian Reiniger

On Friday 27 April 2001 14:15, Tom Beidler wrote:
 I have the following code that doesn't seem to explode. I'm trying to
 make a field that looks like 21,23,25,27 or small,medium,large,x-large
 into a pulldown menu with the individual item broken out.

 if (($size != )  ($size != n/a)) {
$sizearry = explode(,, $size);
while (list($key,$value) = each($sizearry)) {
$size_option_block .= option value=\$value\$size/option\n;

Why are yo using $size (the unexploded string) in the last line?

-- 
Christian Reiniger
LGDC Webmaster (http://sunsite.dk/lgdc/)

Error 032: Recursion error - see error 032

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

2001-03-07 Thread Jason Murray

Rol wrote:
 
 Hello all,
 
 I would like to check some names ( @ seperated strings) with this global 
$PHP_AUTH_USER
 
 I first do
 $arrLoginName = explode("@", $row-usr_loginName);
 
 How can I construct a loop which stops and returns true if a match is found?
 
 Any hints would be great.
 
 Many thanks
 
 Roland

This will do it:

$dim = sizeof($arrLoginName);
for ($nr = 0; $nr  $dim; $nr++) {
if (match) {
return 1;
}
}

Greetings,
Jason
-- 
Jason Murray
Developer
http://www.jwebmedia.com/
1 877 525 jWEB

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

2001-03-07 Thread Chris Lee

?php

 function check()
 {
  $arrLoginName = explode("@", $row-usr_loginName);
  foreach($arrLoginName as $pos = $val)
   if (match)
return 1;
  return ;
 }
 
?

is this what you mean? please post regarding.
-- 

 Chris Lee
 Mediawaveonline.com

 ph. 250.377.1095
 ph. 250.376.2690
 fx. 250.554.1120

 [EMAIL PROTECTED]


""Rol"" [EMAIL PROTECTED] wrote in message 
002301c0a726$615218e0$[EMAIL PROTECTED]">news:002301c0a726$615218e0$[EMAIL PROTECTED]...
Hello all,

I would like to check some names ( @ seperated strings) with this global 
$PHP_AUTH_USER

I first do
$arrLoginName = explode("@", $row-usr_loginName);

How can I construct a loop which stops and returns true if a match is found?


Any hints would be great.

Many thanks

Roland





Re: [PHP] Explode a variable into each character

2001-02-23 Thread Rasmus Lerdorf

 I have a string of 1034 and I want to have an array that has each number in
 an element.(ex: num[0] = 1, num[1] = 0, num[2] = 3 num[3] = 4) Is there a
 way to explode a string by each character?


Just convert it to a string:  ie. $foo = (string)$num; echo $foo[1];

-Rasmus


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