[PHP] breaking the string

2004-05-14 Thread gowthaman ramasamy
hello list,
can we split a string into substrings of particular size.
for example ..
i have as sting of 1000 characters. can i split it into stings of 150
and feed them into an array.

sorry i am bothering you guys again and again today
sincerely
gowtham
-- 
Ra. Gowthaman,
Graduate Student,
Bioinformatics Lab,
Malaria Research Group,
ICGEB , New Delhi.
INDIA

Phone: 91-9811261804
   91-11-26173184; 91-11-26189360 #extn 314

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



[PHP] breaking a string into chunks

2003-09-19 Thread David T-G
Hi, all --

Now it's my turn to ask a simple question, or one that sure sounds like
it should be...

I have a 14-char date string like 20030917181909 and I need to break it
into its component parts for a more readable 2003-09-17 18:19:09 view.
How can I do that?  Do I really need to call substr half a dozen times?(!?)

I tried unpack() but all I ended up getting was an array with one entry
(sometimes with a very strange-looking key).


TIA  HAND

:-D
-- 
David T-G  * There is too much animal courage in 
(play) [EMAIL PROTECTED] * society and not sufficient moral courage.
(work) [EMAIL PROTECTED]  -- Mary Baker Eddy, Science and Health
http://justpickone.org/davidtg/  Shpx gur Pbzzhavpngvbaf Qrprapl Npg!



pgp0.pgp
Description: PGP signature


Re: [PHP] breaking a string into chunks

2003-09-19 Thread Duncan Hill
On Friday 19 Sep 2003 10:20, David T-G wrote:
 Hi, all --

 Now it's my turn to ask a simple question, or one that sure sounds like
 it should be...

 I have a 14-char date string like 20030917181909 and I need to break it
 into its component parts for a more readable 2003-09-17 18:19:09 view.
 How can I do that?  Do I really need to call substr half a dozen

In perl I'd do something like:
$time =~ m/(\d){4}(\d){2}(\d){2}(\d){2}(\d){2}(\d){2}/;
$ntime = $1-$2-$3 $4:$5:$6;

I think php can do that with preg_match, using an array to hold the matches.

As the other poster said, if this is mysql, let mysql do the work for you :)

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



Re: [PHP] breaking a string into chunks

2003-09-19 Thread Marek Kilimajer
you can call preg_match, and only once

David T-G wrote:

Hi, all --

Now it's my turn to ask a simple question, or one that sure sounds like
it should be...
I have a 14-char date string like 20030917181909 and I need to break it
into its component parts for a more readable 2003-09-17 18:19:09 view.
How can I do that?  Do I really need to call substr half a dozen times?(!?)
I tried unpack() but all I ended up getting was an array with one entry
(sometimes with a very strange-looking key).
TIA  HAND

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


Re: [PHP] breaking a string into chunks

2003-09-19 Thread David T-G
Duncan, et al --

...and then Duncan Hill said...
% 
% On Friday 19 Sep 2003 10:20, David T-G wrote:
% 
%  I have a 14-char date string like 20030917181909 and I need to break it
%  into its component parts for a more readable 2003-09-17 18:19:09 view.
%  How can I do that?  Do I really need to call substr half a dozen
% 
% In perl I'd do something like:
% $time =~ m/(\d){4}(\d){2}(\d){2}(\d){2}(\d){2}(\d){2}/;
% $ntime = $1-$2-$3 $4:$5:$6;

Hmmm...  That's not a bad idea.


% 
% I think php can do that with preg_match, using an array to hold the matches.

Yep.


% 
% As the other poster said, if this is mysql, let mysql do the work for you :)

Well, I would, but this has already been pulled out by another call for
its own use.  I'm being clever and reusing the data I have rather than
making an extra DB query.  Gee, see how much time it's saving me? ;-)

It also happens that I don't know how to have mysql format it for me as I
would like were I to make said second query -- but that's only temporary.


Thanks  HAND

:-D
-- 
David T-G  * There is too much animal courage in 
(play) [EMAIL PROTECTED] * society and not sufficient moral courage.
(work) [EMAIL PROTECTED]  -- Mary Baker Eddy, Science and Health
http://justpickone.org/davidtg/  Shpx gur Pbzzhavpngvbaf Qrprapl Npg!



pgp0.pgp
Description: PGP signature


RE: [PHP] breaking a string into chunks

2003-09-19 Thread Javier Tacon

