Jump to content

Add Slashes


iceblox

Recommended Posts

Hi All,

 

I have a script which uploads a CSV feed, the issue is that the feed text contains commas. I have been told the best way to do this is to add slashes?

 

How would i add this to my script. This is line i believe it needs to be added too.

 

$cols = explode(',', trim($line));

 

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/119015-add-slashes/
Share on other sites

Either use a delimiter other than comma in the CSV

[pre]

1|field2|text,with comma|more text

[/pre]

 

or enclose text items in ".."

 

[pre]

1,"field2","text,with comma","more text"

[/pre]

 

EDIT: Nearly forgot, use fgetcsv() to read the data, not explode, then you can specify the delimiter and quotes

Link to comment
https://forums.phpfreaks.com/topic/119015-add-slashes/#findComment-612843
Share on other sites

Thanks for that Barrand,

 

All sorted ;0)

 

One more for you if you dont mind..

 

The script i have replaces data in the feed for a a number which is defind within the feed. I was told that if there was a string i wanted to replace i could do this for example..

 

 

If I have "http://www.url.com/id=xxxx"

 

and i want to replace "xxxx" for "4444" i was told to do this "xxxx|1" => "4444"

 

But this isnt working. Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/119015-add-slashes/#findComment-612846
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.