Jump to content

how to str_replace “ doublequote?


carsten888

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.