Jump to content

str_replace and HTML...


techiefreak05

Recommended Posts

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?

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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;
?>

 

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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...

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.