"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 .= "<a href='/{$words[$i]}.html'>{$words[$i]}</a>";
    }
// 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]

Reply via email to