Jump to content

Splitting text into words


flower.jason

Recommended Posts

Aww someone posted while i was typing this... anyways this will do the samething as hitman's thing...

[code]
<?
$arr = ("This is a sentence");
$arr = explode(" ", $arr);
$c = count($arr);
$arr[$c - 1] = "<font color=\"blue\">" . $arr[$c - 1] . "</font>";
$arr = implode(".", $arr);
echo $arr;
?>
[/code]

would return [code]
This.is.a.<font color="blue">sentence</font>
[/code]
Probably a better way, but this works:

[quote]<?php

$string = "Whatever text you want here";
$explode = explode(' ', $string);
$count = count($explode) - 1;
for($i=0; i<$count; $i++)
    echo "{$explode[$i]}.";
echo "<font color=\"blue\">{$explode[$count]}</font>";

?>[/quote]

Of course, never use the <font> tag :-P

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.