is there a function in PHP that I can use to replace a specific character with another one, but I should be able to limit the number of replacements done? I am currently trying to get preg_replace() to work, as it has that ability, but there seems to be something wrong. Here is what I am using:
$args[0] = preg_replace("/\$/", $args[$x], $args[0], 1);
$args[0] contains letters and special "$" characters, which should be replaced.
Any help?
Have you tried "/\\$/"
(2 backslashes)?
(See How to escape $ in PHP using preg_replace? for more info)
This is the syntax of replacement fn:
preg_replace($patterns, $replacements, $string);
so you have to put first the patterns after that the replacements (the char you want to replace with it) at the end of your string.