Returns a copy of a string with occurrences of one string replaced with another string
Class: String
Parameters: $string – String to copy
$oldString – String to be replaced
$newString – String to replace $oldString
d (Optional) – Integer indicating replacement method
Syntax: $returnString=$replace($string, $oldString, $newString [,d])
Returns:
• If d=0 or omitted – Replace all occurrences of $oldString with $newString
• If d=1 – Replace the first occurrence of $oldString with $newString
• If d=2 – Replace the last occurrence of $oldString with $newString
• If d=3 – $oldString is a regular expression
Remarks: To apply case sensitivity, add 4 to the value of a d
Example:
//Example for the string $left method
$s=”SEIKI BATCH SCRIPT” //Set string
$result=$replace($s, “ “, “_”) //Result (= ‘SEIKI_BATCH_SCRIPT’)
message(“All spaces replaced with underscores in “ + $s + “ is “ + $result) //Display results message