Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Never trust an operating system.


devel / comp.lang.php / Re: question about

SubjectAuthor
* question aboutalex
+- Re: question aboutKristjan Robam
`* Re: question aboutJ.O. Aho
 `* Re: question aboutLew Pitcher
  `- Re: question aboutLew Pitcher

1
question about

<sv5hqt$h8m$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=434&group=comp.lang.php#434

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!aioe.org!J/+ttyvLGPMUJZz1/1rzLg.user.46.165.242.91.POSTED!not-for-mail
From: 1j9448a02@lnx159sneakemail.com.invalid (alex)
Newsgroups: comp.lang.php
Subject: question about
Date: Wed, 23 Feb 2022 15:54:21 +0100
Organization: Aioe.org NNTP Server
Message-ID: <sv5hqt$h8m$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="17686"; posting-host="J/+ttyvLGPMUJZz1/1rzLg.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Content-Language: it-IT
X-Notice: Filtered by postfilter v. 0.9.2
 by: alex - Wed, 23 Feb 2022 14:54 UTC

$ echo center | sed -E 's#(.*)#start-\1-end#'
start-center-end

I tried to do the same thing with php, but the result is different

$ php -r "echo preg_replace('#(.*)#', 'start-\0-end', 'center') . PHP_EOL;"
start-center-endstart--end
^^^^^^^^^^

Why?

Re: question about

<eff37a28-9daa-4a5a-a5a7-fa1fcbb437abn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=472&group=comp.lang.php#472

  copy link   Newsgroups: comp.lang.php
X-Received: by 2002:ac8:5dcf:0:b0:2e1:baf1:502d with SMTP id e15-20020ac85dcf000000b002e1baf1502dmr16619310qtx.635.1649070387390;
Mon, 04 Apr 2022 04:06:27 -0700 (PDT)
X-Received: by 2002:a81:b288:0:b0:2d6:39d5:31a1 with SMTP id
q130-20020a81b288000000b002d639d531a1mr21699815ywh.506.1649070387168; Mon, 04
Apr 2022 04:06:27 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.php
Date: Mon, 4 Apr 2022 04:06:27 -0700 (PDT)
In-Reply-To: <sv5hqt$h8m$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=193.40.120.146; posting-account=JEMYqwoAAADm_ixjLuCjmrPjjrta833N
NNTP-Posting-Host: 193.40.120.146
References: <sv5hqt$h8m$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <eff37a28-9daa-4a5a-a5a7-fa1fcbb437abn@googlegroups.com>
Subject: Re: question about
From: he6655442211@hotmail.com (Kristjan Robam)
Injection-Date: Mon, 04 Apr 2022 11:06:27 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 21
 by: Kristjan Robam - Mon, 4 Apr 2022 11:06 UTC

Something for You.

Can You help me out with 2100 euros ?

I want to buy a new Iphone.

Kristjan Robam

alex kirjutas Kolmapäev, 23. veebruar 2022 kl 16:54:33 UTC+2:
> $ echo center | sed -E 's#(.*)#start-\1-end#'
> start-center-end
>
> I tried to do the same thing with php, but the result is different
>
> $ php -r "echo preg_replace('#(.*)#', 'start-\0-end', 'center') . PHP_EOL;"
> start-center-endstart--end
> ^^^^^^^^^^
>
> Why?

Re: question about

<jb06eqFiv7oU1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=473&group=comp.lang.php#473

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: user@example.net (J.O. Aho)
Newsgroups: comp.lang.php
Subject: Re: question about
Date: Mon, 4 Apr 2022 14:26:01 +0200
Lines: 32
Message-ID: <jb06eqFiv7oU1@mid.individual.net>
References: <sv5hqt$h8m$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: individual.net 6PS+ORLGkNnBo/8dHeHqNwau3xfO8qOJ09N5qs82wpMvhEo91q
Cancel-Lock: sha1:QtNW5/rsIAUfI0H47Ab4QEEUBl4=
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.7.0
Content-Language: en-US-large
In-Reply-To: <sv5hqt$h8m$1@gioia.aioe.org>
 by: J.O. Aho - Mon, 4 Apr 2022 12:26 UTC

On 23/02/2022 15.54, alex wrote:
> $ echo center | sed -E 's#(.*)#start-\1-end#'
> start-center-end
>
> I tried to do the same thing with php, but the result is different
>
> $ php -r "echo preg_replace('#(.*)#', 'start-\0-end', 'center') . PHP_EOL;"
> start-center-endstart--end
>                 ^^^^^^^^^^
>
> Why?

Why I'm not sure, but figured out two solutions:

You set a number a limit to the replacement

$ php -r "echo preg_replace('#(.*)#', 'start-\1-end', 'center', 1) .
PHP_EOL;"

or you can tell that it's from the beginning of the row

$ php -r "echo preg_replace('#^(.*)#', 'start-\1-end', 'center') . PHP_EOL;

I would guess this has to do with the end of char array \0 (internally)
and it's counted as a white space, so it's not included in the first
match, but then as the second match, but that is just a wild guess.

--

//Aho

Re: question about

<t2eqjf$946$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=475&group=comp.lang.php#475

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: lew.pitcher@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.lang.php
Subject: Re: question about
Date: Mon, 4 Apr 2022 13:07:59 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 88
Message-ID: <t2eqjf$946$1@dont-email.me>
References: <sv5hqt$h8m$1@gioia.aioe.org>
<jb06eqFiv7oU1@mid.individual.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 4 Apr 2022 13:07:59 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="3ba0a11514d40783debc501d31ab9e57";
logging-data="9350"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19W0TvtDyOj36Rbnt8cjyucSRZUkQ5hC+8="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:uCS33krIZZpIuFYgDiUej6psFgI=
 by: Lew Pitcher - Mon, 4 Apr 2022 13:07 UTC

On Mon, 04 Apr 2022 14:26:01 +0200, J.O. Aho wrote:

> On 23/02/2022 15.54, alex wrote:
>> $ echo center | sed -E 's#(.*)#start-\1-end#'
>> start-center-end
>>
>> I tried to do the same thing with php, but the result is different
>>
>> $ php -r "echo preg_replace('#(.*)#', 'start-\0-end', 'center') . PHP_EOL;"
>> start-center-endstart--end
>>                 ^^^^^^^^^^
>>
>> Why?
>
> Why I'm not sure,

So, let's look at it and figure the "why" out, shall we?

The first three arguments to preg_replace() are
the regex pattern to test with
the substitution pattern to replace regex matches with, and
the string to be tested with the regex

In the OP's case, the regex pattern is
#(.*)#
where the # characters simply delimit the edges of the regex.
(Note that the convention is to use forward slashes, but PHP
preg_replace() accepts other characters as well. So, you might
normally see this pattern as /(.*)/ in other regex parsers.)

As the octothorpe signs are string delimiters rather than part
of the regex match string, the OP's regex devolves to
(.*)
which will match to ZERO OR MORE occurrences of ANY character.

The OP's substitution pattern is
start-\0-end
which instructs preg_replace() to replace the matched input
with ITSELF (\0), immediately preceded by "start-", and
immediately followed by "-end".

Finally, we get the OP's input string
center

Combine these two, and we get
- the regex #(.*)# matches the multi-character input string
'center'
- preg_replace() replaces 'center' with the interpreted
replacement string, resulting in an output of
begin-center-end
- the regex #(.*) matches EXACTLY ZERO characters in the
remaining input string
- preg_replace() replaces EXACTLY ZERO characters with
the interpreted replacement string, resulting in an
additional output of
begin--end
(note the EXACTLY ZERO characters copied from the input
to the gap between the 'begin-' portion and the '-end'
portion)
- the regex has run out of string, and preg_replace() stops.

> but figured out two solutions:
>
> You set a number a limit to the replacement

Thus telling preg_replace() to stop before it matches the
remaining nothing to (.*)
> $ php -r "echo preg_replace('#(.*)#', 'start-\1-end', 'center', 1) .
> PHP_EOL;"
>
> or you can tell that it's from the beginning of the row

Thus telling preg_replace() to /only/ match everything up to and
including the remaining nothing at the end of the input.

> $ php -r "echo preg_replace('#^(.*)#', 'start-\1-end', 'center') . PHP_EOL;
>
> I would guess this has to do with the end of char array \0 (internally)
> and it's counted as a white space, so it's not included in the first
> match, but then as the second match, but that is just a wild guess.

HTH
--
Lew Pitcher
"In Skills, We Trust"

Re: question about

<t2ersm$946$3@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=477&group=comp.lang.php#477

  copy link   Newsgroups: comp.lang.php
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: lew.pitcher@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.lang.php
Subject: Re: question about
Date: Mon, 4 Apr 2022 13:29:58 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 101
Message-ID: <t2ersm$946$3@dont-email.me>
References: <sv5hqt$h8m$1@gioia.aioe.org>
<jb06eqFiv7oU1@mid.individual.net> <t2eqjf$946$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 4 Apr 2022 13:29:58 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="3ba0a11514d40783debc501d31ab9e57";
logging-data="9350"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Tn37aR8HS/0SD2hYYuGQMEU0Gw1rc0gk="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:/co3rBtlACzlBlE8jSCk0wBe4eg=
 by: Lew Pitcher - Mon, 4 Apr 2022 13:29 UTC

On Mon, 04 Apr 2022 13:07:59 +0000, Lew Pitcher wrote:

> On Mon, 04 Apr 2022 14:26:01 +0200, J.O. Aho wrote:
>
>> On 23/02/2022 15.54, alex wrote:
>>> $ echo center | sed -E 's#(.*)#start-\1-end#'
>>> start-center-end
>>>
>>> I tried to do the same thing with php, but the result is different
>>>
>>> $ php -r "echo preg_replace('#(.*)#', 'start-\0-end', 'center') . PHP_EOL;"
>>> start-center-endstart--end
>>>                 ^^^^^^^^^^
>>>
>>> Why?
>>
>> Why I'm not sure,
>
> So, let's look at it and figure the "why" out, shall we?
>
> The first three arguments to preg_replace() are
> the regex pattern to test with
> the substitution pattern to replace regex matches with, and
> the string to be tested with the regex
>
> In the OP's case, the regex pattern is
> #(.*)#
> where the # characters simply delimit the edges of the regex.
> (Note that the convention is to use forward slashes, but PHP
> preg_replace() accepts other characters as well. So, you might
> normally see this pattern as /(.*)/ in other regex parsers.)
>
> As the octothorpe signs are string delimiters rather than part
> of the regex match string, the OP's regex devolves to
> (.*)
> which will match to ZERO OR MORE occurrences of ANY character.
>
> The OP's substitution pattern is
> start-\0-end
> which instructs preg_replace() to replace the matched input
> with ITSELF (\0), immediately preceded by "start-", and
> immediately followed by "-end".
>
> Finally, we get the OP's input string
> center
>
> Combine these two, and we get
> - the regex #(.*)# matches the multi-character input string
> 'center'
> - preg_replace() replaces 'center' with the interpreted
> replacement string, resulting in an output of
> begin-center-end
> - the regex #(.*) matches EXACTLY ZERO characters in the
> remaining input string
> - preg_replace() replaces EXACTLY ZERO characters with
> the interpreted replacement string, resulting in an
> additional output of
> begin--end
> (note the EXACTLY ZERO characters copied from the input
> to the gap between the 'begin-' portion and the '-end'
> portion)
> - the regex has run out of string, and preg_replace() stops.
>
>> but figured out two solutions:
>>
>> You set a number a limit to the replacement
>
> Thus telling preg_replace() to stop before it matches the
> remaining nothing to (.*)
>
>> $ php -r "echo preg_replace('#(.*)#', 'start-\1-end', 'center', 1) .
>> PHP_EOL;"
>>
>> or you can tell that it's from the beginning of the row
>
> Thus telling preg_replace() to /only/ match everything up to and
> including the remaining nothing at the end of the input.

Oops... strike that. My response was for a different (and bad) solution

>> $ php -r "echo preg_replace('#^(.*)#', 'start-\1-end', 'center') . PHP_EOL;

Thus telling preg_replace() to /only/ match everything from the BEGINNING
of the input (the remaining nothing isn't at the beginning, so it doesn't
match).

>> I would guess this has to do with the end of char array \0 (internally)
>> and it's counted as a white space, so it's not included in the first
>> match, but then as the second match, but that is just a wild guess.
>
>
>
> HTH

--
Lew Pitcher
"In Skills, We Trust"

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor