Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Double-Quotation Marks in a URL

Tags:

html

php

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>';
like image 590
John Avatar asked Dec 01 '22 10:12

John


2 Answers

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

like image 126
Paul Dixon Avatar answered Dec 09 '22 19:12

Paul Dixon


Make sure you urlencode your URL parameter values. see urlencode

like image 35
Robert Ros Avatar answered Dec 09 '22 19:12

Robert Ros