AV1611 Posted December 26, 2006 Share Posted December 26, 2006 I have a table and a field has a bunch of entries with backslashes (\) from some other script. I want to clean them all out.the bs's are not all in the same placeexample entry:buzz\_bait ---> buzz_bait\[HENRY\] ---> [HENRY]etc...I don't think subst() will do it because the bs's are in different position each time... can someone suggest the right function/command to use in PHP? Link to comment https://forums.phpfreaks.com/topic/31883-solved-easy-one/ Share on other sites More sharing options...
tomfmason Posted December 26, 2006 Share Posted December 26, 2006 have you tried stripslashes? Link to comment https://forums.phpfreaks.com/topic/31883-solved-easy-one/#findComment-147947 Share on other sites More sharing options...
Orio Posted December 26, 2006 Share Posted December 26, 2006 stripslashes() won't do the job here- because it doesnt remove the slashes from things like underscores or "[".You can use this function- $string should be the string that you want to remove the slashes from, and escaped should be an array containing all of the chars that got escaped and you want to un-escape.[code]<?phpfunction unescape($string, $escaped){ $b_slash = "\\"; foreach($escaped as $char) $string = str_replace($b_slash.$char, $char, $string); return $string;}$replace = array("[", "]", "&", "#");$string = "\\[Hello\\] \\& \\% \\' \\#"; //I've escaped the backslashes because I have to, not for the testecho $string;echo "<br>";echo unescape($string, $replace);/*Output:\[Hello\] \& \% \' \#[Hello] & \% \' #*/?>[/code]Orio. Link to comment https://forums.phpfreaks.com/topic/31883-solved-easy-one/#findComment-147975 Share on other sites More sharing options...
AV1611 Posted December 26, 2006 Author Share Posted December 26, 2006 actually I did it like this[code]$replace="\\";...$aa=$row[0];...$aa=str_replace($replace,"",$aa);...[/code]BTW thanks for the answer... Link to comment https://forums.phpfreaks.com/topic/31883-solved-easy-one/#findComment-147977 Share on other sites More sharing options...
tomfmason Posted December 26, 2006 Share Posted December 26, 2006 [quote author=Orio link=topic=119953.msg491770#msg491770 date=1167153853]stripslashes() won't do the job here- because it doesnt remove the slashes from things like underscores or "[".[/quote]Well I just tested this..[code]<?php$string = 'this is\_a \[test\]';echo stripslashes($string);?>[/code]The output was this is_a [test]. This worked fine.. it removed all \ s from the string.. I tried in several different ways all with the same out come..So I guess, unless I missed something, that stripslashes would work fine.. Link to comment https://forums.phpfreaks.com/topic/31883-solved-easy-one/#findComment-148012 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.