ÿØÿà JFIF ÿÛ „ ( %"1"%)+...383,7(-.-
![]() Server : Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.20 System : Linux st2.domain.com 3.10.0-1127.10.1.el7.x86_64 #1 SMP Wed Jun 3 14:28:03 UTC 2020 x86_64 User : apache ( 48) PHP Version : 7.4.20 Disable Function : NONE Directory : /var/www/html/admin.adimi/code/spintext/ |
<?php /** * Spintax - A helper class to process Spintax strings. * * @author Jason Davis - https://www.codedevelopr.com/ * * Tutorial: https://www.codedevelopr.com/articles/php-spintax-class/ * * Updated with suggested performance improvement by @PhiSYS. */ class Spintax { public function process($text) { return preg_replace_callback( '/\{(((?>[^\{\}]+)|(?R))*?)\}/x', array($this, 'replace'), $text ); } public function replace($text) { $text = $this->process($text[1]); $parts = explode('|', $text); return $parts[array_rand($parts)]; } public function random($str) { // Returns random values found between { this | and } return preg_replace_callback("/{(.*?)}/", function ($match) { // Splits 'foo|bar' strings into an array $words = explode("|", $match[1]); // Grabs a random array entry and returns it return $words[array_rand($words)]; // The input string, which you provide when calling this func }, $str); } } /* EXAMPLE USAGE */ $spintax = new Spintax(); /*$string = '{Hello|Howdy|Hola} to you, {Mr.|Mrs.|Ms.} {Smith|Williams|Davis}!'; echo $spintax->process($string);*/ $string = '{Hello|Howdy|Hola} to you, {Mr.|Mrs.|Ms.} {Smith|Williams|Davis}!'; var_dump($spintax->random($string)); /* NESTED SPINNING EXAMPLE */ //echo $spintax->process('{Hello|Howdy|Hola} to you, {Mr.|Mrs.|Ms.} {{Jason|Malina|Sara}|Williams|Davis}'); ?>