Jump to content

[SOLVED] replacing <


rarebit

Recommended Posts

Hi i'm stuck on how to make this one work?

<script type='text/javascript'>
var search = new Array(/\076:O/ig, /\x3e:O/ig, /\>:O/ig);
var replace = new Array('XYZ','xyz', 'abc');
var s = "Hello Mr. >!";
s.replace(search[0],replace[0]);
s.replace(search[1],replace[1]);
s.replace(search[2],replace[2]);
document.write(s);
</script>

Link to comment
https://forums.phpfreaks.com/topic/135394-solved-replacing/
Share on other sites

Try this:

 

<script type='text/javascript'>
var search = new Array(/\076:O/ig, /\x3e:O/ig, /\>:O/ig);
var replace = new Array('XYZ','xyz', 'abc');
var s = "Hello Mr. >!";
s = s.replace(search[0],replace[0]);
s = s.replace(search[1],replace[1]);
s = s.replace(search[2],replace[2]);
document.write(s);
</script>

 

The replace() method returns the result... it does not apply it to the string automatically.

Link to comment
https://forums.phpfreaks.com/topic/135394-solved-replacing/#findComment-705229
Share on other sites

Boo Hoo!

 

mmm, that's how I have it in the production code, hadn't noticed here, but for some reason it works in the test but not the production:

search = new Array(
	/\[b\](.*?)\[\/b\]/ig,
	/\[i\](.*?)\[\/i\]/ig,
	/\[u\](.*?)\[\/u\]/ig,
	/\[h1\](.*?)\[\/h1\]/ig,
	/\[h2\](.*?)\[\/h2\]/ig,
	/\[h3\](.*?)\[\/h3\]/ig,
	/\[h4\](.*?)\[\/h4\]/ig,
	/\[sub\](.*?)\[\/sub\]/ig,
	/\[sup\](.*?)\[\/sup\]/ig,
	/\[tt\](.*?)\[\/tt\]/ig,
	/\[s\](.*?)\[\/s\]/ig,
	/\[em\](.*?)\[\/em\]/ig,
	/\[strong\](.*?)\[\/strong\]/ig,
	/\[samp\](.*?)\[\/samp\]/ig,
	/\[kbd\](.*?)\[\/kbd\]/ig,
	/\[code\](.*?)\[\/code\]/ig,
	/\[code=(.*?)\]

 

All the escapism is because it's dumped out by php, and i've tried extra escaping on the backslash...

 

Cheers

Link to comment
https://forums.phpfreaks.com/topic/135394-solved-replacing/#findComment-705237
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.