Hello all.
I am new to PHP and I hope my question is simply a matter of overlooking the obvious. I have looked at many sites, including php.net, and I cannot find a way to elegantly manipulate a string (or array) in a manner I want.
I want to simply -- either through intrinsic or user-defined function -- update a value in a semi-colon-delimited string/array. For example, I would want to replace the sixth value in a string.
HAVE : 0;0;0;1;some_data;UNWANTED_DATA;0;0;1
WANT : 0;0;0;1;some_data;NEW_DATA;0;0;1
Does it require a loop to with a nested if statement? Is it a RegEx situation?
All help is appreciated.
String Manipulation
Moderator: General Moderators
Re: String Manipulation
Code: Select all
$string = '0;0;0;1;some_data;UNWANTED_DATA;0;0;1';
$stringParts = explode(';', $string);
$stringParts[5] = 'NEW_DATA';
$string = implode(';', $stingParts);
Re: String Manipulation
Thank you.