Page 1 of 1
str_ireplace (or str_replace) only once?
Posted: Tue Jun 05, 2007 9:03 pm
by toasty2
I am replacing things but I only want to replace them once, how can I do that? (Case insensitive would be preferred)
Posted: Tue Jun 05, 2007 9:33 pm
by feyd
strpos() + 2 ×
substr() + concatenate.
Posted: Tue Jun 05, 2007 10:36 pm
by toasty2
I don't exactly follow what you mean. Could you please provide an example?
Posted: Tue Jun 05, 2007 10:38 pm
by feyd
Use
strpos() to find the position. Use
substr() to extract the information surrounding that position. Reconstruct the string using concatenation to substitute the now extracted text for the replacement.
I will not post code.
Posted: Wed Jun 06, 2007 4:46 am
by stereofrog
btw preg_replace has a "limit" param.
Posted: Wed Jun 06, 2007 7:52 am
by Chris Corbyn
Also check out substr_replace().