Escaping Single Quotes In A Url Link
I have a link that is sent throw some PHP code: echo 'voir sa galerie'; $gale
Solution 1:
it would interrupt the echo function
It wouldn't. It would break a string literal delimited by '
characters, but your string literal is delimited with "
characters. In this case, it is breaking the HTML attribute value which is delimited by '
characters.
\
is not an escape character for URLs or HTML.
Use urlencode
to make a string safe to put into a URL.
Use htmlspecialchars
to make a string safe to put into an HTML attribute.
$title = get_title($primid);
$urlsafe_title = urlencode($title);
$url = $galerry . "#" . $urlsafe_title;
$htmlsafe_url = htmlspecialchars($url, ENT_QUOTES | ENT_HTML5);
echo"<a href='$htmlsafe_url' class='linkorange'>voir sa galerie</a>";
Solution 2:
If you're looking to escape single quotes only, use double backslashes, as follows
$str= str_replace("'", "\\'", $str);
Post a Comment for "Escaping Single Quotes In A Url Link"