HI, I have string "test 3.0 krish" in the above string i want to replace space and .(dot) to "-". so that result should appear as : test-3-0-krishna. is there any function to achiveve this.
when i have multiple spaces in the string like : $temp="test 3.0 krish"; how to trim the spaces and put only one "-"
function format_string( $string ) { $string = preg_replace( "@ +@", " ", $string ); return str_replace(array(' ', '.'), '-', $string ); } echo format_string( 'a normal string' ); echo '<br />'; echo format_string( 'a not normal.string' ); PHP: