Hi guys, I've tried putting the following code inside a div, but halfway through it switches from php back to html, displaying the second half of the code as text in the div: [COLOR=#000000][COLOR=#0000BB]<?php $username [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#DD0000]"karasulas"[/COLOR][COLOR=#007700]; [/COLOR][COLOR=#0000BB]$feed [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#DD0000]"hxxp: search. twitter. com/search. atom?q=from:" [/COLOR][COLOR=#007700]. [/COLOR][COLOR=#0000BB]$username [/COLOR][COLOR=#007700]. [/COLOR][COLOR=#DD0000]"&rpp=1"[/COLOR][COLOR=#007700]; function [/COLOR][COLOR=#0000BB]parse_feed[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$feed[/COLOR][COLOR=#007700]) { [/COLOR][COLOR=#0000BB]$stepOne [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]explode[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"<content type=\"html\">"[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]$feed[/COLOR][COLOR=#007700]); [/COLOR][COLOR=#0000BB]$stepTwo [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]explode[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"</content>"[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]$stepOne[/COLOR][COLOR=#007700][[/COLOR][COLOR=#0000BB]1[/COLOR][COLOR=#007700]]); [/COLOR][COLOR=#0000BB]$tweet [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]$stepTwo[/COLOR][COLOR=#007700][[/COLOR][COLOR=#0000BB]0[/COLOR][COLOR=#007700]]; [/COLOR][COLOR=#0000BB]$tweet [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]htmlspecialchars_decode[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$tweet[/COLOR][COLOR=#007700],[/COLOR][COLOR=#0000BB]ENT_QUOTES[/COLOR][COLOR=#007700]); return [/COLOR][COLOR=#0000BB]$tweet[/COLOR][COLOR=#007700]; } [/COLOR][COLOR=#0000BB]$twitterFeed [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]file_get_contents[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$feed[/COLOR][COLOR=#007700]); echo([/COLOR][COLOR=#DD0000]'"'[/COLOR][COLOR=#007700]. [/COLOR][COLOR=#0000BB]parse_feed[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$twitterFeed[/COLOR][COLOR=#007700]). [/COLOR][COLOR=#DD0000]'"'[/COLOR][COLOR=#007700]); [/COLOR][COLOR=#0000BB]?>[/COLOR][/COLOR] Code (markup): For some reason after ("<content type=\"html\"> it switches to html, displaying as text from ", $feed); onward. Any ideas? Thanks, Alex
@JohnnySchultz (and anyone else that didn't read my mind!): I am wanting that whole block to be in php, from <?php at the top to ?> at the bottom, but something is triggering it to go out of php straight after ("<content type=\"html\"> and display the rest of the block as text in the div. @jazzcho: Correct me if I'm wrong (and I very well may be), but since it's switching out of php on the 5th line, $twitterFeed isn't even being set up. If I'm wrong I'll learn how to do this print_r/var_dump thing and post it. Cheers!
As far as I can see this code looks ok. Please delete and then reenter your doublequote characters on the line which is causing the problem and see if this helps. If this does not help, then put the parameters passed to explode() in single quotes and remove backslashes around the word html.
Are you after the raw html on screen rather than the rendered? If so echo your content with htmlentities();
Where are you placing the HTLM elements? maybe you have commas in it that could be interfering with php's execution of your code. I'd be inclinded to place HTML outside the php marks like so: [COLOR="#0000FF"]<style>[/COLOR] div#your_css_hook { background: none repeat scroll 0 0 #DBE4FF; float: left; padding: 5px; width: 76%; height: 4%; text-align: left; } [COLOR="#0000FF"]</style>[/COLOR] [COLOR="#0000FF"]<div id="your_css_hook">[/COLOR] [COLOR="#FF0000"]<?php[/COLOR] //$username = "karasulas"; $username = "google"; $feed = "hxxp ://search.twitter.com/search.atom?q=from:" . $username . "&rpp=1"; function parse_feed($feed) { $stepOne = explode("<content type=\"html\">", $feed); $stepTwo = explode("</content>", $stepOne[1]); $tweet = $stepTwo[0]; $tweet = htmlspecialchars_decode($tweet,ENT_QUOTES); return $tweet; } $twitterFeed = file_get_contents($feed); echo('"'. parse_feed($twitterFeed). '"'); [COLOR="#FF0000"]?>[/COLOR] [COLOR="#0000FF"]</div>[/COLOR] Code (markup): ROOFIS
Could you post a legitimate feed URL? Yours returns "failed to open stream" (meaning that the URL [yes, corrected] is bad).