stringreplaceencodinghyperlinkdouble-quotes

link: issue with symbol " (might be an encoding issue)


I have a link generated on my page as

<a href="#" onClick="loadList(5); return false;">5</a>

The problem is that when I click on the link it redirects me to

<a #" onClick="loadList(4); return false;

In Google Chrome when I do inspect, I see that the generated HTML is

<a href="#&quot; onClick=&quot;loadList(5); return false;">5</a>

My issue is that I am using an external class and getting the strings <a href="# and ">5</a> from a different function (as a string), and I have no control over that. The only thing that I can do are string functions such as str_replace(). I tried to find the substring " in the strings I get from the function to no avail.

Can this be an encoding issue?

How do I fix this weird phenomenon?

The page is http://www.belgiumdiamonds.net/en/diamond-collection-test


Solution

  • Given the URL to look at the problem is clear. Inspect element is showing how Chrome has parsed the HTML, not the genuine HTML.

    The pagination comes from this ajaxed page

    http://www.belgiumdiamonds.net/index.php/tools/blocks/diamond_list/list_display

    So look at it's source.

    <a href='#" onClick="loadList(2); return false;' >
    

    Notice the mismatched quotes

    <a href='#" onClick="loadList(2); return false;' >
            ^ ^ here
    

    and

    <a href='#" onClick="loadList(2); return false;' >
                        ^                          ^ here
    

    The reason the links still appear is that you have a seemingly valid pair of quotes, creating this URL: #" onClick="loadList(2); return false; which is clearly wrong.

    Now, if you can't fix this, you need to show us the relevant code from that class and/or how you're calling the function to create the pagination. It could be the execution that's wrong not the class. If it is the class you can either extend it and fix it or stick a band-aid on it with str_replace like you tried, but surely this would work:

     $the_anchor=str_replace("'", '"', $the_anchor);