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.
Result of php executing
Full code of test1.php
- <?php
- function titleCreateProduct($text,$art, $price)
- {
- //first shorten to max_len
- $max_len = 32; //note: additional text is ~32
- $words = explode(" ",$text);
- $tot_text = "";
- foreach ($words as $word)
- {
- if ((strlen($tot_text)+strlen($word))>$max_len)
- break;
- $tot_text.=" ".$word;
- }
- $tot_text = trim($tot_text);
- //next check art_type and add
- switch ($art)
- {
- case 0: $tot_text.= ": Crochet"; break;
- case 1: $tot_text.= ": Sewing"; break;
- case 2: $tot_text.= ": Knitting"; break;
- case 3: $tot_text.= ": Tunisian"; break;
- }
- $tot_text.= " pattern";
- //next add "FREE" if price=0
- if ($price==0)
- $tot_text = "FREE ".$tot_text;
- //next add Ribblr
- $tot_text.= " | Ribblr";
- return $tot_text;
- }
- function descriptionCreateProduct($text,$art, $price)
- {
- $max_words = 7;
- $words = explode(" ",$text);
- $tot_text = ""; $cnt=0;
- foreach ($words as $word)
- {
- if (++$cnt>=$max_words)
- break;
- $tot_text.=" ".$word;
- }
- $tot_text = trim($tot_text);
- //next check art_type and add
- switch ($art)
- {
- case 0: $tot_text.= " Crochet"; break;
- case 1: $tot_text.= " Sewing"; break;
- case 2: $tot_text.= " Knitting"; break;
- case 3: $tot_text.= " Tunisian"; break;
- }
- $tot_text.= " pattern! Best crafting experience with Ribblr ePattern: progress tracking, smart sizing and more!";
- //next add "FREE" if price=0
- if ($price==0)
- $tot_text = "FREE ".$tot_text;
- return $tot_text;
- }
- function slugCreateProduct($text,$art, $price)
- {
- $max_words = 7;
- $words = explode(" ",$text);
- $tot_text = ""; $cnt=0;
- foreach ($words as $word)
- {
- if (++$cnt>=$max_words)
- break;
- $tot_text.=$word."-";
- }
- $tot_text = trim(strtolower ($tot_text));
- //next check art_type and add
- switch ($art)
- {
- case 0: $tot_text.= "crochet"; break;
- case 1: $tot_text.= "sewing"; break;
- case 2: $tot_text.= "knitting"; break;
- case 3: $tot_text.= "tunisian"; break;
- }
- return $tot_text;
- }
- echo titleCreateProduct("The big bad wolf",2,0);
- echo '<br>';
- echo descriptionCreateProduct("The big bad wolf",2,0);
- echo '<br>';
- echo slugCreateProduct("The big bad wolf",2,0);
- ?>