Forum Moderators: coopster
<div>1. Turn <b>Left</b> at <b>E Main St/State Route 1033</b></div>
<div>2. Turn <b>Right</b> at <b>State Route 670/Elm St</b></div>
<div>3. Take the 1st <b>Left</b> onto <b>Jefferson Ave</b></div>
<div>4. Turn <b>Right</b> onto <b>US-81</b></div>...
// example
$line = "<div>1. Turn <b>Left</b> at <b>State Route 1033/E Main St</b></div>";
// if you have each line isolated you could use a regular expression to isolate the last bold section
preg_match_all("/<b>([^<]+)<\/b>/",$line,$matches);
$lastval = count($matches[1]) - 1;
$street_data = $matches[1][$lastval];
// If you want to remove the extra part with numbers, if it exists, you could do this:
if ( strstr($street_data,"/") ) {
// split the parts
$parts = explode("/",$street_data);
// test to see if the part does not end with a number, if it doesn't, then we set $street_name to that value
if ( !preg_match("/[0-9]+$/",$parts[0],$matches) ) {
$street_name = $parts[0];
} else if ( !preg_match("/[0-9]+$/",$parts[1],$matches) ) {
$street_name = $parts[1];
} else {
// just in case they somehow both end with a number we just set $street_name to the first value
$street_name = $parts[0];
}
} else {
// if theres no "/" character then $street_name is set to the original string
$street_name = $street_data;
}
preg_match_all("/<b>([^<]+)<\/b>/",$html_instructions,$matches); // Find all bold contents
$lastval = count($matches[1]) - 1; // Identify the last bold string
$street_data = $matches[1][$lastval]; // Set that value to $street_data
if ( strstr($street_data,"/") ) { // If $street data contains a slash
$parts = explode("/",$street_data); // Split $street_data at the slash
if ( !preg_match("/[0-9]/",$parts[0],$matches) ) { // test to see if the part does not contain a number, if it doesn't, then we set $street_name to that value
$street_name = $parts[0];
}
else if ( !preg_match("/[0-9]/",$parts[1],$matches) ) {
$street_name = $parts[1];
}
else { // just in case they somehow both contain a number we just set $street_name to the first value
$street_name = $parts[0];
}
}
else { // if theres no "/" character then $street_name is set to the original string
$street_name = $street_data;
}
Exit onto <b>Route 625/W Main St</b> toward <b>Huntsville</b>
preg_match_all("/<b>([^<]+)<\/b>/",$html_instructions,$matches); // Find all bold contents
foreach($matches as $match) { // for each Bold tag
if( stripos($match,"/") ) { // if $match contains a slash
$parts=explode("/",$match); // Break it apart at the slash
if ( !preg_match("/[0-9]/",$parts[0],$match) ) { // If the part BEFORE the slash doesn't contain a number
$street_name=$parts[0];// use it as the street name
}
elseif ( !preg_match("/[0-9]/",$parts[1],$match) ) { // if the part AFTER the slash doesn't contain a number
$street_name=$parts[1]; // use it as the street name
}
else { // In case BOTH parts contain a number
$street_name=$parts[0]; // Just use the part before the slash
}
}
else { // If no slash was found in the $street_data
$street_name=$match; // put the $street_data through into the $street_name
}
$html_instructions=str_replace($match,$street_name,$html_instructions); // Puts the resolved street name in place of the complicated string
} // end foreach