Str_replace that En Dash (or minus sign)! How to fix the problem when it’s not working

HTML, PHP, Wordpress
Building my first theme on Wordpress I had been a very long time in to understand how to use str_replace function to change title of a page to remove all the words following another. This was approximately the string to change: i had name and surname of a specific person (John Doe) and what i wanted to do was to remove all the rest of the phrase. Page Title:  John Doe Contact Page – Sitename String i wanted to get as result after str_replace:  John Doe So practically i had to get just "John Doe" from that page title. The easiest way i knew was to use str_replace function in PHP in the following way: Getting the Wordpress Title as a variable: <?php $string = get_the_title(); $replace = " Contact Page - Sitename"; $replacewith   = " "; ?> Then using str_re