Question Mark in The Middle of a Url Variable

How to use a question mark in url?

You can still use the query string (?version=1) without having access to the server. Just capture the value using the method Austin linked and go from there.

Is it valid to have more than one question mark in a URL?

Yes, it is valid. Only the first ? in a URL has significance, any after it are treated as literal question marks:

The query component is indicated by
the first question mark ("?")
character and terminated by a number
sign ("#") character or by the end of
the URI.

...

The characters slash ("/") and
question mark ("?") may represent data
within the query component. Beware
that some older, erroneous
implementations may not handle such
data correctly when it is used as the
base URI for relative references
(Section 5.1), apparently because they
fail to distinguish query data from
path data when looking for
hierarchical separators. However, as
query components are often used to
carry identifying information in the
form of "key=value" pairs and one
frequently used value is a reference
to another URI, it is sometimes better
for usability to avoid
percent-encoding those characters.

https://www.rfc-editor.org/rfc/rfc3986#section-3.4

how to pass question mark in url javascript

There is not enough details in your question so I will assume that you are using AngularJS routing - or at least the $location service - in non-HTML5 mode. If so, the part after the # character represents your URL from the single-page-application point of view (more about AngularJS here).

If the above assumptions are correct it means that you shouldn't try to add or manipulate the question mark "by hand". Instead you should change the search part of the $location to manipulate query string (part after ?) and the question mark will be added / removed to the final URL as needed.

In your case you could write:

$location.path('/store/items').search('page', 2)

This is assuming that you are manipulating URLs from JavaScript, as stated in your question.

What is the question mark for in a Typescript parameter name

It is to mark the parameter as optional.

  • TypeScript handbook https://www.typescriptlang.org/docs/handbook/2/functions.html#optional-parameters
  • TypeScript Deep Dive https://basarat.gitbook.io/typescript/type-system/functions#optional-parameters

how to get url value after question mark in javascript

use this code:

var a = location.href; 
var b = a.substring(a.indexOf("?")+1);

How to remove ? (question mark) from url when it is not followed by any parameters?

You can use the String.prototype.slice() method to achieve this. If the last character of your url is '?', you can remove it from the url string.

let url = "www.someurl.com?";let length = url.length;if(url.charAt(length-1)==='?')url=url.slice(0,length-1);console.log(url);

PHP - How do question marks after address work?

If there's just ?foo the whole querystring which is available in $_SERVER['QUERY_STRING'] is "foo".

When using a HTML form with method="GET" you get key-value pairs which are then available via $_GET['key']. Actually you also receive those pairs when using POST but then they are not visible in the URL and you access them via $_POST['key'].


So your code would look like this assuming you want it totally simple and not use some advanced routing framework:

switch($_SERVER['QUERY_STRING']) {
case 'editname':
// do stuff
break;
case 'editpassword':
// do stuff
break;
default:
// do stuff if none of the cases matched
}

But I'd really suggest you to use proper GET variables instead of just plain query strings. Simply replace the first line of that snipped with this:

$action = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '';
switch($action) {


Related Topics



Leave a reply



Submit