Close

Results 1 to 3 of 3

Thread: PHP Question

  1. #1
    DF VIP Member Sushi's Avatar
    Join Date
    Jun 2004
    Location
    Scotland
    Posts
    502
    Thanks
    0
    Thanked:        0
    Karma Level
    300

    Default PHP Question

    Hi, I'm trying to write a very simple piece of PHP to add into a script at the moment and my knowledge is non-existent apart from some programming at school and Uni many years ago.

    I just want to know how i would take a text string that is passed into the program as one variable and split the individual words into an array when the words are seperated by spaces.

    I'd really appreciate the help if anyone knows the answer to this.
    Lets bring back the word Rad......

    [live=Sushi%20MaC]Sushi MaC[/live]

  2. #2
    DF VIP Member inspectercoley's Avatar
    Join Date
    May 2007
    Location
    TaxiMike
    Posts
    3,733
    Thanks
    234
    Thanked:        64
    Karma Level
    408

    Default Re: PHP Question

    This will do it for 2 words...

    http://codr.us/category/PHP/Left-and-Right-Functions

    And this will do it with more than 2 words

    http://www.tanguay.info/web/codeExample.php?id=984

    And this is probably the best way to do it

    http://php.oregonstate.edu/manual/en....str-split.php

    This is a good example for splitting a date:

    Code:
    <?php
    // Delimiters may be slash, dot, or hyphen
    $date = "04/30/1973";
    list($month, $day, $year) = split('[/.-]', $date);
    echo "Month: $month; Day: $day; Year: $year<br />\n";
    ?>
    So the end result should look like this...

    Code:
    // Split a string into words on boundaries of one or more spaces
    // This also uses tabs or new-lines but just delete the \t\n parts
    $input = "Please cut   \t me \n in pieces";
    $words = split("[\n\r\t ]+", $input);
    print_r($words);
    
    // Output:
    Array
    (
        [0] => Please
        [1] => cut
        [2] => me
        [3] => in
        [4] => pieces
    )
    Just use a combination of a couple of them so it look like your own work ^^

    I gave a few links as well so you can learn the different ways you can use this sort of thing.

    Hope this helps.
    Last edited by inspectercoley; 7th December 2007 at 12:15 PM.
    [live=TaxiMike]TaxiMike[/live]

  3. #3
    DF VIP Member Sushi's Avatar
    Join Date
    Jun 2004
    Location
    Scotland
    Posts
    502
    Thanks
    0
    Thanked:        0
    Karma Level
    300

    Default Re: PHP Question

    Cheers mate. I'll give it a try. Have some K+.
    Lets bring back the word Rad......

    [live=Sushi%20MaC]Sushi MaC[/live]

Similar Threads

  1. redirect question
    By Psychoschiz in forum Web Hosting & Domain Names
    Replies: 2
    Last Post: 26th September 2002, 04:09 PM
  2. Quick Saturn question
    By doughboy in forum Old Skool Gaming & Retro
    Replies: 1
    Last Post: 16th September 2002, 02:19 AM
  3. Xbox DVD Rom question
    By nims076 in forum Microsoft Consoles
    Replies: 12
    Last Post: 1st September 2002, 04:21 PM
  4. 5210 question
    By miniboot in forum Unlocking Questions & Solutions
    Replies: 1
    Last Post: 29th August 2002, 12:36 PM
  5. Decorating Question
    By Roty in forum The Dog and Duck
    Replies: 6
    Last Post: 28th August 2002, 11:36 AM

Social Networking 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
  •