Ask a Question related to PHP Development, Design and Development.
-
sinister #1
modify string in one position only
Is it possible to modify a string in one place using an indexing operator
and an assignment statement?
E.g.:
$s = "1234567890";
$s[5] = "d"; // $s is now "12345d7890"
According to _PHP Bible_ (2nd ed., p.175), this kind of syntax can work ,
but is undocumented and, moreover, appears to be discouraged because "almost
all PHP string manipulation functions return modified copies of their string
arguments rather than making direct changes, which seems to indicate that
this is the style that the PHP designers prefer."
I did a google search (both www and USENET) and found nothing on this.
sinister Guest
-
Strip out from a position till end of string
I'm trying to link to google maps from my website, but some of the addresses in the database I have, include the apartment number (eg. #2b), so I... -
Position of String Occurence
Hey guys, I have a string like "lalala: djkahsd : dajkdassd : adasd :" Is there a function to find the position of the "I"th occurence of a... -
awk : find position of nth occurrence in string
In awk, how can I find the position of the nth occurrence of a character in a string. I want to find the position of the 10th tab character in a... -
how can I modify a string within a file?
I have a config file with various parameters defined and I want to change the value for one of the parms. The problem is that I have about 100 of... -
Return a Character String-position through a function
Thanks in advance for your help! (MS Access 2000 Professional) I have the following function: Public Function EnterMfgPartNum(Placeholder As... -
Jon Kraft #2
Re: modify string in one position only
"sinister" <sinister@nospam.invalid> wrote:
Hi,> Is it possible to modify a string in one place using an indexing
> operator and an assignment statement?
>
> E.g.:
> $s = "1234567890";
> $s[5] = "d"; // $s is now "12345d7890"
Square brackets here are deprecated since 4.0, use curly braces:
$s = "1234567890";
$s{5} = "d"; // $s is now "12345d7890"
HTH;
JOn
Jon Kraft Guest
-
sinister #3
Re: modify string in one position only
"Jon Kraft" <jon@jonux.co.uk> wrote in message
news:Xns943D85B786EB6jonjonuxcouk@130.133.1.4...My question wasn't really about {} or []; I already knew the difference.> "sinister" <sinister@nospam.invalid> wrote:
>>> > Is it possible to modify a string in one place using an indexing
> > operator and an assignment statement?
> >
> > E.g.:
> > $s = "1234567890";
> > $s[5] = "d"; // $s is now "12345d7890"
> Hi,
>
> Square brackets here are deprecated since 4.0, use curly braces:
>
> $s = "1234567890";
> $s{5} = "d"; // $s is now "12345d7890"
The line
$s{5} = "d";
(that is, altering a string by an indexing operator and an assignment
statement) isn't documented anywhere either.
>
> HTH;
> JOn
sinister Guest
-
Jon Kraft #4
Re: modify string in one position only
"sinister" <sinister@nospam.invalid> wrote:
Your question was whether it was possible.> "Jon Kraft" <jon@jonux.co.uk> wrote:>>> "sinister" <sinister@nospam.invalid> wrote:
>>>>>> > Is it possible to modify a string in one place using an indexing
>> > operator and an assignment statement?
>> >
>> > E.g.:
>> > $s = "1234567890";
>> > $s[5] = "d"; // $s is now "12345d7890"
>> Square brackets here are deprecated since 4.0, use curly braces:
>>
>> $s = "1234567890";
>> $s{5} = "d"; // $s is now "12345d7890"
> My question wasn't really about {} or []; I already knew the difference.
>
> The line
> $s{5} = "d";
> (that is, altering a string by an indexing operator and an assignment
> statement) isn't documented anywhere either.
From the manual:
"Characters within strings may be accessed by specifying the zero-based
offset of the desired character after the string in curly braces."
[url]http://uk.php.net/manual/en/language.types.string.php[/url]
Although the example given shows how to read certain characters in a
string, the term "accessed" doesn't necessarily imply read-only.
JOn
Jon Kraft Guest
-
sinister #5
Re: modify string in one position only
"Jon Kraft" <jon@jonux.co.uk> wrote in message
news:Xns943DC81074F67jonjonuxcouk@130.133.1.4...That's simply not clear. That they don't give an example of a write isn't> "sinister" <sinister@nospam.invalid> wrote:
>>> > "Jon Kraft" <jon@jonux.co.uk> wrote:> >> >> "sinister" <sinister@nospam.invalid> wrote:
> >>
> >> > Is it possible to modify a string in one place using an indexing
> >> > operator and an assignment statement?
> >> >
> >> > E.g.:
> >> > $s = "1234567890";
> >> > $s[5] = "d"; // $s is now "12345d7890"
> >>
> >> Square brackets here are deprecated since 4.0, use curly braces:
> >>
> >> $s = "1234567890";
> >> $s{5} = "d"; // $s is now "12345d7890"
> > My question wasn't really about {} or []; I already knew the difference.
> >
> > The line
> > $s{5} = "d";
> > (that is, altering a string by an indexing operator and an assignment
> > statement) isn't documented anywhere either.
> Your question was whether it was possible.
>
> From the manual:
> "Characters within strings may be accessed by specifying the zero-based
> offset of the desired character after the string in curly braces."
>
> [url]http://uk.php.net/manual/en/language.types.string.php[/url]
>
> Although the example given shows how to read certain characters in a
> string, the term "accessed" doesn't necessarily imply read-only.
encouraging. Nor do they illustrate this operation anywhere else in the
manual, AFAICT.
I do appreciate your having commented, however.
>
> JOn
sinister Guest



Reply With Quote

