croakingtoad Posted May 9, 2008 Share Posted May 9, 2008 Greetings! I am querying a database and after a little magic it outputs a variable called - $HomeStyle Now, this is a migration script so I am migrating from a database that has a field length of 3000 to a database that has a field length of 250. Here's a sample value: $HomeStyle= "Adirondack-style,Cabin,Cedar shake,Conventional,Cottages,Farmhouse,Lake"; //Obviously this is less than the needed field length, but let's just pretend so we can save space! So how would I take the value of $HomeStyle, reduce it to 250 AND eliminate any characters after the last comma (including the last comma)? (So we don't have incomplete words.) Thanks for your guidance! Quote Link to comment Share on other sites More sharing options...
moselkady Posted May 9, 2008 Share Posted May 9, 2008 Try something like this but replace 60 with 250: $HomeStyle= "Adirondack-style,Cabin,Cedar shake,Conventional,Cottages,Farmhouse,Lake"; echo ereg_replace(",[^,]+$","",substr($HomeStyle,0,60)); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.