Changeset 25425 for trunk/include/functions.inc.php
- Timestamp:
- Nov 10, 2013, 5:18:55 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/functions.inc.php
r25360 r25425 63 63 { 64 64 return number_format( $end - $start, 3, '.', ' ').' s'; 65 }66 67 // - The replace_space function replaces space and '-' characters68 // by their HTML equivalent &nbsb; and −69 // - The function does not replace characters in HTML tags70 // - This function was created because IE5 does not respect the71 // CSS "white-space: nowrap;" property unless space and minus72 // characters are replaced like this function does.73 // - Example :74 // <div class="foo">My friend</div>75 // ( 01234567891111111111222222222233 )76 // ( 0123456789012345678901 )77 // becomes :78 // <div class="foo">My friend</div>79 function replace_space( $string )80 {81 //return $string;82 $return_string = '';83 // $remaining is the rest of the string where to replace spaces characters84 $remaining = $string;85 // $start represents the position of the next '<' character86 // $end represents the position of the next '>' character87 ; // -> 088 $end = strpos ( $remaining, '>' ); // -> 1689 // as long as a '<' and his friend '>' are found, we loop90 while ( ($start=strpos( $remaining, '<' )) !==false91 and ($end=strpos( $remaining, '>' )) !== false )92 {93 // $treatment is the part of the string to treat94 // In the first loop of our example, this variable is empty, but in the95 // second loop, it equals 'My friend'96 $treatment = substr ( $remaining, 0, $start );97 // Replacement of ' ' by his equivalent ' '98 $treatment = str_replace( ' ', ' ', $treatment );99 $treatment = str_replace( '-', '−', $treatment );100 // composing the string to return by adding the treated string and the101 // following HTML tag -> 'My friend</div>'102 $return_string.= $treatment.substr( $remaining, $start, $end-$start+1 );103 // the remaining string is deplaced to the part after the '>' of this104 // loop105 $remaining = substr ( $remaining, $end + 1, strlen( $remaining ) );106 }107 $treatment = str_replace( ' ', ' ', $remaining );108 $treatment = str_replace( '-', '−', $treatment );109 $return_string.= $treatment;110 111 return $return_string;112 65 } 113 66
Note: See TracChangeset
for help on using the changeset viewer.