Fuxi
Fuxi

Reputation: 7599

php unexpected output using str_replace

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 ..

Upvotes: 0

Views: 111

Answers (3)

Jamil Hneini
Jamil Hneini

Reputation: 1

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

Upvotes: 0

silkfire
silkfire

Reputation: 25945

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>.

Upvotes: 1

Ahmet Mehmet
Ahmet Mehmet

Reputation: 288

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.

Upvotes: 0

Related Questions