简体   繁体   中英

Using Double-Quotation Marks in a URL

The link below works fine unless the variable $row["title"] contains a double-quotation mark ("). In that case, everything after the quotation marks is omitted in the link.

How can I make the link include everything after a double-quotation mark?

Thanks in advance,

John

echo '<td class="sitename2"><a href="http://www...com/.../comments/index.php?submission='.$row["title"].'">'.$row["countComments"].' COMMENTS</a></td>';

Always use urlencode for parts of a URL which might need to contain anything unusual....

echo '<td class="sitename2">'.
  '<a href="http://www...com/.../comments/index.php?submission='.
  urlencode($row["title"]).
  '">'.
  $row["countComments"].' COMMENTS</a></td>';

If you want to get into the standards, refer to RFC3986 which defines the safe, or 'unreserved' character as follows:

unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"

urlencode makes sure that a value you want to include in a URL obeys these standards

Make sure you urlencode your URL parameter values. see urlencode

. urlencode($row['title']) . '"> etc

the values of parameters in a url must be escaped in order for the url to be valid.

so instead of

$row["title"]

use

urlencode($row["title"])

urlencode will transform the double-quote into %22 so you will avoid the problem with the wrong double-quote ending your link.

Jerome Wagner

In my case, urlencode did not help, I used urlencode ($var) and the result in the browser is: localhost/"aaMoldau+-+Aus+dem+Zyklus++"Mein+Vaterland""/

What the browser says:

An Error Was Encountered

The URI you submitted has disallowed characters.

And here is my MYSQL entry ($var):

aaMoldau - Aus dem Zyklus "Mein Vaterland"

update:

the quotes in the beginning and end of $var are clear, because I inserted them, but still the error is there.

(I do not understand why urlencode creates double quotes in the beginning and in the end.)

Furthermore, the double quote before 'Mein' and after Vaterland should be removed ?

Update 2: I now used str_replace to remove the double quotes together with urlencode and it is fine. But I thought I did not need str_replace ?

Furthermore, I read another post of stack where it is recommended to change my allowed uri chars to: $config['permitted_uri_chars'] = '+=\\az 0-9~%.:_-';

Here CodeIgnite was the problem but now solved. Strange that CI does not accept + in principal which is needed in spaces .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM