Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: Separate words

  1. #1
    Regular Coder sitNsmile's Avatar
    Join Date
    Dec 2009
    Location
    Charlotte, NC
    Posts
    358
    Thanks
    19
    Thanked 2 Times in 2 Posts

    Separate words

    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.)

    Thanks

  • #2
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Code:
    $string = 'some words';
    $string = implode(' Games |', explode(' ', $string)).' Games';

  • Users who have thanked MattF for this post:

    sitNsmile (03-19-2010)

  • #3
    Regular Coder sitNsmile's Avatar
    Join Date
    Dec 2009
    Location
    Charlotte, NC
    Posts
    358
    Thanks
    19
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by MattF View Post
    Code:
    $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>

    Code:
    <a h=www.rally.com>Rally Games</a> | <a h=www.point.com>Point Games</a>
    Thanks
    Last edited by sitNsmile; 03-19-2010 at 05:08 PM.

  • #4
    Regular Coder sitNsmile's Avatar
    Join Date
    Dec 2009
    Location
    Charlotte, NC
    Posts
    358
    Thanks
    19
    Thanked 2 Times in 2 Posts
    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?


    Thanks

  • #5
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Code:
    $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:

    Code:
    $links[] = '<a href="http://'.strtolower($word).'.com">'.$word.' Games</a>';
    Last edited by MattF; 03-19-2010 at 05:49 PM.

  • Users who have thanked MattF for this post:

    sitNsmile (03-19-2010)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •