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. В моята нова публикация: Google 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). Това, което трябва да направите е да разбера съществуващите променливи сте outputting съдържанието на всяка страница (вероятно намерени във вашия шаблон). 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 база данни и $ ID е числото, което се отнася до ред на съдържанието във вашите база данни. 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(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, тъй като ви позволява да се задейства, ако във връзка с изявления. 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 Емисия

5 Added To 4 = 5 Добавена до 4 =

Custom Theme by Rob Malon | Content & Design © 2008 - Rob Malon [dot] Com. Специален тема от Роб Malon | Съдържание и дизайн © 2008 - Роб Malon [точка] СОМ. "));
"));