String Function for taking the first & last characters?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
JPlush76
Forum Regular
Posts: 819
Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:

String Function for taking the first & last characters?

Post 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!
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
JPlush76
Forum Regular
Posts: 819
Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

it will ;)
Post Reply