In my recent post: Google AdSense Now Logs Into Your Sites I mentioned that displaying a quick preview of your content might be useful in some scenarios.在我最近帖子: 现在谷歌的AdSense登录到您的网站,我提到,展示了快速预览您的内容可能是有用的一些情景。 Particularly if you want to charge subscription fees for full content. I’ll illustrated with an example so you can get an idea of where to start in accomplishing this with your own sites.尤其是如果您想收取订阅费的全部内容。表明我会用一个例子,让您能够了解哪里开始完成这一与您自己的网站。 The key component in making this work is the substr ($content,0,300) function.的重要组成部分,使这项工作是substr ( $内容, 0300 )的功能。 You specify the length of content by declaring a start (0) and the end (300).您可以指定长度的内容,宣布启动( 0 )和结束( 300 ) 。 You can then output a shortened version of $content and store it in a separate variable.然后,您就可以输出缩短为内容并将其存储在一个单独的变量。 Great to use as a “preview” for your content.大使用作为一个“预览”为您的内容。 Note: the number refers to the numbers of characters in the provided string, not words.注:数量指的是数字中的字符所提供的字符串,而不是言辞。

What you need to do is figure out the existing variables you’re outputting on each content page (likely found within your template).你需要做的是找出现有的变数你输出的每个内容页(可能内发现您的范本) 。 This part goes beyond the scope of this article.这部分超出了本文的范围。 All sites are set up with slightly differently variables and even grab content from different sources…this is not an exact science.所有网站都设立了略有不同的变量,甚至抓斗的内容从不同来源...这不是一个精确的科学。

I will assume your data is coming from a mySQL database and $id is a number that refers to a row of content in your database.我将承担您的数据是来自MySQL数据库美元和编号是一个号码,是指连续的内容在您的数据库。 This first snippet shows a row being queried in preparation for it to be cut down into a preview.这是第一个片段显示,连续受到质疑,准备将其降低到一个预览。

  1. $result = mysql_query ( "SELECT id,content FROM table WHERE id={$id}" , $db ) ;
  2. $row = mysql_fetch_row ( $result ) ;
  3. echo $row [ 0 ] ; //The value of id
  4. echo $row [ 1 ] ; //The value of content
  5. $content = $row [ 1 ] ; //Store it into something we can identify easily

This is even easier when you already have your content in a string.这是更容易当你已经有了您的内容字符串。 In that case you wouldn’t have to run a query on it again.在这种情况下你就不会运行查询一遍。 There are also applications in which you would want to have this preview show before you content.也有应用在您希望有此之前预览显示您的内容。 In that case you would only need to integrate something like this into your templates (and yes there is more then one way to do this):在这种情况下你只需要把这样的事情到您的模板(和肯定有更多然后一个途径做到这一点) :

  1. $previewcontent = substr ( $content , 0 , 300 ) ;
  2. if ( isset ( $go ) ) { //If set then they have seen the preview already
  3. echo $content ; //Display your usual content
  4. } else { //First time viewing this page
  5. echo "Article preview:<br><br>" . $previewcontent ;
  6. echo "See this entire post<a href= \" showcontent.php?id=" . $id . "&go=yes \" >here</a>" ;
  7. //Or you could add something like this (instead of lines 6 & 7) for paid/subscription content
  8. if ( isset ( $user ) ) { //If a user is logged in…
  9. echo "Go ahead and <a href= \" showcontent.php?id=" . $id . "&go=yes \" >view</a>" ;
  10. } else { //$user is not set - insert login/signup link/form below
  11. echo "To view this solution please click <a href= \" yoursignupscript.php \" >here</a> to purchase access." ;
  12. }

In my alternate configuration where visitors need to purchase access you should also change your first if statement to check if a user is logged in by doing:在我的候补配置,游客需要购买机会,你也应该改变你的第一个if语句来检查,如果用户登录在做:
if(isset($go) && isset($user)) 如果( isset ( $去) & & isset ( $用户) )

There’s some security and usability you need to consider when implementing this which I didn’t get into.这里也有一些安全和可用性则需要考虑何时执行本,我没有进入。 As shown above isset () is another very handy function in php as it allows you to set triggers in conjunction with if statements.如上所示isset ( )是另一个非常有用的功能在PHP ,因为它让您可以设定触发与if语句。 This can make a webpage very dynamic.这可以使一个网页非常活跃。

If you’re not that far yet with a coding language, I hope this at least gives you some ideas of what you can do. For additional help check out php.net: http://us3.php.net/substr .如果你不那么远尚未与编码语言,我希望这至少给你一些想法什么可以做。如需帮助检查php.net : http://us3.php.net/substr Just getting started with php/mySQL?: Increase Earning Potential With These PHP/mySQL Tutorials刚开始用PHP / MySQL的? 增加收入潜力随着这些PHP / MySQL的教程



Leave A Comment:发表评论:

Comments RSS Feed 评论RSS馈送

8 - 3 = 8至3月=

Custom Theme by Rob Malon | Content & Design © 2008 - Rob Malon [dot] Com. 自订主题罗布丙二|内容与设计© 2008 -罗布丙二[斑点]通信。 "));
"));