0

i'm having the following php code:

    $html = '<p>[tag]</p>';
    $test = "<a href='#'><div class='test'>button</div></a>";
    $html = str_replace("[tag]", $test, $html);

when using echo htmlentities($html) i'm getting the expected result:

<p><a href='#'><div class='test'>button</div></a></p> 

but when echoing the $html, firefox renders it like this:

<p>
<a href="#"></a>
</p>
<div class="test">
<p></p>

which is very strange .. any ideas what's wrong?

thanks

EDIT: i found out that it's only wrong when checking with firebug. when displaying the browser's source, it show's up as expected. nevertheless, to the browser it seems to be invalid html markup ..

2
  • how did you check firefox renders it? did you use any tool (e.g. firebug etc) or just saw the plain html source. Commented Jun 29, 2013 at 19:37
  • you cannot add ul, ol, div, etc.. tags inside a p tag, use span instead
    – bystwn22
    Commented Jun 29, 2013 at 19:48

3 Answers 3

1

I believe it's because you can't have block level elements inside inline elements. Similar to that you can't put a <p> tag inside a <span> tag.

HTML 4.01 specifies that <a> elements may only contain inline elements. A <div> is a block element, so it may not appear inside an <a>.

2
  • How does browsers' rendering logic relate to PHP's output? Commented Jun 29, 2013 at 19:36
  • @shiplu.mokadd.im Firefox is a browser that does what it feels like.
    – silkfire
    Commented Jun 29, 2013 at 19:37
0

maybe you're showing "selected source code". In firefox, the selected source code is modified version with the standart usage rules. You can show retrieved DOM by using show page source.

0

Please do me a favor: replace the div element with span and it will work.
Reasons:

  1. Div Element Contain Line Breaks so a div inside a link seems firefox rejecting.
  2. Plugins....Uninstall Plugins.

Do That And You are good to go :D

1
  • Reasonable solution, questionable justifications. Please try to format the answers properly (SO has nice markup tools), avoid unneeded wording and bring reference if required to justify claims. Welcome aboard :)
    – MasterAM
    Commented Jun 29, 2013 at 20:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.