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) Quote Link to comment 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. Quote Link to comment 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); Quote Link to comment 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] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.