PHP: Handle comma separated input

A quick example of how to handle comma separated input from a POST variable in PHP. The code below will turn your POST variable into an array containing the user’s input which you can further validate or store in a database. This is useful for letting users add tags to items on your website.

, , ,

  • Rudi Ahlers

    I don’t think the code works as expected.

    This is the output from “?tags=1,2,3,,,,5”

    output from “var_dump($_REQUEST);”:
    array(1) { [“tags”]=> string(10) “1,2,3,,,,5” }

    Output from “$tagSting” function
    :0 – 11 – 22 – 36 – 5

    Output from “printArray($_REQUEST);”:
    tags => 1,2,3,,,,5

Powered by WordPress. Designed by Woo Themes