title - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of title.php

  1. <?php
  2. function titleCreate($text,$art, $price)
  3. {
  4.     //first shorten to max_len
  5.     $max_len = 32; //note: additional text is ~32
  6.     $words = explode(" ",$text);
  7.     $tot_text = "";
  8.     foreach ($words as $word)
  9.     {
  10.         if ((strlen($tot_text)+strlen($word))>$max_len)
  11.             break;   
  12.         $tot_text.=" ".$word;
  13.     }
  14.     $tot_text = trim($tot_text);
  15.     //next check art_type and add
  16.     switch ($art)
  17.     {
  18.         case 0: $tot_text.= ": Crochet"; break;
  19.         case 1: $tot_text.= ": Sewing"; break;
  20.         case 2: $tot_text.= ": Knitting"; break;
  21.         case 3: $tot_text.= ": Tunisian"; break;
  22.     }
  23.     $tot_text.= " pattern";
  24.     //next add "FREE" if price=0
  25.     if ($price==0)
  26.         $tot_text = "FREE ".$tot_text;
  27.     //next add Ribblr
  28.         $tot_text.= " | Ribblr";
  29.     return $tot_text;
  30. }
  31.  
  32. echo titleCreate("The big bad wolf",2,0)
  33.  
  34. ?>
File Description
  • title
  • PHP Code
  • 26 Oct-2020
  • 866 Bytes
You can Share it: