Re: [PHP] Breaking up a line and using the text?

2001-02-05 Thread Christian Reiniger

On Monday 05 February 2001 13:59, jaskirat wrote:

> $string = ereg_replace(" ","\n",$string)

simpler and faster: str_replace(), explode() and split()

> >Original line
> > Hi my name is Sam Rose
> >
> >Which can then be broken down into
> > Hi
> > My
> > Names
> > is
> > Sam Rose

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

The most exciting phrase to hear in science, the one that heralds new
discoveries, is not "Eureka", but "That's funny..."

- Isaac Asimov

--
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 up a line and using the text?

2001-02-05 Thread Steve Werby

"Sam" <[EMAIL PROTECTED]> wrote:
> I was wondering if it is possible to break up a line of text from a
> database, and split it into separate links,
> Original line
> Hi my name is Sam Rose
>
> Which can then be broken down into
> Hi
> My
> Names
> is
> Sam Rose

Sam, do you want to turn them into hyperlinks?  If your data is really that
clean explode() should do the trick, otherwise you may want to look at
split().  Here's a solution using explode().  See the PHP manual for
details.  FYI, unless you have some way planned for grouping together words
(like "Sam Rose") the PHP code will split them apart.

// $string is a string pulled from a database.
// explode() below splits $string into an array by splitting into array
elements when encounters " " in code.
// In your example, $words[0] = "Hi"; $words[1] = "My"; ...; $words[5] =
"Rose";
$words = explode( " ", $string );
// Loop through array and build string $output containing hyperlinks.
for ( $i = 0; $i < count( $words ); $i++ )
{
$output .= "{$words[$i]}";
}
// Print hyperlinks.
echo $output;

--
Steve Werby
COO
24-7 Computer Services, LLC
Tel: 804.817.2470
http://www.247computing.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] Breaking up a line and using the text?

2001-02-05 Thread jaskirat

Hi,
Read about ereg_replace() function in PHP.
some thing like 
$string = ereg_replace(" ","\n",$string)

should do the trick for you.

HTH
Jaski

At 01:00 PM 2/5/01 +, Sam wrote:
>Hi all, 
>
>I was wondering if it is possible to break up a line of text from a
>database, and split it into separate links, 
>
>eg 
>
>Original line
>   Hi my name is Sam Rose
>
>Which can then be broken down into
>   Hi
>   My
>   Names
>   is
>   Sam Rose
>
>Thanks in advance
>Sam
>
>-- 
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>To contact the list administrators, e-mail: [EMAIL PROTECTED]
> 

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




[PHP] Breaking up a line and using the text?

2001-02-05 Thread Sam

Hi all, 

I was wondering if it is possible to break up a line of text from a
database, and split it into separate links, 

eg 

Original line
Hi my name is Sam Rose

Which can then be broken down into
Hi
My
Names
is
Sam Rose

Thanks in advance
Sam

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