I've tried in many ways to replace ONLY degree and (greek)Phi symbols. I've googled and did everything the articles said to do, it's driving me crazy. I can't use htmlentities() because I don't want to encode the html tags... just those two characters, I do this... it doesn't return an error, just replaces the entire string with nothing
preg_replace(array('/( )+/', '/\x{00B0}/u', '/\x{03A6}/u', '/\x{03D5}/u'), array(' ','°','Φ','Φ'), $str);
By The Way, the first replace just gets rid of extra white space and that works fantastic, but when I add in the other three (degree, capital Phi and lowercase Phi), the entire string gets replaced with white space.
It appears your code is working as expected
Live Demo
Code
<?php
$string = 'hi ϕllip it is 900°';
$output = preg_replace(array('/( )+/', '/\x{00B0}/u', '/\x{03A6}/u', '/\x{03D5}/u'), array(' ','°','Φ','Φ'), $string );
echo "this is the output:" . $output;
Output
this is the output:hi Φllip it is 900°
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With