开发者

How can I replace apostrophes while uploading a csv file?

I'm having trouble replacing apostroph开发者_如何学Pythones while uploading a csv file with a bunch of different descriptions.

Right now I have

$remarks = str_replace("'", "’", $data[28]); 

This gives me an error starting with the first apostrophe that shows up in my file. That first phrase where the apostrophe appears ends in "'s". If I change it to

$remarks = str_replace("'s", "’", $data[28]); 

it will go past that first problem and get to the next problem ('t).

What am I doing wrong? I'm new to php, and I'm sure this must be a simple solution...


array_map($data, function($a) { return(str_replace($a, "'", "’")) });

should walk all elements of the array and replace all quotes for you.


It looks like you're trying to re-invent the wheel. It looks like you're trying to parse the csv yourself. If you are stop it. You should be using str_getcsv and you won't have to worry about escaping anything.

After that, you'll probably want to look into preg_replace.

preg_replace( "#'\w?#g", '', $data[$index] );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