Page 1 of 1

String Function for taking the first & last characters?

Posted: Mon Aug 19, 2002 12:10 pm
by JPlush76
hey all, I'm getting an excel file and I have to save it as a tab deliminated text file then I do a load data infile into my database...

well that works fine but in the text file some of the descriptions have " " (quotes around them)

like instead of the product name being: jims red truck its coming out as "jims red truck"

any way to cut the first and last char off a string if it matches " ?

or is there a way in excel to stop outputting those quotes around my desc? cause they don't have them when you open the exel file, only when I output it to text. thanks all!

Posted: Mon Aug 19, 2002 2:18 pm
by volka
I don't know if you can omit the " within excel but

Code: Select all

$str = substr($file, 1, strlen($str)-2);
or

Code: Select all

$str=preg_replace("/"(.*)"/", "$1", $str);
gets rid of it.

Posted: Mon Aug 19, 2002 2:22 pm
by JPlush76
that would get rid of the quotes at the beginning and end of field but leave quotes in the middle?


alot of our stuff has like: 32" roll of film

so I wouldnt' wanna remove all quotes from the middle

thanks V

Posted: Mon Aug 19, 2002 2:22 pm
by volka
it will ;)