3v4l.org

run code in 300+ PHP versions simultaneously
<?php function remove_irrelevant_text($text) { $remove = array( '?','!', ',', '\'', '"', '#', '$', '&', '*', '(', ')', '-', '+', '.', "'s ", ' for ', ' to ', ' in ', ' the ', ' and ', ' on ', ' of ', ' by ', ' he ', ' she ', ' his ', ' her ', ' a ', ' but ', ' at ', ' as ', ' para ', ' no ', ' na ', ' e ', ' o ', ' em ', ' do ', ' de ', ' da ', ' por ', ' ele ', ' ela ', ' seu ', ' dela ', ' é ', ' mas ', ' ' ); return str_ireplace($remove, ' ', $text); } function search_text($full_text, $words, $offset=0) { $words_found = 0; $stripped_text = remove_irrelevant_text($full_text); $words = remove_irrelevant_text($words); if(!is_array($words)) { $words = explode(' ', $words); } $total_words = sizeof($words); foreach($words as $word) { if(stripos($stripped_text, $word, $offset)) { $words_found++; } } $relative = ($words_found / $total_words) * 100; $result = array( 'total_words'=>$total_words, 'percentage_found'=>number_format($relative, 0), 'parsed_text'=>$stripped_text ); 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 = "where did Einstein's wife was born?"; $result = search_text($str, $search); if($result['percentage_found'] > 50) { echo $result['percentage_found']. '% related to your query (Total words: '.$result['total_words'].', Words found: '.$result['percentage_found'].')'; } else { echo 'Could not find anything related'; } echo PHP_EOL.PHP_EOL.'======================'.PHP_EOL.PHP_EOL.PHP_EOL.$result['parsed_text'];
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 20
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FHRMi
function name:  (null)
number of ops:  25
compiled vars:  !0 = $str, !1 = $search, !2 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   ASSIGN                                                   !0, 'Albert%27s+Einstein+was+born+in+Ulm%2C+in+the+Kingdom+of+W%C3%BCrttemberg+in+the+German+Empire+on+14+March+1879.%5B10%5D+His+father+was+Hermann+Einstein%2C+a+salesman+and+engineer.+His+mother+was+Pauline+Einstein+%28n%C3%A9e+Koch%29.+In+1880%2C+the+family+moved+to+Munich%2C+where+his+father+and+his+uncle+founded+Elektrotechnische+Fabrik+J.+Einstein+%26+Cie%2C+a+company+that+manufactured+electrical+equipment+based+on+direct+current.%5B10%5D%0A%0AThe+Einsteins+were+non-observant+Ashkenazi+Jews.+Albert%27s+attended+a+Catholic+elementary+school+from+the+age+of+five+for+three+years.+At+the+age+of+eight%2C+he+was+transferred+to+the+Luitpold+Gymnasium+%28now+known+as+the+Albert%27s+Einstein+Gymnasium%29%2C+where+he+received+advanced+primary+and+secondary+school+education+until+he+left+Germany+seven+years+later.%5B11%5D+Contrary+to+popular+suggestions+that+he+had+struggled+with+early+speech+difficulties%2C+the+Albert%27s+Einstein+Archives+indicate+he+excelled+at+the+first+school+that+he+attended.%5B12%5D+He+was+right-handed%3B%5B12%5D%5B13%5D+there+appears+to+be+no+evidence+for+the+widespread+popular+belief%5B14%5D+that+he+was+left-handed.%0A%0AHis+father+once+showed+him+a+pocket+compass%3B+Einstein+realized+that+there+must+be+something+causing+the+needle+to+move%2C+despite+the+apparent+%22empty+space%22.%5B15%5D+As+he+grew%2C+Einstein+built+models+and+mechanical+devices+for+fun+and+began+to+show+a+talent+for+mathematics.%5B10%5D+When+Einstein+was+ten+years+old%2C+Max+Talmud+%28later+changed+to+Max+Talmey%29%2C+a+poor+Jewish+medical+student+from+Poland%2C+was+introduced+to+the+Einstein+family+by+his+brother.+During+weekly+visits+over+the+next+five+years%2C+he+gave+the+boy+popular+books+on+science%2C+mathematical+texts+and+philosophical+writings.+These+included+Immanuel+Kant%27s+Critique+of+Pure+Reason%2C+and+Euclid%27s+Elements+%28which+Einstein+called+the+%22holy+little+geometry+book%22%29.%5B16%5D%5B17%5D%5Bfn+1%5D%0A%0AIn+1894%2C+his+father%27s+company+failed%3A+direct+current+%28DC%29+lost+the+War+of+Currents+to+alternating+current+%28AC%29.+In+search+of+business%2C+the+Einstein+family+moved+to+Italy%2C+first+to+Milan+and+then%2C+a+few+months+later%2C+to+Pavia.+When+the+family+moved+to+Pavia%2C+Einstein+stayed+in+Munich+to+finish+his+studies+at+the+Luitpold+Gymnasium.+His+father+intended+for+him+to+pursue+electrical+engineering%2C+but+Einstein+clashed+with+authorities+and+resented+the+school%27s+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%2C+he+travelled+to+Italy+to+join+his+family+in+Pavia%2C+convincing+the+school+to+let+him+go+by+using+a+doctor%27s+note.%5B19%5D+It+was+during+his+time+in+Italy+that+he+wrote+a+short+essay+with+the+title+%22On+the+Investigation+of+the+State+of+the+Ether+in+a+Magnetic+Field.%22%5B20%5D%5B21%5D%0A%0AIn+1895%2C+at+the+age+of+sixteen%2C+Einstein+sat+the+entrance+examinations+for+the+Swiss+Federal+Polytechnic+in+Z%C3%BCrich+%28later+the+Eidgen%C3%B6ssische+Technische+Hochschule+ETH%29.+He+failed+to+reach+the+required+standard+in+the+general+part+of+the+examination%2C%5B22%5D+but+obtained+exceptional+grades+in+physics+and+mathematics.%5B23%5D+On+the+advice+of+the+Principal+of+the+Polytechnic%2C+he+attended+the+Argovian+cantonal+school+%28gymnasium%29+in+Aarau%2C+Switzerland%2C+in+1895%E2%80%9396+to+complete+his+secondary+schooling.+While+lodging+with+the+family+of+Professor+Jost+Winteler%2C+he+fell+in+love+with+Winteler%27s+daughter%2C+Marie.+%28Albert%27s+sister+Maja+later+married+Wintelers%27+son+Paul.%29%5B24%5D+In+January+1896%2C+with+his+father%27s+approval%2C+he+renounced+his+citizenship+in+the+German+Kingdom+of+W%C3%BCrttemberg+to+avoid+military+service.%5B25%5D+In+September+1896%2C+he+passed+the+Swiss+Matura+with+mostly+good+grades%2C+including+a+top+grade+of+6+in+physics+and+mathematical+subjects%2C+on+a+scale+of+1-6%2C%5B26%5D+and%2C+though+only+seventeen%2C+enrolled+in+the+four-year+mathematics+and+physics+teaching+diploma+program+at+the+Z%C3%BCrich+Polytechnic.+Marie+Winteler+moved+to+Olsberg%2C+Switzerland+for+a+teaching+post.%0A%0AEinstein%27s+future+wife%2C+Mileva+Mari%C4%87%2C+also+enrolled+at+the+Polytechnic+that+same+year%2C+the+only+woman+among+the+six+students+in+the+mathematics+and+physics+section+of+the+teaching+diploma+course.+Over+the+next+few+years%2C+Einstein+and+Mari%C4%87%27s+friendship+developed+into+romance%2C+and+they+read+books+together+on+extra-curricular+physics+in+which+Einstein+was+taking+an+increasing+interest.+In+1900%2C+Einstein+was+awarded+the+Z%C3%BCrich+Polytechnic+teaching+diploma%2C+but+Mari%C4%87+failed+the+examination+with+a+poor+grade+in+the+mathematics+component%2C+theory+of+functions.%5B27%5D+There+have+been+claims+that+Mari%C4%87+collaborated+with+Einstein+on+his+celebrated+1905+papers%2C%5B28%5D%5B29%5D+but+historians+of+physics+who+have+studied+the+issue+find+no+evidence+that+she+made+any+substantive+contributions+xdva%27s+uter.%0A'
   65     1        ASSIGN                                                   !1, 'where+did+Einstein%27s+wife+was+born%3F'
   67     2        INIT_FCALL                                               'search_text'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_FCALL                                      0  $5      
          6        ASSIGN                                                   !2, $5
   69     7        FETCH_DIM_R                                      ~7      !2, 'percentage_found'
          8        IS_SMALLER                                               50, ~7
          9      > JMPZ                                                     ~8, ->20
   71    10    >   FETCH_DIM_R                                      ~9      !2, 'percentage_found'
         11        CONCAT                                           ~10     ~9, '%25+related+to+your+query+%28Total+words%3A+'
         12        FETCH_DIM_R                                      ~11     !2, 'total_words'
         13        CONCAT                                           ~12     ~10, ~11
         14        CONCAT                                           ~13     ~12, '%2C+Words+found%3A+'
         15        FETCH_DIM_R                                      ~14     !2, 'percentage_found'
         16        CONCAT                                           ~15     ~13, ~14
         17        CONCAT                                           ~16     ~15, '%29'
         18        ECHO                                                     ~16
         19      > JMP                                                      ->21
   75    20    >   ECHO                                                     'Could+not+find+anything+related'
   78    21    >   FETCH_DIM_R                                      ~17     !2, 'parsed_text'
         22        CONCAT                                           ~18     '%0A%0A%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%0A%0A%0A', ~17
         23        ECHO                                                     ~18
         24      > RETURN                                                   1

Function remove_irrelevant_text:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FHRMi
function name:  remove_irrelevant_text
number of ops:  9
compiled vars:  !0 = $text, !1 = $remove
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        ASSIGN                                                   !1, <array>
   12     2        INIT_FCALL                                               'str_ireplace'
          3        SEND_VAR                                                 !1
          4        SEND_VAL                                                 '+'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $3      
          7      > RETURN                                                   $3
   13     8*     > RETURN                                                   null

End of function remove_irrelevant_text

Function search_text:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 20
Branch analysis from position: 15
2 jumps found. (Code = 77) Position 1 = 23, Position 2 = 32
Branch analysis from position: 23
2 jumps found. (Code = 78) Position 1 = 24, Position 2 = 32
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 31
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
Branch analysis from position: 31
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
Branch analysis from position: 20
filename:       /in/FHRMi
function name:  search_text
number of ops:  46
compiled vars:  !0 = $full_text, !1 = $words, !2 = $offset, !3 = $words_found, !4 = $stripped_text, !5 = $total_words, !6 = $word, !7 = $relative, !8 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      0
   18     3        ASSIGN                                                   !3, 0
   20     4        INIT_FCALL                                               'remove_irrelevant_text'
          5        SEND_VAR                                                 !0
          6        DO_FCALL                                      0  $10     
          7        ASSIGN                                                   !4, $10
   21     8        INIT_FCALL                                               'remove_irrelevant_text'
          9        SEND_VAR                                                 !1
         10        DO_FCALL                                      0  $12     
         11        ASSIGN                                                   !1, $12
   23    12        TYPE_CHECK                                  128  ~14     !1
         13        BOOL_NOT                                         ~15     ~14
         14      > JMPZ                                                     ~15, ->20
   25    15    >   INIT_FCALL                                               'explode'
         16        SEND_VAL                                                 '+'
         17        SEND_VAR                                                 !1
         18        DO_ICALL                                         $16     
         19        ASSIGN                                                   !1, $16
   28    20    >   COUNT                                            ~18     !1
         21        ASSIGN                                                   !5, ~18
   30    22      > FE_RESET_R                                       $20     !1, ->32
         23    > > FE_FETCH_R                                               $20, !6, ->32
   32    24    >   INIT_FCALL                                               'stripos'
         25        SEND_VAR                                                 !4
         26        SEND_VAR                                                 !6
         27        SEND_VAR                                                 !2
         28        DO_ICALL                                         $21     
         29      > JMPZ                                                     $21, ->31
   34    30    >   PRE_INC                                                  !3
   30    31    > > JMP                                                      ->23
         32    >   FE_FREE                                                  $20
   38    33        DIV                                              ~23     !3, !5
         34        MUL                                              ~24     ~23, 100
         35        ASSIGN                                                   !7, ~24
   41    36        INIT_ARRAY                                       ~26     !5, 'total_words'
   42    37        INIT_FCALL                                               'number_format'
         38        SEND_VAR                                                 !7
         39        SEND_VAL                                                 0
         40        DO_ICALL                                         $27     
         41        ADD_ARRAY_ELEMENT                                ~26     $27, 'percentage_found'
   43    42        ADD_ARRAY_ELEMENT                                ~26     !4, 'parsed_text'
   40    43        ASSIGN                                                   !8, ~26
   46    44      > RETURN                                                   !8
   47    45*     > RETURN                                                   null

End of function search_text

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
172.39 ms | 1402 KiB | 24 Q