How to Spin With PHP

How to Spin With PHP thumbnail
PHP can produce dynamic content for any website.

PHP, which stands for PHP: Hypertext Preprocessor, is a server-side scripting language used for creating interactive Web pages, mostly with PHP and HTML codes. PHP works similarly to other platforms, such as ASP or ColdFusion, in that it processes information and then releases the data to your browser. PHP, however, is an open source and cross-platform language that can fully integrate with all production environments. There are many things you can do with PHP, such as a spinner project. A PHP spinner is a simple code that makes your text strings rotate to create interesting SEO-driven word combinations that often form comical sentences.

Instructions

    • 1

      Paste the following PHP code to use as a template for your spinner project:

      <?php

      function Spin($txt){

      $test = preg_match_all("#\{(.*?)\}#", $txt, $out);

      if (!$test) return $txt;

      $toFind = Array();

      $toReplace = Array();

      foreach($out[0] AS $id => $match){

      $choices = explode("|", $out[1][$id]);

      $toFind[]=$match;

      $toReplace[]=trim($choices[rand(0, count($choices)-1)]);

      }

      return str_replace($toFind, $toReplace, $txt);

      }

      ?>

    • 2

      Add the following code below to run your spinner project. The code will create two functions: the spin function and the replacement line for the first instance of a string:

      <?php

      $text = "The {fast|timid| reluctantly slow} {red|green|purple|pink} {fox|sheep|moose|camel}

      {jumped|walked|hopped} {over|past|under} the {sleepy|exhausted|boring} {dog|cat|goat}";

      $count = 0;

      while ($count++ < 100){

      echo Spin($text);

      echo "<br />";

      }

      ?>

      This code will produce various funny yet beneficial spin combinations for your subject in terms of SEO, such as:

      The fast red fox walked over the sleepy dog

      The timid green sheep walked under the exhausted goat

      The reluctantly slow pink moose hopped over the boring cat

    • 3

      Paste the code below to keep your PHP spinner project nested in its designated spot:

      $string = '{{A {{common|basic}} example|An uncomplicated scenario|The {{plain|trivial|elementary|rudimentary}} case|My {{analysis|invest{{igative|igation}}}} case}} to illustrate the {{problem|issue}}';

      echo '<p>';

      for($i = 1; $i <= 5; $i++)

      {

      echo Spinner::detect($string, false).'<br />';

      // or Spinner::nested($string, false).'<br />';

      }

      echo '</p>';

Tips & Warnings

  • Join discussion forums to seek expert advice about PHP programming.

Related Searches:

References

Resources

  • Photo Credit Stockbyte/Stockbyte/Getty Images

Comments

Related Ads

Featured