PHP switching back to HTML and I don't know why ...

Discussion in 'PHP' started by karasulas, Oct 3, 2011.

  1. #1
    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]'&quot;'[/COLOR][COLOR=#007700]. [/COLOR][COLOR=#0000BB]parse_feed[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$twitterFeed[/COLOR][COLOR=#007700]). [/COLOR][COLOR=#DD0000]'&quot;'[/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
     
    karasulas, Oct 3, 2011 IP
  2. JohnnySchultz

    JohnnySchultz Peon

    Messages:
    277
    Likes Received:
    4
    Best Answers:
    7
    Trophy Points:
    0
    #2
    what are you trying to achieve? when you echo something in PHP that will be in HTML..
     
    JohnnySchultz, Oct 4, 2011 IP
  3. jazzcho

    jazzcho Peon

    Messages:
    326
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Do a print_r/var_dump on $twitterFeed and post it here.
     
    jazzcho, Oct 4, 2011 IP
  4. karasulas

    karasulas Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    @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!
     
    karasulas, Oct 4, 2011 IP
  5. HuggyEssex

    HuggyEssex Member

    Messages:
    297
    Likes Received:
    4
    Best Answers:
    2
    Trophy Points:
    45
    #5
    Make sure your error reporting is set to all, might help.
     
    HuggyEssex, Oct 4, 2011 IP
  6. kwiatek

    kwiatek Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    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.
     
    Last edited: Oct 6, 2011
    kwiatek, Oct 6, 2011 IP
  7. mfscripts

    mfscripts Banned

    Messages:
    319
    Likes Received:
    4
    Best Answers:
    8
    Trophy Points:
    90
    Digital Goods:
    3
    #7
    Are you after the raw html on screen rather than the rendered? If so echo your content with htmlentities();
     
    mfscripts, Oct 7, 2011 IP
  8. ROOFIS

    ROOFIS Well-Known Member

    Messages:
    1,234
    Likes Received:
    30
    Best Answers:
    5
    Trophy Points:
    120
    #8
    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('&quot;'. parse_feed($twitterFeed). '&quot;');
    [COLOR="#FF0000"]?>[/COLOR]
    [COLOR="#0000FF"]</div>[/COLOR]
    Code (markup):






    ROOFIS
     
    ROOFIS, Oct 10, 2011 IP
  9. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #9
    Could you post a legitimate feed URL? Yours returns "failed to open stream" (meaning that the URL [yes, corrected] is bad).
     
    Rukbat, Oct 14, 2011 IP