1

In my website I have a section where I generate HTML from a twitter feed. Here is the php code that wraps the section in HTML:

    <p class="columns">
    <?
    require ("twitter-feed.php");
    echo generatetwitter();
    ?>
    </p>

the generatetwitter(); method returns this as a string:

    <li class="twitter">&#x201c;@<a class=" " href="http://twitter.com/lecrae">lecrae</a>: If people throw stones at you, pick em up and build something. <a href="http://search.twitter.com/search?q=%23stayfocused" title="#stayfocused" class=" ">#stayfocused</a>&#x201d;</li>


When the page generates it shows the code properly in the "View Source" option of Chrome and Firefox, but when I do "inspect element" it shows this

    <p class="columns"></p>
    <li class="twitter">...</li>
    <p></p>

So the class CSS isn't getting applied to the twitter feed. I need the twitter feed to be in the p tags with the class defined.

Some points:

  • generatetwitter() returns the HTML in a string
  • I've tried having twitter-feed.php (the generatetwitter() method) echoing out the HTML directly, but it makes no difference. I've had the same results every time.
  • when the generatetwitter() method is overridden to return only a normal string "eg return "test";" it works normally.
  • It seems that this doesn't work if the generatetwitter() method returns anything but regular text (excluding HTML).
tshepang
  • 12,111
  • 21
  • 91
  • 136
blockloop
  • 5,565
  • 5
  • 30
  • 31
  • 1
    Probably because your HTML is malformed and the browser is trying to correct it, where is your
      or
      starting tag for your
    1. element? Also, what doctype are you using?
    – Scuzzy Apr 12 '12 at 01:23
  • Thanks for catching that, but it didn't resolve the problem. – blockloop Apr 12 '12 at 01:26
  • try using DIV or SPAN instead, there are rules as to what elements can be nested inside of Paragraph tags, I believe the rule is not block level elements inside of a

    – Scuzzy Apr 12 '12 at 01:28
  • THANK YOU!! I changed it to and it worked. I've been working on this all day... – blockloop Apr 12 '12 at 01:31
  • Neat, please accept my reply as the answer to your question, I also found a similar case for you to read :) – Scuzzy Apr 12 '12 at 01:33

1 Answers1

1

Certain block level tags will close opened paragraph tags when nested, try using DIV or SPAN instead of the P tag as per my earlier comments.

Nesting block level elements inside the <p> tag... right or wrong?

Community
  • 1
  • 1
Scuzzy
  • 12,186
  • 1
  • 46
  • 46