Make your own function, for example:

function transformDate($format,$str) {
  $d = Array();
  for($i=0;$istrlen($str);$i+=2) { $d[]=substr($str,$i,2); }
  return
date($format,mktime($d[4],$d[5],$d[6],$d[2],$d[3],$d[0]$d[1]));
}

print transformDate(Y-m-d H:i:s,20030917181909);

So, you can change to any format with the first arg. of the function.


Javier Tacon Iglesias.


-Mensaje original-
De: David T-G [mailto:[EMAIL PROTECTED]
Enviado el: viernes, 19 de septiembre de 2003 11:20
Para: PHP General list
Asunto: [PHP] breaking a string into chunks
Importancia: Baja


Hi, all --

Now it's my turn to ask a simple question, or one that sure sounds like
it should be...

I have a 14-char date string like 20030917181909 and I need to break
it
into its component parts for a more readable 2003-09-17 18:19:09 view.
How can I do that?  Do I really need to call substr half a dozen
times?(!?)

I tried unpack() but all I ended up getting was an array with one entry
(sometimes with a very strange-looking key).


TIA  HAND

:-D
-- 
David T-G  * There is too much animal courage in 
(play) [EMAIL PROTECTED] * society and not sufficient moral
courage.
(work) [EMAIL PROTECTED]  -- Mary Baker Eddy, Science and
Health
http://justpickone.org/davidtg/  Shpx gur Pbzzhavpngvbaf Qrprapl
Npg!

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



Re: [PHP] breaking a string into chunks

2003-09-19 Thread Curt Zirzow
* Thus wrote Duncan Hill ([EMAIL PROTECTED]):
 On Friday 19 Sep 2003 10:20, David T-G wrote:
  Hi, all --
 
  Now it's my turn to ask a simple question, or one that sure sounds like
  it should be...
 
  I have a 14-char date string like 20030917181909 and I need to break it
  into its component parts for a more readable 2003-09-17 18:19:09 view.
  How can I do that?  Do I really need to call substr half a dozen
 
 In perl I'd do something like:
 $time =~ m/(\d){4}(\d){2}(\d){2}(\d){2}(\d){2}(\d){2}/;
 $ntime = $1-$2-$3 $4:$5:$6;

preg_match('/(\d){4}(\d){2}(\d){2}(\d){2}(\d){2}(\d){2}/', $time, $m);

Then $m is an array where the indexes
$m[0] = the matched string
$m[1] = first ()
$m[2] = second ()
...


 
 I think php can do that with preg_match, using an array to hold the matches.
 
 As the other poster said, if this is mysql, let mysql do the work for you :)
 
I suggest this also.  Or use the mysql unixtimestamp function to
return a uts and format the output with php.


In general most of my timestamp fields, in my tables, I create as an
INT then just store the Unix timestamp in there.  Makes things
easier when trying to display things.

Curt
-- 
I used to think I was indecisive, but now I'm not so sure.

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



Re: [PHP] Breaking a string

2001-10-28 Thread David Robley

On Fri, 26 Oct 2001 22:36, Dan McCullough wrote:
 I was looking to take a string like Dan or Dan is great and return it
 like

 D
 a
 n

 or

 D
 a
 n

 i
 s

 g
 r
 e
 a
 t

 is it the str function that does that and if so does someone have an
 example?

 thanks

You can dealt with the string as if it were an array of characters.
Or you could use substr to work your way through the string.
-- 
David Robley  Techno-JoaT, Web Maintainer, Mail List Admin, etc
CENTRE FOR INJURY STUDIES  Flinders University, SOUTH AUSTRALIA  

   Useless Invention: Strap-on portable chairs.

-- 
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] Breaking a string

2001-10-28 Thread speedboy

 I was looking to take a string like Dan or Dan is great and return it
 like

 D
 a
 n...

http://www.php.net/manual/en/function.wordwrap.php


-- 
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] Breaking a string

2001-10-26 Thread Dan McCullough

I was looking to take a string like Dan or Dan is great and return it like 

D
a
n

or

D
a
n

i
s

g
r
e
a
t

is it the str function that does that and if so does someone have an example?

thanks


=
Dan McCullough
---
Theres no such thing as a problem unless the servers are on fire!
h: 603.444.9808
w: McCullough Family
w: At Work

__
Do You Yahoo!?
Make a great connection at Yahoo! Personals.
http://personals.yahoo.com

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