fork(1) download
  1. <?php
  2. use warnings;
  3. $glossary = array(
  4. 'word1' => '<span title="Explanation for Word 1">word1</span>',
  5. 'word2' => '<span title="Explanation for Word 2">word2</span>',
  6. 'word3' => '<span title="Explanation for Word 3">word3</span>'
  7. );
  8.  
  9. $text = "This is a text about Word1. We also talk about word2 and WORD3. Also woRd3, word2 and WORD1";
  10.  
  11. $pttrns = array_map(function ($val) {return "/" . preg_quote($val) . "/i"; },array_keys($glossary));
  12. $res = preg_replace_callback($pttrns, function ($m) use($glossary){
  13. return str_replace(strtolower($m[0]), $m[0], $glossary[strtolower($m[0])]);
  14. }, $text);
  15. echo $res;
Success #stdin #stdout #stderr 0.03s 52480KB
stdin
Standard input is empty
stdout
This is a text about <span title="Explanation for Word 1">Word1</span>. We also talk about <span title="Explanation for Word 2">word2</span> and <span title="Explanation for Word 3">WORD3</span>. Also <span title="Explanation for Word 3">woRd3</span>, <span title="Explanation for Word 2">word2</span> and <span title="Explanation for Word 1">WORD1</span>
stderr
PHP Warning:  The use statement with non-compound name 'warnings' has no effect in /home/M27NMC/prog.php on line 2