test1 - 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 test1.php

  1. <?php
  2. function titleCreateProduct($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. function descriptionCreateProduct($text,$art, $price)
  32. {
  33.         $max_words = 7;
  34.     $words = explode(" ",$text);
  35.     $tot_text = ""; $cnt=0;
  36.     foreach ($words as $word)
  37.     {
  38.         if (++$cnt>=$max_words)       
  39.             break;   
  40.         $tot_text.=" ".$word;
  41.     }
  42.     $tot_text = trim($tot_text);
  43.     //next check art_type and add
  44.     switch ($art)
  45.     {
  46.         case 0: $tot_text.= " Crochet"; break;
  47.         case 1: $tot_text.= " Sewing"; break;
  48.         case 2: $tot_text.= " Knitting"; break;
  49.         case 3: $tot_text.= " Tunisian"; break;
  50.     }
  51.     $tot_text.= " pattern! Best crafting experience with Ribblr ePattern: progress tracking, smart sizing and more!";
  52.     //next add "FREE" if price=0
  53.     if ($price==0)
  54.         $tot_text = "FREE ".$tot_text;
  55.     return $tot_text;
  56. }
  57. function slugCreateProduct($text,$art, $price)
  58. {
  59.         $max_words = 7;
  60.     $words = explode(" ",$text);
  61.     $tot_text = ""; $cnt=0;
  62.     foreach ($words as $word)
  63.     {
  64.         if (++$cnt>=$max_words)       
  65.             break;   
  66.         $tot_text.=$word."-";
  67.     }
  68.     $tot_text = trim(strtolower ($tot_text));
  69.     //next check art_type and add
  70.     switch ($art)
  71.     {
  72.         case 0: $tot_text.= "crochet"; break;
  73.         case 1: $tot_text.= "sewing"; break;
  74.         case 2: $tot_text.= "knitting"; break;
  75.         case 3: $tot_text.= "tunisian"; break;
  76.     }
  77.     return $tot_text;
  78. }
  79. echo titleCreateProduct("The big bad wolf",2,0);
  80. echo '<br>';
  81. echo descriptionCreateProduct("The big bad wolf",2,0);
  82. echo '<br>';
  83. echo slugCreateProduct("The big bad wolf",2,0);
  84. ?>
File Description
  • test1
  • PHP Code
  • 26 Oct-2020
  • 2.39 Kb
You can Share it: