Can a query string parameter key contain the hyphen (-) char? [duplicate] - php

This question already has answers here:
Can hyphens be used in query string values?
(2 answers)
Closed 1 year ago.
Hello to everyone who might read this question.
The question is very basic, can a query string parameter key contain the hiphen (-) char?
I have this url
https://www.example.com/page?uid=83485743jfj4f37gj348&thank-you
Thank you all.

Judging from
https://url.spec.whatwg.org/#application-x-www-form-urlencoded-percent-encode-set
you can use the hypen character without any escaping.

Related

add INT with STRING in PHP [duplicate]

This question already has answers here:
Getting a number when it has certain prefix from a block of text in PHP
(3 answers)
Zero-pad digits in string
(5 answers)
Closed 1 year ago.
I am trying to add the int with strings in PHP but I could get a helpful answer on StackOverflow and other website communities.
I want the code separate the ALPHABETS and NUMBER and then add the value in NUMBER and again JOIN the ALPHABETS AND ADDED NUMBER together.
How I achieve this, Please help.
Example:
$mynumber = 'SBI0001';
$addValue = '1';
It will be 'SBI0002' in PHP.

Regex return string between two matches [duplicate]

This question already has answers here:
Get string between two strings
(6 answers)
Closed 6 years ago.
I'm trying to get the string between two specific matches, for example two hashtags.
What I would like to achieve:
input: some text in front ##hi there## some text behind
output: hi there
With /%%(.*)%%/, ##hi there## is returned.
Thanks in advance
You need a look ahead and look behind.
(?<=##).*(?=##)
This will match hi there
https://regex101.com/r/qUR4NR/1

Generate a variables length placement holder string for paramaterized queries in python [duplicate]

This question already has answers here:
python list in sql query as parameter [duplicate]
(16 answers)
Closed 8 years ago.
I'd like to build a query string with a variable length in where clause.
In PHP I might do this like
<?php
$vars=array('john','mike','matt');
$placeHolders=array_fill(0,sizeof($vars),'%s');
$whereClause=" name in (".join(',',$placeHolders).")";
Is there a concise Python translation of this in python
I think I'd use this to create the variable strings:
', '.join('%s' for _ in vars)
That eliminates the need to substring the result and gets you as many placeholders as you have values.

php regex match a comma delimited list of integers [duplicate]

This question already has answers here:
Difference between * and + regex
(7 answers)
Closed 4 years ago.
I know the following regex will match a single integer, as well as a list of comma delimited integers:
/^\d+(?:,\d+)*$/
How can i turn this into only matching a list of integers? A single integer should not match. 123,456 and 634,34643,3424 should match.
You would use the + operator meaning "one or more" times instead of * to repeat your group.
/^\d+(?:,\d+)+$/
Live Demo

How to select a word after a # using preg_match in php [duplicate]

This question already has answers here:
Preg replace to words with hash
(3 answers)
Closed 9 years ago.
I want to select a word that as hash using preg_match in php.
For Example consider this string:
Facebook has re-designed #timeline and it is out in New Zealand
Now I want to select #timeline how to do that, I use this code but it select only #t
preg_match_all("/#[a-zA-Z0-9]/")
Thanks in advance :)
It's currently only set up to select a single character following the #. Try this:
preg_match_all("/#[a-zA-Z0-9]+/")

Categories