I am currently learning from the book, Eric Rosebrock's "Creating interactive websites with PHP and web services" it is a great book, but I have a question.
I have a string loaded from mysql that looks like this:

 $allowedfiletypes = '".jpg", ".tif", ".gif", ".png"';

I want to turn this into an array but its not working, I'm trying something like:

$allowedfiletypes = array($allowedfiletypes);

so that if I print_r it it will output something like:
[0] => .jpg
[1] => .gif
[2] => .png
etc...
I am doing this because I want to check that a file type is allowed before it is uploaded in a script.
Thanks so much, hope this is understandable,
Todd

    This would be how I would do it. I created a function that takes a string formatted like yours and returns a nice array without any qualifiers (the quotes around the extensions) or spaces:

    // code removed

    If you have differently formatted strings, you can look at the two main functions I used, [man]explode/man and [man]trim/man to alter them accordingly.

    EDIT: Erm yeah, decided to let you learn. Woops :p. Try making the code on your own. If you can't get exactly what you're looking for, post what you tried and I'll help tweak.

      Ah! I got it, Explode is exactly what I was looking for, thanks

        Write a Reply...