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! Link to comment https://forums.phpfreaks.com/topic/104871-using-substrstr_replace-on-a-variable/ 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)); Link to comment https://forums.phpfreaks.com/topic/104871-using-substrstr_replace-on-a-variable/#findComment-536756 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.