I've got some hyphenated zip codes as values in an array and I need to dump the hyphen (and everything after the hyphen). Is trim() the best function for this?
| SitePoint Sponsor |

I've got some hyphenated zip codes as values in an array and I need to dump the hyphen (and everything after the hyphen). Is trim() the best function for this?
Probably not the most efficient, but seems to do the job:
PHP Code:<?php
$a = array('1234-456', '9874-412');
function strip_hyphen($s){
$bits = explode('-', $s);
return $bits[0];
}
$new = array_map('strip_hyphen', $a);
print_r($new);
?>




$new_zip = substr( $old_zip, 0, 5 );
Bookmarks