logo
Home XtGem- Templates- XtScript- bottom
Find all occurrences of a sub-string within a string and replace them with another sub-string
[...] = optional ... = your value
[var $... = ]call str_replace $subject=…;$search=…;$replace[=…]
Show in textarea
<!--parser:xtscript-->
# Special cases semi-colons and spaces

var $input = f o o b« a« r«

# how to assign a space for str_replace
var $this = call chr $val=32

# how to assign a ; (semi-colon) for str_replace 
var $that = call chr $val=59

var $output = call str_replace $subject=$input; $search=$this ; $replace=$that
print  input = $input<br />
print output = $output<hr/>

/* how to assign characters that your browser/device cannot reproduce from the keypad
this example uses «  known as  the left angle quote */
 var $this=call urldecode $val=%C2%AB 

# and ‹ known as  the left single angle quote 
var $that=call urldecode $val=%E2%80%B9

var $output = call str_replace $subject=$input; $search=$this ; $replace=$that
print  input = $input<br />
print output = $output
<!--/parser:xtscript-->  
Show in textarea
Reload
input = f o o b« a« r«
output = f;o;o;b«;a«;r«
input = f o o b« a« r«
output = f o o b‹ a‹ r‹
Powered by XtGem
About us Contact Forum top