SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Attach strings1 to string2

    I've been trying to make a 'keyword maker'.
    It's supposed to read words in a text file, and attach all of them in different combinations.

    Here's what i have managed to do.

    PHP Code:
    <?php

    $file 
    file_get_contents('text.txt');
    $file_words explode(" "$file);
    $file_count count($file_words);

    for (
    $i=0$i $file_count$i++){ 
        echo 
    $file_words[$i] . "<br />";
    }

    ?>

    And here's the text.txt file.
    Code:
    name one two five
    It should output:

    nameone
    nametwo
    namefive
    onename
    onetwo
    onefive
    ...

    Any suggestion or direction on how i am supposed to achieve the above mentioned results would be greatly appreciated.

  2. #2
    SitePoint Zealot
    Join Date
    Aug 2009
    Posts
    122
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi, I hope code below should work for you:

    PHP Code:
    <?php
    $file 
    file_get_contents('text.txt');

    $file_words explode(" "$file);

    foreach (
    $file_words as $word)
    {
        
    print_combined($word$file_words);
    }

    function 
    print_combined($base_word$words)
    {
        foreach (
    $words as $word)
        {
            if (
    $word == $base_word) continue;
            echo 
    $base_word.$word."<br/>";
        }
    }

    ?>

  3. #3
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Works like a charm! Thank you.

  4. #4
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do not mess with search engines. You could get unsexpected results

  5. #5
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    The results are pretty predictable.

    Failure :P
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  6. #6
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Shrapnel_N5 View Post
    unsexpected


    Quote Originally Posted by Jake Arkinstall View Post
    The results are pretty predictable.

    Failure :P
    It's supposed to be predictable.


Bookmarks

Posting Permissions

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