Jump to content

Truncate data after a specific symbol


SF23103

Recommended Posts

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

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.