-
Notifications
You must be signed in to change notification settings - Fork 7.9k
substring/subistring functions #6602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The function name |
Hello @vdelau, Javascrip too has this name. It has substr and substring both, and people are used to of using these functions. See the following entry in MDN docs. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring |
Hi @literary-programmer, the proposed functions would not take integer characters position (or lengths), but strings to look up in the string. The JavaScript functions you mention differ in the sense that they are function substring(string $haystack, string $from, string $to): string
{
$start = strpos($haystack, $from) + strlen($from);
$end = strpos($haystack, $to, $start);
return substr($haystack, $start, $end - $start);
} (Code is for illustration, not tested or verified against implementation.) |
I am struggling to think of when I would use these and not just use |
Thanks @vdelau for making it clear. Now, I do second your first
opinion. Even other languages beside js do have the similar function
signature. I suggest to make the substring function similar to what is
found in the other languages.
Because the strpos and stripos already exist in PHP, we don't need
such a function that takes string parameters. If Substring is
introduced as it exists in the other languages, it would be worth.
Moreover, this function will then have a wider scope.
Substr has following shortcomings:
1. It requires a length instead of an index. Therefore, to achieve the
substring effect, devs have to perform some math.
2. The length is different from the index positions. Therefore, math
always comes in.
And, I don't wish to see another misleading function in PHP like sizeof!
The substring function must behave like following:
`$scheme = substring($url, 0, strpos(':'));`
If one still wants to add such functions, they should not be named
subistring and substring.
Regards
…On 1/15/21, Mike Schinkel ***@***.***> wrote:
I am struggling to think of when I would use these and not just use
`preg_replace()`. In large part because `preg_replace()` can handle many
different match patterns and can support regular expression matching. Rhese
functions can only handle one match pattern with no wildcards. I can't
remember a time I would use them. #jmtcw
--
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
#6602 (comment)
|
Mailing list thread: https://externals.io/message/112864 |
What's the status here? Are you planning to draft an RFC? |
Closing as there was no response. |
Hi all - apologies for not replying, completely missed the notifications here. |
Functions and supporting tests for substring and case-insensitive subistring functions.
Returns a trim'd portion of the string found between two strings.