View Full Version : Separate words

03-19-2010, 04:26 PM
Separate words in example, title.

Game Name = Rally Point
(i want to take that it also have the system show me)

"Rally Games | Point Games"

anyone know how to separate words in a title (that's grabbed from the database, and i'll add the word 'games' at the end of each.)


03-19-2010, 04:34 PM
$string = 'some words';
$string = implode(' Games |', explode(' ', $string)).' Games';

03-19-2010, 04:41 PM
$string = 'some words';
$string = implode(' Games |', explode(' ', $string)).' Games';

Thank you, That worked perfect.

but to add to that, is there a way of making it so that I can wrap a <a link on each one.. example

<a> Rally Games </a> | <a> Point Games</a>

<a h=www.rally.com>Rally Games</a> | <a h=www.point.com>Point Games</a>


03-19-2010, 05:20 PM
Main concept im trying to accomplish is define both words as separate. Above is a start.

"Rally = $word1" and "Point = $word2"

So that they can be sent to a different URL and I can use those words. Hope that makes sense. Ideas?


03-19-2010, 05:45 PM
$links = array();
$string = 'Rally Point';
$words = explode(' ', $string);

foreach ($words as $word)
$links[] = '<a href="[uri here]">'.$word.' Games</a>';
$string = implode(' | ', $links);

Edit: If the URI domain name is always the word, you could change the $links[] line to:

$links[] = '<a href="http://'.strtolower($word).'.com">'.$word.' Games</a>';