Note that there are some explanatory texts on larger screens.

plurals
  1. POEcho A Link, Get A Trailing Slash?
    primarykey
    data
    text
    <p>I've discovered that any time I do the following:</p> <pre><code>echo '&lt;a href="http://" title="bla"&gt;huzzah&lt;/a&gt;'; </code></pre> <p>I end up with the following being rendered to the browser:</p> <pre><code>&lt;a href="http:///" title="bla"&gt;huzzah&lt;/a&gt; </code></pre> <p>This is particularly annoying when I link to a file with an extension, as it breaks the link.</p> <p>Any ideas why this is happening and how I can fix it?</p> <p><strong>Update:</strong> For those asking about my exact implementation, here it is. In my troubleshooting I've dumbed it down as much as I could, so please don't mind where I concat plain text to plaintext...</p> <pre><code>function print_it($item) { echo '&lt;div class="listItem clearfix"&gt;'; echo '&lt;div class="info"&gt;'; echo '&lt;span class="title"&gt;'; if(isset($item[6])) { echo '&lt;a href="http://" title=""&gt;' . 'me' . '&lt;/a&gt;'; } echo '&lt;/span&gt;'; echo '&lt;/div&gt;&lt;/div&gt;'; } </code></pre> <p><strong>Update:</strong> In response to Matt Long, I pasted in your line and it rendered the same.</p> <p><strong>Update:</strong> In response to Fire Lancer, I've put back in my original attempt, and will show you both below.</p> <pre><code>echo substr($item[6],13) . '&lt;br&gt;'; echo '&lt;a href="http://' . substr($item[6],13) . '" title="' . $item[0] . '"&gt;' . $item[0] . '&lt;/a&gt;'; &lt;span class="title"&gt;www.edu.gov.on.ca%2Feng%2Ftcu%2Fetlanding.html&lt;br&gt; &lt;a href="http://www.edu.gov.on.ca%2Feng%2Ftcu%2Fetlanding.html" title="Employment Ontario"&gt;Employment Ontario&lt;/a&gt;&lt;/span&gt; </code></pre> <p>The reason for the substr'ing is due to the URL being run through rawurlencode() elsewhere, and linking to http%3A%2F%2F makes the page think it is a local/relative link.</p> <p><strong>Update:</strong> I pasted the above response without really looking at it. So the HTML is correct when viewing source, but the actual page interprets it with another trailing slash after it.</p> <p><strong>Solution:</strong> This was all a result of rawlurlencode(). If I decoded, or skipped the encoding all together, everything worked perfectly. Something about rawurlencode() makes the browser want to stick a trailing slash in there.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload