SF23103 Posted February 16, 2015 Share Posted February 16, 2015 I have some data that I am displaying: var formatted_marker_data = "<div class=\"map_header\">" + data.formatted_address + "</div> The data.formatted_address is some MySQL data which is formatted like this: 123 Main Street, San Francisco, CA A few of the entries have the lat/lon added to the address: 123 Main Street, San Francisco, CA | 37.7917618,-122.3943405 I do not want to display anything after the | Is there a way to truncate all data after the | ? The only problem I see with that is that it WILL show the |, however I suppose since they are all CA addresses, I could truncate everything after the CA. Then again, if there is an address with a CA in it, then I'm screwed. Any ideas? Link to comment https://forums.phpfreaks.com/topic/294650-truncate-data-after-a-specific-symbol/ Share on other sites More sharing options...
CroNiX Posted February 16, 2015 Share Posted February 16, 2015 Sure, just split the string on "|", and grab the first part of the new array data.formatted_address = data.formatted_address.split('|')[0]; var formatted_marker_data = "<div class=\"map_header\">" + data.formatted_address + "</div> Link to comment https://forums.phpfreaks.com/topic/294650-truncate-data-after-a-specific-symbol/#findComment-1505824 Share on other sites More sharing options...
SF23103 Posted February 16, 2015 Author Share Posted February 16, 2015 Just what I needed. Thanks! Link to comment https://forums.phpfreaks.com/topic/294650-truncate-data-after-a-specific-symbol/#findComment-1505847 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.