user10030215
user10030215

Reputation:

append space in URL in form of variable

I have an url say.

WWW.XYZ.COM

I have a varibale in bakend contains space in it. Then i want to add it with that url.

eg.www.xyz.com/variable   or www.xyz.com/stack over

But url is not going to accept it. How can i do this?

Upvotes: 3

Views: 585

Answers (4)

KeyMaker00
KeyMaker00

Reputation: 6462

Theory: From HTML URL Encoding Reference

  • URLs can only be sent over the Internet using the ASCII character-set.
  • Since URLs often contain characters outside the ASCII set, the URL has to be converted into a valid ASCII format.
  • URL encoding replaces unsafe ASCII characters with a "%" followed by two hexadecimal digits.
  • URLs cannot contain spaces. URL encoding normally replaces a space with a plus (+) sign or with %20.

In other words, every character ('a', 'b', '', '_', ...) can be replace with its correspondant ASCII representation. For example, the ASCII representation of space is %20.

Example: When you want to send the attribute "text" containing "Hello World" through a formular or URL, the web-server will process the input "text=Hello%20World" or, less frequent "text=Hello+World".

Your example: So, your URL www.xyz.com/stack over will be mostly represented as www.xyz.com/stack%20over

Reserved characther = | ; | / | # | ? | : | space are reserved characters. RFC 1630

Upvotes: 0

Sivabalakrishnan
Sivabalakrishnan

Reputation: 515

Say for Ex : this is your Stackoverflow URL

"stackoverflow.com/questions/51166674/append-space-in-url-in-form-of-variable"

Just Remove "-" in that.

Click Enter.

You Will See the same page with url

"stackoverflow.com/questions/51166674/append%20space%20in%20url%20in%20form%20of%20variable"

Just add %20 instead of space. I hope May be this is helpfull.

Thank you

Upvotes: 0

Dadhich Sourav
Dadhich Sourav

Reputation: 289

A typical URL embed %20 in place of space. That means your url www.xyz.com/stack overwill be treated as www.xyz.com/stack%20over. So, there can be a solution , write a function that will retrive data from backend as a %20 in every space. Then that will make an url. And try to make the pages appended as %20.

Upvotes: 1

Elbek
Elbek

Reputation: 646

You have to use url encode like function to eliminate some characters (converting to other composite characters). Example of url encode in php

Upvotes: 0

Related Questions