mattjones Posted November 25, 2008 Share Posted November 25, 2008 Hello everyone i am new here and quite new to PHP. I have a couple of questions and would be grateful if anyone could answer them. I am creating a niche directory site and i have made php create a new page from some form data using the following. file_get_contents str_replace fwrite and a few things. I have used place holders to create these pages and also to create a link to these new pages. On part where a new link is created i make the script write a new placeholder ready for the next new entry. Hope you are still with me!! :-\ anyway my questions are.. 1. Is using placeholders the best way to go about this or is there another way? 2. What is the best way to hide these placeholders on a page that people will be viewing as they are unsightly. I was thinking of making the text the same colour as the background but they will still be visible if highlighted and i have also heard i would be penalised by google for hiding text and i want my page to rank well and not annoy the search engines. Thank you very much for any help in advance!! Matt Quote Link to comment https://forums.phpfreaks.com/topic/134214-placeholders-and-automated-pages/ Share on other sites More sharing options...
trq Posted November 25, 2008 Share Posted November 25, 2008 One of php's main uses is for creating dynamic content. The idea of actually writting to a file (excepting maybe as a stoarge solution) kinda goes against this entire concept. Do you think when you post a new thread on this forum php creates a new file especially to hold your thread? Then with each reply a placeholder is replaced with a users posted data? This is not the case. Quote Link to comment https://forums.phpfreaks.com/topic/134214-placeholders-and-automated-pages/#findComment-698938 Share on other sites More sharing options...
mattjones Posted November 25, 2008 Author Share Posted November 25, 2008 ok thanks for the tip. Where should i look to find out what commmands to use to do it the right way then? or could you give me a hint. I will work out how to do it myself if i am pointed in the right direction. thanks matt Quote Link to comment https://forums.phpfreaks.com/topic/134214-placeholders-and-automated-pages/#findComment-699056 Share on other sites More sharing options...
trq Posted November 26, 2008 Share Posted November 26, 2008 There is no simple functions that are going to magically do this for you. Its an entire concept and the main one which php centres around. For instance (and this is a very simplified example), say you wanted every user of your site to get there own page which simply displays there name and email address. Using your method, you would make each individual file (you may as well be using html). Even if your using php to generate these files its still not exactly dynamic. Using php to generate the impression of each user having there own file is however. The script might look something like: <?php if (isset($_GET['user'])) { include 'db.connect.php'; $user = mysql_real_escape_string($_GET['user']); $sql = "SELECT email FROM users WHERE uname = '$user' LIMIT 1"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); echo "<p>$user - {$row['email']}</p>"; } } } ?> Thats it! No more saving and manipulating files all over the server. Given that you store your usernames and email addresses within a database, this is the only code (obviously its a simplified example) you would need to create the impression of each user having there own page. Quote Link to comment https://forums.phpfreaks.com/topic/134214-placeholders-and-automated-pages/#findComment-699126 Share on other sites More sharing options...
DeanWhitehouse Posted November 26, 2008 Share Posted November 26, 2008 Having a look at some more code examples might help you http://djw-webdesign.awardspace.com/snippet.php?cat=1 Quote Link to comment https://forums.phpfreaks.com/topic/134214-placeholders-and-automated-pages/#findComment-699131 Share on other sites More sharing options...
mattjones Posted November 26, 2008 Author Share Posted November 26, 2008 ok that is very useful thank you very much. I will use that for my users pages. I still have a HTML page that is already created where i wish the links to be added in certain places. I need this page to stay as HTML so it can be indexed by the search engines as this is the way i will get new members. Is using placeholders the best way to do this. Thanks again you are being very helpful. Matt Quote Link to comment https://forums.phpfreaks.com/topic/134214-placeholders-and-automated-pages/#findComment-699393 Share on other sites More sharing options...
trq Posted November 26, 2008 Share Posted November 26, 2008 I need this page to stay as HTML so it can be indexed by the search engines PHP pages are indexed by search engines. Besides that, its a simple process to make a php page appear to be served with the html extension (using mod_rewrite). I still think your missing a big part of what php is and can do. Quote Link to comment https://forums.phpfreaks.com/topic/134214-placeholders-and-automated-pages/#findComment-699407 Share on other sites More sharing options...
mattjones Posted November 26, 2008 Author Share Posted November 26, 2008 ok i guess i better get reading some posts and a bit more about PHP then. I am new to PHP so I think you are right i dont get the full extent of its powers yet and am still learning. Thanks for the help matt Quote Link to comment https://forums.phpfreaks.com/topic/134214-placeholders-and-automated-pages/#findComment-699703 Share on other sites More sharing options...
trq Posted November 26, 2008 Share Posted November 26, 2008 Lets make a simple example. Take this html file with your placeholder in it. links.html <html> <head> <title>links</title> </head> <body> <p> <!-- {LINKS_PLACEHOLDER} --> </p> </body> </html> Now, at the moment you might have a script something like.... generate_links_html.php <?php $links = array( '<a href="foo.com">foo.com</a>', '<a href="bar.com">bar.com</a>', '<a href="bob.com">bob.com</a>' ); $file = file_get_contents('links.html'); $file = str_replace('<!-- {LINKS_PLACEHOLDER} -->', implode("<br />\n", $links) . "<!-- {LINKS_PLACEHOLDER} -->\n", $file); file_put_contents('file.html', $file); ?> While this would work, its messy and not very dynamic. Using a database to store your links you could simply have one script... links.php <html> <head> <title>links</title> </head> <body> <p> <?php include 'dbconnect.php'; $sql = "SELECT link, linkname FROM links" if ($result = mysql_query($sql)) { if ($mysql_num_rows($result)) { while ($row = mysql_fetch_assoc($result)) { echo ' <a href="' . $row['link'] . '">' . $row['linkname'] . "</a>\n"; } } } ?> </p> </body> </html> Which would achieve the same goal. It might look like more work but the major benifit is that you would then simply have another script which would allow you to add new links via a form and they would automatically appear. Quote Link to comment https://forums.phpfreaks.com/topic/134214-placeholders-and-automated-pages/#findComment-699769 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.