I loaded a csv to array. And I want to put " to column 21 if they don't have yet. This is sample of column 21. Some are empty. It's $data[21] in my case.
21
14"
14"
14"
empty
16"
This is my code
if (!str_contains($data[21], '"')) {
$data[21] = preg_replace('/[0-9]+/',$data[21].'"',$data[21]);
}
But the result is
21"
14"
14''"''
14''"''
empty
16''"''
Only the first two and the empty ones are correct. What's wrong with this? Thanks.
EDIT.. Please read comment
After helps from everyone, I realized some of the data was actually bad. They use 2 single quotes instead of double quotes. So actually this code works, as well as suggestions from Nick. Thanks.
$data[21] .= '"'inside theif?arraystag?