3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class keywords { public $ngramsSpecific = array ( 'tos pačios lyties', 'seksualin* mažum*', 'gėj* eityn*' ); public $ngramsGeneric = array ( 'žmogaus teis*' ); public $keywordsSpecific = array ( 'gėjus', 'lesbietė', 'transvestitas', 'homoseksualas', 'biseksualas', 'homoseksualumas', 'homoseksualus', 'pride', 'LGBT', 'homofobija', 'homofobiškas', 'transseksualas', 'LGBTQ', 'DOMA', 'queer' ); public $keywordsGeneric = array ( 'tolerantiškas', 'tolerancija', 'diskriminacija', 'orientacija', 'paradas', 'eitynės', 'neapykanta', 'lygybė', 'mažuma' ); public $positiveAuthors = array ( 'Nida Vasiliauskaitė', 'Artūras Rudomanskis', 'Marija Aušrinė Pavilionienė', 'Mindaugas Kluonis', 'J. V. Daugmaudis' ); public $negativeAuthors = array ( 'Liudvika Pociūnienė', 'Tomas Čyvas', 'Vytautas Sinica', 'Paulius Stonis' ); } function getRelevancy(article $article = null) { $keywords = new keywords(); //$articleBody = strtolower($article->body); $articleBody = "laba diena seksualinė mažuma yra labai geri, bet seksualinės mažumos nėra pats geriausias vaistas nuo visu ligu, nes seksualinėse mažumose gali buti pasitaike daugybe ivairiu dalyku tuo tarpu aseseksualinės mažumos nenori valgyto"; $match = array(); foreach($keywords->ngramsSpecific as $ngram) { //\b(seksualin\w+)\s\b(mazum\w+) $ngram = str_ireplace('*', '\w+', $ngram); $exploded = explode(" ", $ngram); foreach($exploded as &$piece) { $piece = "\b" . $piece; } $regex = "/" . implode("\s", $exploded) . "/iu"; preg_match_all($regex, $articleBody, $matches); $match[] = $matches; } return $match; /* $annotatedTitle = annotateText($article->title); $annotatedBody = annotateText($article->body); $titleIntersection = array_intersect($annotatedTitle, array_map('strtolower', $specificKeywords)); $bodyIntersection = array_intersect($annotatedBody, array_map('strtolower', $specificKeywords)); $titleIntersectionI = array_intersect($annotatedTitle, array_map('strtolower', $genericKeywords)); $bodyIntersectionI = array_intersect($annotatedBody, array_map('strtolower', $genericKeywords)); return array($titleIntersection, $bodyIntersection, $titleIntersectionI, $bodyIntersectionI); */ } print_r(getRelevancy());
Output for 5.3.4 - 5.6.21, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Array ( [0] => Array ( [0] => Array ( ) ) [1] => Array ( [0] => Array ( [0] => seksualinė mažuma [1] => seksualinės mažumos [2] => seksualinėse mažumose ) ) [2] => Array ( [0] => Array ( ) ) )
Output for 5.1.0 - 5.3.3
Array ( [0] => Array ( [0] => Array ( ) ) [1] => Array ( [0] => Array ( ) ) [2] => Array ( [0] => Array ( ) ) )
Output for 5.0.0 - 5.0.5
Fatal error: Argument 1 must not be null in /in/qNd6N on line 31
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/qNd6N on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/qNd6N on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/qNd6N on line 4
Process exited with code 255.