Problem with HTML in PHP

Discussion in 'PHP' started by genji, Sep 13, 2009.

  1. #1
    Hey guys..
    At this moment I have the following PHP code:

    
    $content = "
    <div class=\"postlinks\">
    <ul>
    	<li>
    		<span id=\"trailr\"><a href=\"#trailer$r\" rel=\"facebox\"><img alt=\"trailer\" src=\"http://imgur.com/pQwmw.png\" width=\"50\" height=\"50\"/></a></span></li>
    		<div id=\"trailer$r\" style=\"display:none;\">
    
    Code (markup):
    When I do e.g. echo $content, it strips ALL of the id, rel etc.. it only leaves blank <span> and <div> tags..


    Can anyone help me out how to display everything without getting stripped?
     
    genji, Sep 13, 2009 IP
  2. killaklown

    killaklown Well-Known Member

    Messages:
    2,666
    Likes Received:
    87
    Best Answers:
    0
    Trophy Points:
    165
    #2
    instead of using \" just use '


    HTML inside a php variable = horrible coding.
     
    killaklown, Sep 13, 2009 IP
  3. genji

    genji Peon

    Messages:
    61
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    ah.. I'm pretty new at PHP heh, what do you recommend me doing instead?

    Because I need the $content variable to hold some html data..
     
    genji, Sep 13, 2009 IP
  4. genji

    genji Peon

    Messages:
    61
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    bump..bump..bump..
     
    genji, Sep 13, 2009 IP
  5. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #5
    $content = "
    <div class=\"postlinks\">
    <ul>
    	<li>
    		<span id=\"trailr\"><a href=\"#trailer$r\" rel=\"facebox\"><img alt=\"trailer\" src=\"http://imgur.com/pQwmw.png\" width=\"50\" height=\"50\"/></a></span></li>
    		<div id=\"trailer$r\" style=\"display:none;\">
    PHP:
    Only thing wrong with this is lack of a closing "; .

    option 1:
    Use ' as the delimiter to avoid escaping ".
    $content = '
    <div class="postlinks">
    <ul>
    	<li>
    		<span id="trailr"><a href="#trailer' . $r . '" rel="facebox"><img alt="trailer" src="http://imgur.com/pQwmw.png" width="50" height="50"/></a></span></li>
    		<div id="trailer'. $r .'" style="display:none;">';
    
    PHP:

    option 2:
    drop the variable and use HTML. ( can use the shorthand tag <?=$r ?> )
    
    
    <div class="postlinks">
    <ul>
    	<li>
    		<span id="trailr"><a href="#trailer<?php echo  $r ;?>" rel="facebox"><img alt="trailer" src="http://imgur.com/pQwmw.png" width="50" height="50"/></a></span></li>
    		<div id="trailer<?php echo  $r ;?>" style="display:none;">
    
    
    PHP:
     
    shallowink, Sep 13, 2009 IP
  6. genji

    genji Peon

    Messages:
    61
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks allot for trying to help me out so far guys..



    Sorry for sounding like a noob but could you please elaborate?
    I need the html to be stored in a variable because I'm trying to make a script to remotely publish wordpress posts. And the template I am trying to use for the layout of the posts, needs to be stored in a variable.


    When I submit the variable, the html is still getting stripped down.. the <script> and the rel and span id's are being taken away.. ugh
     
    genji, Sep 13, 2009 IP
  7. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #7
    go with option 1 or your original code if it has to be a variable. option 2 works better for direct output.
     
    shallowink, Sep 13, 2009 IP
  8. matthewrobertbell

    matthewrobertbell Peon

    Messages:
    781
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #8
    $var = '<tag>'.$r.'</tag>';

    You know about XML-RPC for remote publishing, right?
     
    matthewrobertbell, Sep 13, 2009 IP
  9. genji

    genji Peon

    Messages:
    61
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Yeah man, the post and everything works. But when the post is published, it is stripped of its <script> tags and the rel etc :(

    Do any of you have MSN so we can communicate easier?
     
    genji, Sep 13, 2009 IP
  10. genji

    genji Peon

    Messages:
    61
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    I don't understand option 2.. :/
     
    genji, Sep 13, 2009 IP
  11. matthewrobertbell

    matthewrobertbell Peon

    Messages:
    781
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #11
    option 2 is for sending to browser, which you dont want.

    the server probably doesnt allow javascript etc, so is stripping tags it doesnt like. Download wordpress and look at the source to see what it strips by default.
     
    matthewrobertbell, Sep 13, 2009 IP
  12. genji

    genji Peon

    Messages:
    61
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    It does allow javascript. Also, it only displays the first <div id="postlinks"> but after that it strips and id or class tags that I have..

    I'm gonna see if i can find what wordpress is stripping and how to bypass it.
     
    genji, Sep 13, 2009 IP
  13. matthewrobertbell

    matthewrobertbell Peon

    Messages:
    781
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #13
    SHouldn't that html be part of a template, not the post? the post just consisting of <p>,<img> etc
     
    matthewrobertbell, Sep 13, 2009 IP
  14. genji

    genji Peon

    Messages:
    61
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Nope, because what I'm trying to do is make a form to just fill in certain fields instead of pasting the entire template i made, then looking into the code to paste specific links etc. that wastes allot of time.

    The form already works for remote posting, it's just that i can't seem to get around this stripping of tags
     
    genji, Sep 13, 2009 IP
  15. genji

    genji Peon

    Messages:
    61
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15
    bump! i really need help with this guys
     
    genji, Sep 17, 2009 IP
  16. matthewrobertbell

    matthewrobertbell Peon

    Messages:
    781
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #16
    it's probably a limitation of wordpress, experiment with your own install.
     
    matthewrobertbell, Sep 17, 2009 IP
  17. Christian Little

    Christian Little Peon

    Messages:
    1,753
    Likes Received:
    80
    Best Answers:
    0
    Trophy Points:
    0
    #17
    
    $content = "
    <div class=\"postlinks\">
    <ul>
    	<li>
    		<span id=\"trailr\"><a href=\"#trailer$r\" rel=\"facebox\"><img alt=\"trailer\" src=\"http://imgur.com/pQwmw.png\" width=\"50\" height=\"50\"/></a></span></li>
    		<div id=\"trailer$r\" style=\"display:none;\">[COLOR="Red"][B]";[/B][/COLOR]
    
    Code (markup):
    See the part in red. You forgot to close your string declaration.
     
    Christian Little, Sep 18, 2009 IP
  18. genji

    genji Peon

    Messages:
    61
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #18
    I only did that in the code i pasted. i know about that :/
     
    genji, Sep 18, 2009 IP