logo
Home XtGem- Templates- XtScript- bottom
XtGemmanual

XtScript functions

str replace

Find all occurrences of a sub-string within a string and replace them with another sub-string

Syntax

[var $... = ]call str_replace $subject=…;$search=…;$replace[=…][...] optional · ... your value

Example

<!--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-->  

Copy as text

Output 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‹

Related

str_ireplace

XtGem manual · all sections

Powered by XtGem
About us Contact Forum top