Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

w2ksp4.exe, WwwxxXdbf, procmail "FROM_MAILER" patch, Use of assignment to $[ is deprecated at /usr/local/sbin/apxs line 86. , wwwxxx vim, mysql closing table and opening table, 800c5000, setgid operation not permitted, pciehp: acpi_pciehprm on IBM, WWWXXX.DBF

Links

XODOX
Impressum

#1: Replace a space with a newline every 2 spaces

Posted on 2010-04-22 19:29:06 by Paul Halliday

Ex:

"This is the string and it is this long"

This is
the string
and it
is this
long

I found some long functions to achieve this but I couldn't help but
think that it could be done in a couple lines.

Possible?

Thanks.

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

Report this message

#2: Re: Replace a space with a newline every 2 spaces

Posted on 2010-04-22 19:56:48 by Andrew Ballard

On Thu, Apr 22, 2010 at 1:29 PM, Paul Halliday <paul.halliday@gmail.com> wrote:
> Ex:
>
> "This is the string and it is this long"
>
> This is
> the string
> and it
> is this
> long
>
> I found some long functions to achieve this but I couldn't help but
> think that it could be done in a couple lines.
>
> Possible?
>
> Thanks.
>

I'm not sure it's the best method, but it didn't take long to come up with this:

<?php

$string = "This is the string and it is this long";

if (preg_match_all('/(?:(?:\w+\s+){2}|(?:\w+$))/', $string, $matches)) {
var_dump($matches[0]);
}


?>

Andrew

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

Report this message

#3: Re: Replace a space with a newline every 2 spaces

Posted on 2010-04-23 03:32:51 by Lupus Michaelis

Le 22/04/2010 19:29, Paul Halliday a écrit :

> I found some long functions to achieve this but I couldn't help but
> think that it could be done in a couple lines.
>
> Possible?

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

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

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

Report this message