techiefreak05 Posted February 15, 2010 Share Posted February 15, 2010 I decided to see if I could make a theme system kind of like Tumblr, in which you are able to completely write your own HTML form top to bottom, using special strings to indicate the site functions, but it's only partially working. $theme_code is the entire HTML code.. <?php $theme_parssed = str_replace("{follow}",ProfileFollowLink($uname),$theme_code); ?> That adds the "follow" link where it's supposed to go in the template... but instead of being where it's supposed to, it's moved to before the <html> tag... any ideas why? Quote Link to comment https://forums.phpfreaks.com/topic/192132-str_replace-and-html/ Share on other sites More sharing options...
jl5501 Posted February 15, 2010 Share Posted February 15, 2010 you need to make sure that the resultant string is echoed within the structure of your document, not before it. You can do all the replacement first, but echo the results within the structure. Post some of your code and you will get more specific help Quote Link to comment https://forums.phpfreaks.com/topic/192132-str_replace-and-html/#findComment-1012546 Share on other sites More sharing options...
techiefreak05 Posted February 15, 2010 Author Share Posted February 15, 2010 Here's all the replacements. The only one that works is the "username', because it's just text. The rest have HTML elements. <?php $theme_parssed = str_replace("{follow}",ProfileFollowLink($uname),$theme_code); $theme_parssed = str_replace("{searchbox}",ProfileSearchBox(),$theme_parssed); $theme_parssed = str_replace("{posts}",ProfilePosts($uname),$theme_parssed); $theme_parssed = str_replace("{username}",$uname,$theme_parssed); echo $theme_parssed; ?> Quote Link to comment https://forums.phpfreaks.com/topic/192132-str_replace-and-html/#findComment-1012551 Share on other sites More sharing options...
jl5501 Posted February 15, 2010 Share Posted February 15, 2010 ok this is my point, you are echoing the result immediately. You are not echoing it in the structure of your html page If you can post your html and indicate where the theme_parsed variable should go, then I can help further Quote Link to comment https://forums.phpfreaks.com/topic/192132-str_replace-and-html/#findComment-1012553 Share on other sites More sharing options...
techiefreak05 Posted February 15, 2010 Author Share Posted February 15, 2010 Here's the HTML template... <html> <head> <title>{=username}'s Profile</title> <style> ... </style> </head> <body> <div id='container'> <table cellspacing='2' cellpadding='2' align='center' style='margin:0 auto;' width='100%'> <tr> <td valign='center'> <img src='/logo.png' style='padding:10px;align:left;'> </td> <td valign='center'> <a class='nav' href='/Home'>home</a> <a class='nav' href='/user/{=username}'>profile</a> <a class='nav' href='/do/logout'>logout</a> <a class='nav' href='/notifications'>notifications(0)</a>{=searchbox} </td> </tr> </table> <div id='top'> </div> <div id='box'> <div id='padding'> <h2><a href='/user/{=username}'>{=username}</a>'s Posts</h2> {=follow} <br> {=posts} </div> </div> <div id="bottom"><center>© Copyright</center></div> </div> </body> </html> Note: I changed the tags to have a "=" before the name. Quote Link to comment https://forums.phpfreaks.com/topic/192132-str_replace-and-html/#findComment-1012570 Share on other sites More sharing options...
Wolphie Posted February 15, 2010 Share Posted February 15, 2010 {username} is not the same as {=username} Quote Link to comment https://forums.phpfreaks.com/topic/192132-str_replace-and-html/#findComment-1012576 Share on other sites More sharing options...
techiefreak05 Posted February 15, 2010 Author Share Posted February 15, 2010 I know, didnt you see the bottom of my last post? I know I changed the tags. I said, "Note: I changed the tags to have a "=" before the name." it all WORKS.. just the follow link, the search box, and the posts all get pushed to above the <HTML> tag. Quote Link to comment https://forums.phpfreaks.com/topic/192132-str_replace-and-html/#findComment-1012577 Share on other sites More sharing options...
Wolphie Posted February 15, 2010 Share Posted February 15, 2010 Sorry, no I didn't see that. I'm assuming, $theme_parssed contained all of the HTML to begin with? Quote Link to comment https://forums.phpfreaks.com/topic/192132-str_replace-and-html/#findComment-1012580 Share on other sites More sharing options...
techiefreak05 Posted February 15, 2010 Author Share Posted February 15, 2010 No, $theme_code contains all the HTML before the tags are replaced. Quote Link to comment https://forums.phpfreaks.com/topic/192132-str_replace-and-html/#findComment-1012581 Share on other sites More sharing options...
jl5501 Posted February 15, 2010 Share Posted February 15, 2010 ok so somwhere in that html is a {follow} or {=follow} indicating where the follow code is to go Quote Link to comment https://forums.phpfreaks.com/topic/192132-str_replace-and-html/#findComment-1012584 Share on other sites More sharing options...
techiefreak05 Posted February 15, 2010 Author Share Posted February 15, 2010 If you look at the HTML code I posted above, you'll see a {=follow] in there. That HTML is an example of what $theme_code holds. So, yes. Quote Link to comment https://forums.phpfreaks.com/topic/192132-str_replace-and-html/#findComment-1012585 Share on other sites More sharing options...
jl5501 Posted February 15, 2010 Share Posted February 15, 2010 ok I see it now, so the {=follow} looks nicely placed in a div. So no obvious reason why it should not appear there in the replaced result. So the next stage is to look at view source on the final generated html. and then we can see what it happening. Browsing with firefox and using firebug may also be useful at this stage Quote Link to comment https://forums.phpfreaks.com/topic/192132-str_replace-and-html/#findComment-1012588 Share on other sites More sharing options...
Wolphie Posted February 15, 2010 Share Posted February 15, 2010 Where is the HTML coming from? Are you opening a different file and reading the contents or is it hard coded as a string in the PHP script itself? or perhaps somewhere in a database? Quote Link to comment https://forums.phpfreaks.com/topic/192132-str_replace-and-html/#findComment-1012589 Share on other sites More sharing options...
techiefreak05 Posted February 15, 2010 Author Share Posted February 15, 2010 Database. The templates are located in the database, and when the profile is loaded, the database looks for template code, gets it, and parses it. Quote Link to comment https://forums.phpfreaks.com/topic/192132-str_replace-and-html/#findComment-1012592 Share on other sites More sharing options...
jl5501 Posted February 15, 2010 Share Posted February 15, 2010 yes, as expected, but the only thing we are not seeing yet, is what the final, parsed, html looks like, particularly the follow link Quote Link to comment https://forums.phpfreaks.com/topic/192132-str_replace-and-html/#findComment-1012595 Share on other sites More sharing options...
techiefreak05 Posted February 15, 2010 Author Share Posted February 15, 2010 Here's the parsed HTML. I didnt move anything any place. The follow code is the VERY top of html HTML document....the form is the searchbox... <div id='follow'> <a href="#" OnClick="javascript:UnFollowUser(5);" title='Un-follow User'><img alt='Un-follow User' src='/unfollow.png' border='0'></a> </div> <form action="/Home" method="get"> <table cellpadding="0px" cellspacing="0px" align="right"> <tr> <td style="border-style:solid none solid solid;border-color:#4B7B9F;border-width:1px;"> <input type="text" name="q" style="width:100px; border:0px solid; height:17px; padding:0px 3px; position:relative;"> </td> <td style="border-style:solid;border-color:#4B7B9F;border-width:1px;"> <input name="sDo" type="submit" value="" style="border-style: none; background: url('/searchbutton3.gif') no-repeat; width: 24px; height: 20px;"> </td> </tr> </table> </form> <div id=flow> //posts are here. I removed them before posting. </div><html> <head> <title>staff's Profile</title> //same as the template HTML... Quote Link to comment https://forums.phpfreaks.com/topic/192132-str_replace-and-html/#findComment-1012598 Share on other sites More sharing options...
jl5501 Posted February 15, 2010 Share Posted February 15, 2010 ok so let me get this straight coming out of the database is the template which has this structure <html> . . <div id='padding'> <h2><a href='/user/{=username}'>{=username}</a>'s Posts</h2> {=follow} <br> {=posts} </div> . . . .</html> and the {=follow} placeholder gets converted to <div id='follow'> <a href="#" OnClick="javascript:UnFollowUser(5);" title='Un-follow User'><img alt='Un-follow User' src='/unfollow.png' border='0'></a> </div> and somehow manages to appear outside the <html> Does that sum up the issue you are having Quote Link to comment https://forums.phpfreaks.com/topic/192132-str_replace-and-html/#findComment-1012603 Share on other sites More sharing options...
techiefreak05 Posted February 15, 2010 Author Share Posted February 15, 2010 Exactly. I should note though, it's not ONLY the follow placeholder that gets moved. It's the search box, and the posts. Anything that has HTML. Because the username gets converted just fine. Quote Link to comment https://forums.phpfreaks.com/topic/192132-str_replace-and-html/#findComment-1012604 Share on other sites More sharing options...
jl5501 Posted February 15, 2010 Share Posted February 15, 2010 Yes, I am just concentrating on the {=follow} as an example of one that exhibits this behaviour Quote Link to comment https://forums.phpfreaks.com/topic/192132-str_replace-and-html/#findComment-1012612 Share on other sites More sharing options...
MadTechie Posted February 15, 2010 Share Posted February 15, 2010 Shot in the dark, but check your functions (ie ProfileFollowLink) don't echo value and do return a value! Quote Link to comment https://forums.phpfreaks.com/topic/192132-str_replace-and-html/#findComment-1012616 Share on other sites More sharing options...
jl5501 Posted February 15, 2010 Share Posted February 15, 2010 good point, I think that may be the issue Quote Link to comment https://forums.phpfreaks.com/topic/192132-str_replace-and-html/#findComment-1012622 Share on other sites More sharing options...
techiefreak05 Posted February 15, 2010 Author Share Posted February 15, 2010 Yes.. that is the issue. It now works like a charm. Thanks! Wow, that was quite annoying. Haha Quote Link to comment https://forums.phpfreaks.com/topic/192132-str_replace-and-html/#findComment-1012625 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.