simpler html/JS --> php conversion

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • themadjester
    New Member
    • Mar 2008
    • 37

    simpler html/JS --> php conversion

    Hello,

    I am fairly new to web and am making a page I am happy with, however I am wonding if my method is flawed. Currently what I do is load everything into a monster sized sting in my php script like:
    Code:
    function printContent(){
    $string = "\n<div id='" . $someID . "\n'>" . $content . "\n</div>\n";
    $string .= "more stuff here...";
    echo $string;
    }
    Do people actually do this? if yes, it takes a long time, and is prone to error, is there a tool that can help me do this?^.- It seems to me that this method is a bit of a hack.

    my eventual intent is to load all these strings into a SQL database and query them out (entire divs, and divs inside of divs!), and am wondering if this approach also seems appropriate as well.

    Also, my tactic with css for my divs has been to use php to echo a style section into the code like so: "<style>" . $styles . "</style>" >.> which also seems kinda flawed.

    Thanks!
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    Originally posted by themadjester
    Do people actually do this?
    I doubt that but you never know. a better approach would be making a template and using placeholders to substitute the variable parts (str_replace()) .

    Originally posted by themadjester
    my eventual intent is to load all these strings into a SQL database and query them out (entire divs, and divs inside of divs!), and am wondering if this approach also seems appropriate as well.
    not to me, IMO databases should be used to hold data, not the data structure mark-up. (because that is the same for all data)

    Originally posted by themadjester
    Also, my tactic with css for my divs has been to use php to echo a style section into the code like so: "<style>" . $styles . "</style>" >.> which also seems kinda flawed.
    you can use external stylesheets, way easier to handle and maintain.

    Comment

    • dlite922
      Recognized Expert Top Contributor
      • Dec 2007
      • 1586

      #3
      Look into Smarty templating system. Should clear everything up for you.

      Data should never be mixed in with presentation code (except during presentation, duh!)

      :) Good luck,



      Dan

      Comment

      Working...