carsten888 Posted January 28, 2010 Share Posted January 28, 2010 I want to replace those leaning doublequotes to normal double quotes. for a normal double quote this works fine: $bb2html = str_replace('"','doublequote',$bb2html); but this does not work with “ and ”. how to str_replace “ doublequote? (I just deleted my sample codes because I saw in the preview those funny doublequotes got replaced) Link to comment https://forums.phpfreaks.com/topic/190091-how-to-str_replace-%E2%80%9C-doublequote/ Share on other sites More sharing options...
Yucky Posted January 28, 2010 Share Posted January 28, 2010 Just a quick example. $string = " “Test” "; $replace = array(chr(147),chr(148)); $string = str_replace($replace,'"',$string); echo $string; //Output is "Test" It depends on what character set you're using on the page. That should work for most though. Link to comment https://forums.phpfreaks.com/topic/190091-how-to-str_replace-%E2%80%9C-doublequote/#findComment-1002948 Share on other sites More sharing options...
oni-kun Posted January 28, 2010 Share Posted January 28, 2010 Damned hate for curly quotes and elipses. Use the following code, it should work on them: $search = array(chr(145), chr(146), chr(147), chr(148)); $replace = array("'", "'", '"', '"'); $string = str_replace($search, $replace, $string); Link to comment https://forums.phpfreaks.com/topic/190091-how-to-str_replace-%E2%80%9C-doublequote/#findComment-1002956 Share on other sites More sharing options...
carsten888 Posted January 28, 2010 Author Share Posted January 28, 2010 I can get this to work: $string = " “Test” "; $search = array(chr(145), chr(146), chr(147), chr(148)); $replace = array("'", "'", '"', '"'); $string = str_replace($search, $replace, $string); but it does not work with the string I submit! really weird. Never seen this before. string: s “alhij”dfv works in the above script, but not when I use it in my class. function bbcode_to_html($bb2html){ //find and replace b, url and img $bb2html = preg_replace_callback("/\[b\](.+?)\[\/b\]/i", array(get_class($this), 'get_b'), $bb2html); $bb2html = preg_replace_callback("/\[url\](.+?)\[\/url\]/i", array(get_class($this), 'get_link'), $bb2html); $bb2html = preg_replace_callback("/\[img\]http://(.+?)\[\/img\]/i", array(get_class($this), 'get_image'), $bb2html); //clean up all unclosed tags $bb2html = str_replace('[b]','',$bb2html); $bb2html = str_replace('[b]','',$bb2html); $bb2html = str_replace('[/b]','',$bb2html); $bb2html = str_replace('[/b]','',$bb2html); $bb2html = str_replace('[url=http://','',$bb2html); $bb2html = str_replace('[url]','',$bb2html); $bb2html = str_replace(']','',$bb2html); $bb2html = str_replace('[url]','',$bb2html); $bb2html = str_replace('[/url]','',$bb2html); $bb2html = str_replace('[/url]','',$bb2html); $bb2html = str_replace('[img]','',$bb2html); $bb2html = str_replace('[img]','',$bb2html); $bb2html = str_replace('[/img]','',$bb2html); $bb2html = str_replace('[/img]','',$bb2html); $bb2html = str_replace('[/','',$bb2html); $bb2html = str_replace('[','',$bb2html); $bb2html = str_replace(']','',$bb2html); //echo $bb2html; //echo '<br /><br />'; $search = array(chr(145), chr(146), chr(147), chr(148)); $replace = array("'", "'", '"', '"'); $bb2html = str_replace($search, $replace, $bb2html); //echo $bb2html; //exit; return $bb2html; } as you see I outputted it twice to see what going on and it simply outputs: s “alhij”dfv<br /><br />s “alhij”dfv What is there to overlook here? is this some bizar chartype issue? [sight] Link to comment https://forums.phpfreaks.com/topic/190091-how-to-str_replace-%E2%80%9C-doublequote/#findComment-1003131 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.