I'm having some troubles with PostreSQL arrays and html forms. Let's say I have a text field in a webpage where users can write a comma-separated list of strings, like for example a list of names. This list is stored in a Postgres db.
When the page is requested,
1) My php code fills the textfield with SELECT name_list FROM names; and what I get is something like:
| name_list |
|____________________|
| {alice,bob,carl} |
| .... |
| |
2) Remove the first and the last char (the brackets) in order to get a printable string:
..
$arrayWithoutBrackets = substr($row['name_list'], 1,-1);
echo($arrayWithoutBrackets) ----> alice,bob,carl
..
That string is what the users can read and, eventually, modify and send back to the server using a simple html form.
But what if the user inserts a name containing blank spaces (like alice,bob,carl,john doe)? That's what happens after updating the table:
| name_list |
|_______________________________|
| {alice,bob,carl,"john doe"} |
| .... |
| |
Postgres is auto-quoting my string and when the users will reload the page they will see
alice,bob,carl,"john doe"
NOT
alice,bob,carl,john doe
Manually searching for quote characters and removing them using str_replace() is not an option since I have many of those array-based text fields in my application (hundreds of them).
Is there any way to solve this?