bulrush Posted August 10, 2010 Share Posted August 10, 2010 I've tried several variations of preg_replace to get rid of this string: "\f". But nothing seems to remove it. What am I doing wrong? Here is what I've tried. $partname=preg_replace('/\f/', '', $partname); $partname=preg_replace('/\\f/', '', $partname); This works fine in Perl, but not in PHP. In Perl you simply escape the backslash with another backslash. Link to comment https://forums.phpfreaks.com/topic/210347-cant-get-rid-of-f-string/ Share on other sites More sharing options...
Anti-Moronic Posted August 10, 2010 Share Posted August 10, 2010 Sorry I can't be more help - but have you tried using " " instead of ' '. PHP will treat \f as a literal if it's enclosed in ' '. Link to comment https://forums.phpfreaks.com/topic/210347-cant-get-rid-of-f-string/#findComment-1097652 Share on other sites More sharing options...
tgeorge06 Posted August 10, 2010 Share Posted August 10, 2010 what if you did $partname = str_replace("\f", "", "$partname"); Link to comment https://forums.phpfreaks.com/topic/210347-cant-get-rid-of-f-string/#findComment-1097654 Share on other sites More sharing options...
bulrush Posted August 10, 2010 Author Share Posted August 10, 2010 str_replace not working either. I tried: $partname = str_replace("\f", "", "$partname"); $partname = str_replace("\f", "", $partname); //No quotes around $partname All my other preg_replaces work, but I don't use backslash in any of them. It appears preg_replace and str_replace choke on a backslash. Link to comment https://forums.phpfreaks.com/topic/210347-cant-get-rid-of-f-string/#findComment-1097661 Share on other sites More sharing options...
tgeorge06 Posted August 10, 2010 Share Posted August 10, 2010 What about using ". ." around the \f $partname = str_replace(".\f.", "", "$partname"); Link to comment https://forums.phpfreaks.com/topic/210347-cant-get-rid-of-f-string/#findComment-1097663 Share on other sites More sharing options...
bulrush Posted August 10, 2010 Author Share Posted August 10, 2010 It worked! This is the only thing that worked. $partname = str_replace("\\f", "", "$partname"); Link to comment https://forums.phpfreaks.com/topic/210347-cant-get-rid-of-f-string/#findComment-1097665 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.