How to escape characters in href of anchor tag


Kuldeep dangi

I want to escape three characters, these are

  1. apostrophe(')
  2. Double quotes(")
  3. backslash()

my href value istest.html?key="test' me'"&event=3

I want to fix it phpby callingaddslashes function

<a href="test.html?key="test' me'"&event=3">test</a>

Note: I need a dynamic way to do this

Quentin

The PHP function used to get the data and generate a properly encoded query string is http_build_query. You can then put it in a URL and encode it using htmlspecialcharsto insert it into the document.

<?php

    $base = "test.html";
    $query_data = Array(
        "key" => "\"test' me'\"",
        "event" => 3
    );
    $url = $base . "?" . http_build_query($query_data);
    $html_safe_url = htmlspecialchars($url);
?>

    <a href="<?= $html_safe_url ?>">test</a>

Related


How to escape characters in href of anchor tag

Kuldeep dangi I want to escape three characters, these are apostrophe(') Double quotes(") backslash() my href value istest.html?key="test' me'"&event=3 I want to fix it phpby callingaddslashes function <a href="test.html?key="test' me'"&event=3">test</a> Note

How to open alert box in anchor tag <a href>?

Anuja Lamaheva I want to open an alert box when a certain link is clicked. How to do it? username You can also use the following code: <a href="#" id="link">Link</a> Javascript: $(document).on("click","#link",function(){ alert("I am a pop up ! "); }); eithe

How to focus on anchor tag without href="#"

username How to focus when using keyboard tabs? <a class="ui-datepicker-prev ui-corner-all" data-handler="prev" data-event="click" title="Prev"><span class="ui-icon ui-icon-circle-triangle-w">Prev</span></a> I try to use CSS like this ui-datepicker-prev:focus

How to open alert box in anchor tag <a href>?

Anuja Lamaheva I want to open an alert box when a certain link is clicked. How to do it? username You can also use the following code: <a href="#" id="link">Link</a> Javascript: $(document).on("click","#link",function(){ alert("I am a pop up ! "); }); or: <

How to use querySelector with anchor tag with href?

User 3242861 I'm trying to use dropzone and I have an anchor tag to which I need to add an event click, but the way I'm doing this returns an error. URL: <a href="#new-intervention">Criar Intervenção</a> Inquire: var myDropzone = this; this.element.querySele

How to open alert box in anchor tag <a href>?

Anuja Lamaheva I want to open an alert box when a certain link is clicked. How to do it? username You can also use the following code: <a href="#" id="link">Link</a> Javascript: $(document).on("click","#link",function(){ alert("I am a pop up ! "); }); eithe

How to focus on anchor tag without href="#"

username How to focus when using keyboard tabs? <a class="ui-datepicker-prev ui-corner-all" data-handler="prev" data-event="click" title="Prev"><span class="ui-icon ui-icon-circle-triangle-w">Prev</span></a> I try to use CSS like this ui-datepicker-prev:focus

How to focus on anchor tag without href="#"

username How to focus when using keyboard tabs? <a class="ui-datepicker-prev ui-corner-all" data-handler="prev" data-event="click" title="Prev"><span class="ui-icon ui-icon-circle-triangle-w">Prev</span></a> I try to use CSS like this ui-datepicker-prev:focus

How to focus on anchor tag without href="#"

username How to focus when using keyboard tabs? <a class="ui-datepicker-prev ui-corner-all" data-handler="prev" data-event="click" title="Prev"><span class="ui-icon ui-icon-circle-triangle-w">Prev</span></a> I try to use CSS like this ui-datepicker-prev:focus

How to do both onClick and href in anchor tag (<a>)

username I have a link like this: <a href="www.google.com" onClick="someFunction()">Click me</a> After clicking the link, it's executing the javascript function but it doesn't take me to the href link. How can I do this? Esco I think the easiest way is to mak

How to open alert box in anchor tag <a href>?

Anuja Lamaheva I want to open an alert box when a certain link is clicked. How to do it? username You can also use the following code: <a href="#" id="link">Link</a> Javascript: $(document).on("click","#link",function(){ alert("I am a pop up ! "); }); or: <

How to open alert box in anchor tag <a href>?

Anuja Lamaheva I want to open an alert box when a certain link is clicked. How to do it? username You can also use the following code: <a href="#" id="link">Link</a> Javascript: $(document).on("click","#link",function(){ alert("I am a pop up ! "); }); eithe

How to focus on anchor tag without href="#"

username How to focus when using keyboard tabs? <a class="ui-datepicker-prev ui-corner-all" data-handler="prev" data-event="click" title="Prev"><span class="ui-icon ui-icon-circle-triangle-w">Prev</span></a> I try to use CSS like this ui-datepicker-prev:focus

How to focus on anchor tag without href="#"

username How to focus when using keyboard tabs? <a class="ui-datepicker-prev ui-corner-all" data-handler="prev" data-event="click" title="Prev"><span class="ui-icon ui-icon-circle-triangle-w">Prev</span></a> I try to use CSS like this ui-datepicker-prev:focus

onclick and href in anchor tag

Mohamed Arifkhan A How to do both onclick and href in anchor tag in javascript . My code is: enter code here for (l = 0; l < k; l++) { var tmp1 = searched_headings_filename[l]; var tmp2 = searched_headings[l]; frameDoc.body.innerHTML += '<div styl

onclick and href in anchor tag

Mohamed Arifkhan A How to do both onclick and href in anchor tag in javascript . My code is: enter code here for (l = 0; l < k; l++) { var tmp1 = searched_headings_filename[l]; var tmp2 = searched_headings[l]; frameDoc.body.innerHTML += '<div styl

How to get href value if anchor tag contains image tag

Sun I am trying to get the image src with jquery, this is the code below jQuery("img").click(function() { var im = $(this).attr('src'); alert(im); return false; }); The above works fine and I can get the image src. Also, I try to get the href val

How to get href value if anchor tag contains image tag

sun I am trying to get the image src with jquery, this is the code below jQuery("img").click(function() { var im = $(this).attr('src'); alert(im); return false; }); The above works fine and I can get the image src. Also, I try to get the href val

How to replace some text in href of anchor tag in jQuery

Ram Singh I have few url anchors like "http%3a/test.dev.test.com/posts/test test" and I want to replace it with " http://test.dev.test.com/posts/test Test" on the window loading function, I have tried the following code but it does not update the url of the an

How to execute href link and onClick function in anchor tag <a>

Yakub I need to redirect to another page via href and then execute my onClick function. I hope that when you click "Zobrazit namapě" here http://mapaskladek.aspone.cz/List , you will be redirected to the index page and the map will be centered on the marker of

How to get href value on server side when anchor tag is clicked

May Eswaramoorthi I have a table with anchor tags in each row, when the anchor link is clicked, I use jquery to get the href value and bind the href value in a hidden field, at the same time I want to pass the hidden field value on the server side. How to pass

How to find href path of anchor tag using jquery?

Vignesh Pichamani How can i get and check if href path contains image path or other link using jquery. E.g: <a href="image.png"><img src="image.png"/></a> In the above example, the anchor text contains the image src, then only the jquery function can find the

How to get value href value instead of anchor tag?

John Mayer I've just started using HtmlAgilityPack and I'm running into a problem. My code is: var urls = html.DocumentNode.SelectNodes("//a[contains(@href, 'watch?v=')"); Currently, I am returning an array of anchor tags. The thing is, I want to return an ar

How to replace some text in href of anchor tag in jQuery

Ram Singh I have few url anchors like "http%3a/test.dev.test.com/posts/test test" and I want to replace it with " http://test.dev.test.com/posts/test Test" on the window loading function, I have tried the following code but it does not update the url of the an