run code in 150+ php & hhvm versions
Bugs & Features
<?php function multineedle_stripos($full_text, $words, $offset=0) { $words_found = 0; if(!is_array($words)) { $words = explode(' ', $words); } $total_words = sizeof($words); foreach($needles as $needle) { if(stripos($haystack, $needle, $offset)) { $found++; } } $relative = ($found / $total_words) * 100; $result = array( 'total_words'=>$total_words, 'percentage_found'=>number_format($relative, 0) ); return $result; } $str = <<<EOT Albert's Einstein was born in Ulm, in the Kingdom of Württemberg in the German Empire on 14 March 1879.[10] His father was Hermann Einstein, a salesman and engineer. His mother was Pauline Einstein (née Koch). In 1880, the family moved to Munich, where his father and his uncle founded Elektrotechnische Fabrik J. Einstein & Cie, a company that manufactured electrical equipment based on direct current.[10] The Einsteins were non-observant Ashkenazi Jews. Albert's attended a Catholic elementary school from the age of five for three years. At the age of eight, he was transferred to the Luitpold Gymnasium (now known as the Albert's Einstein Gymnasium), where he received advanced primary and secondary school education until he left Germany seven years later.[11] Contrary to popular suggestions that he had struggled with early speech difficulties, the Albert's Einstein Archives indicate he excelled at the first school that he attended.[12] He was right-handed;[12][13] there appears to be no evidence for the widespread popular belief[14] that he was left-handed. His father once showed him a pocket compass; Einstein realized that there must be something causing the needle to move, despite the apparent "empty space".[15] As he grew, Einstein built models and mechanical devices for fun and began to show a talent for mathematics.[10] When Einstein was ten years old, Max Talmud (later changed to Max Talmey), a poor Jewish medical student from Poland, was introduced to the Einstein family by his brother. During weekly visits over the next five years, he gave the boy popular books on science, mathematical texts and philosophical writings. These included Immanuel Kant's Critique of Pure Reason, and Euclid's Elements (which Einstein called the "holy little geometry book").[16][17][fn 1] In 1894, his father's company failed: direct current (DC) lost the War of Currents to alternating current (AC). In search of business, the Einstein family moved to Italy, first to Milan and then, a few months later, to Pavia. When the family moved to Pavia, Einstein stayed in Munich to finish his studies at the Luitpold Gymnasium. His father intended for him to pursue electrical engineering, but Einstein clashed with authorities and resented the school's regimen and teaching method. He later wrote that the spirit of learning and creative thought were lost in strict rote learning. At the end of December 1894, he travelled to Italy to join his family in Pavia, convincing the school to let him go by using a doctor's note.[19] It was during his time in Italy that he wrote a short essay with the title "On the Investigation of the State of the Ether in a Magnetic Field."[20][21] In 1895, at the age of sixteen, Einstein sat the entrance examinations for the Swiss Federal Polytechnic in Zürich (later the Eidgenössische Technische Hochschule ETH). He failed to reach the required standard in the general part of the examination,[22] but obtained exceptional grades in physics and mathematics.[23] On the advice of the Principal of the Polytechnic, he attended the Argovian cantonal school (gymnasium) in Aarau, Switzerland, in 1895–96 to complete his secondary schooling. While lodging with the family of Professor Jost Winteler, he fell in love with Winteler's daughter, Marie. (Albert's sister Maja later married Wintelers' son Paul.)[24] In January 1896, with his father's approval, he renounced his citizenship in the German Kingdom of Württemberg to avoid military service.[25] In September 1896, he passed the Swiss Matura with mostly good grades, including a top grade of 6 in physics and mathematical subjects, on a scale of 1-6,[26] and, though only seventeen, enrolled in the four-year mathematics and physics teaching diploma program at the Zürich Polytechnic. Marie Winteler moved to Olsberg, Switzerland for a teaching post. Einstein's future wife, Mileva Marić, also enrolled at the Polytechnic that same year, the only woman among the six students in the mathematics and physics section of the teaching diploma course. Over the next few years, Einstein and Marić's friendship developed into romance, and they read books together on extra-curricular physics in which Einstein was taking an increasing interest. In 1900, Einstein was awarded the Zürich Polytechnic teaching diploma, but Marić failed the examination with a poor grade in the mathematics component, theory of functions.[27] There have been claims that Marić collaborated with Einstein on his celebrated 1905 papers,[28][29] but historians of physics who have studied the issue find no evidence that she made any substantive contributions xdva's uter. EOT; $search = "Einstein wife"; $result = multineedle_stripos($str, $search); if($result['percentage_found'] > 50) { echo $relative. '% related to your query (Total words: '.$result['total_words'].', Words found: '.$result['percentage_found'].')'; } else { echo 'Could not find anything related'; }
Output for 5.1.0 - 7.1.0
Notice: Undefined variable: needles in /in/D3bYF on line 14 Warning: Invalid argument supplied for foreach() in /in/D3bYF on line 14 Notice: Undefined variable: found in /in/D3bYF on line 22 Could not find anything related
Output for 5.0.4 - 5.0.5
Warning: Invalid argument supplied for foreach() in /in/D3bYF on line 14 Notice: Undefined variable: found in /in/D3bYF on line 22 Could not find anything related
Output for 4.3.0 - 4.3.10, 4.4.0 - 5.0.3
Warning: Invalid argument supplied for foreach() in /in/D3bYF on line 14 Notice: Undefined variable: found in /in/D3bYF on line 22 Could not find anything related
Output for 4.3.11
Notice: Undefined variable: found in /in/D3bYF on line 22 Could not find anything related