3v4l.org

run code in 300+ PHP versions simultaneously
<?php // all keys must be lowercase $keywords_external_path = array( "business analyst là gì" => "business-analyst/", "tài liệu cho business analyst" => "tai-lieu-cho-business-analyst/", "product manager là gì" => "product-manager-la-gi/", "công việc của product manager" => "product-manager-phai-biet-dat-cau-hoi/", "QA là gì" => "qc-la-gi-qa-la-gi/", "QC là gì" => "qc-la-gi-qa-la-gi/", "Kiểm thử phần mềm là gì" => "kiem-thu-phan-mem-ai-lam-chang-duoc/", "Automation QA là gì" => "3-loi-khuyen-giup-ban-nang-cap-su-nghiep-qa/", "Tester là gì" => "tester-thanh-cong/", "kỹ năng của Tester giỏi" => "tester-thanh-cong/", "công việc QA" => "qa-gioi/", "Technical Architect là gì" => "how-to-become-ta/", ); //change the keys to lowercase (support multibyte characters) mb_internal_encoding("UTF-8"); $keywords_external_path = array_combine(array_map('mb_strtolower', array_keys($keywords_external_path)), $keywords_external_path); $data = array( 'post_content' => '"business analyst là gì" => "business-analyst/", "tài liệu cho business analyst" => "tai-lieu-cho-business-analyst/", "product manager là gì" => "product-manager-la-gi/", "công việc của product manager" => "product-manager-phai-biet-dat-cau-hoi/", "QA là gì" => "qc-la-gi-qa-la-gi/", "QC là gì" => "qc-la-gi-qa-la-gi/", "Kiểm thử phần mềm là gì" => "kiem-thu-phan-mem-ai-lam-chang-duoc/", "Automation QA là gì" => "3-loi-khuyen-giup-ban-nang-cap-su-nghiep-qa/", "Tester là gì" => "tester-thanh-cong/", "kỹ năng của Tester giỏi" => "tester-thanh-cong/", "công việc QA" => "qa-gioi/", "Technical Architect là gì" => "how-to-become-ta/"' ); $base = 'http://domain.com/'; // only if this is useful $keywords_external = array_keys($keywords_external_path); rsort($keywords_external); // to quickly discards useless position (if you have many keywords): you can also do the same with the second letter $keywords_first_letter = implode('', array_unique(array_reduce($keywords_external, function ($c, $i) { $c[] = mb_substr($i, 0, 1); return $c; }, []))); $pattern = '~\b(?=['. $keywords_first_letter . '])(?:' . implode('|', $keywords_external) . ')\b~iu'; $result = preg_replace_callback($pattern, function ($m) use ($keywords_external_path, $base) { return '<a href="' . $base . $keywords_external_path[mb_strtolower($m[0])] . '">' . $m[0] . '</a>'; }, $data['post_content']); echo $result;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/H0gib
function name:  (null)
number of ops:  60
compiled vars:  !0 = $keywords_external_path, !1 = $data, !2 = $base, !3 = $keywords_external, !4 = $keywords_first_letter, !5 = $pattern, !6 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   19     1        INIT_FCALL                                               'mb_internal_encoding'
          2        SEND_VAL                                                 'UTF-8'
          3        DO_ICALL                                                 
   20     4        INIT_FCALL                                               'array_combine'
          5        INIT_FCALL                                               'array_map'
          6        SEND_VAL                                                 'mb_strtolower'
          7        INIT_FCALL                                               'array_keys'
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                         $9      
         10        SEND_VAR                                                 $9
         11        DO_ICALL                                         $10     
         12        SEND_VAR                                                 $10
         13        SEND_VAR                                                 !0
         14        DO_ICALL                                         $11     
         15        ASSIGN                                                   !0, $11
   22    16        ASSIGN                                                   !1, <array>
   38    17        ASSIGN                                                   !2, 'http%3A%2F%2Fdomain.com%2F'
   40    18        INIT_FCALL                                               'array_keys'
         19        SEND_VAR                                                 !0
         20        DO_ICALL                                         $15     
         21        ASSIGN                                                   !3, $15
   41    22        INIT_FCALL                                               'rsort'
         23        SEND_REF                                                 !3
         24        DO_ICALL                                                 
   44    25        INIT_FCALL                                               'implode'
         26        SEND_VAL                                                 ''
         27        INIT_FCALL                                               'array_unique'
         28        INIT_FCALL                                               'array_reduce'
         29        SEND_VAR                                                 !3
         30        DECLARE_LAMBDA_FUNCTION                          ~18     [0]
         31        SEND_VAL                                                 ~18
         32        SEND_VAL                                                 <array>
         33        DO_ICALL                                         $19     
         34        SEND_VAR                                                 $19
         35        DO_ICALL                                         $20     
         36        SEND_VAR                                                 $20
         37        DO_ICALL                                         $21     
         38        ASSIGN                                                   !4, $21
   46    39        CONCAT                                           ~23     '%7E%5Cb%28%3F%3D%5B', !4
         40        CONCAT                                           ~24     ~23, '%5D%29%28%3F%3A'
         41        INIT_FCALL                                               'implode'
         42        SEND_VAL                                                 '%7C'
         43        SEND_VAR                                                 !3
         44        DO_ICALL                                         $25     
         45        CONCAT                                           ~26     ~24, $25
         46        CONCAT                                           ~27     ~26, '%29%5Cb%7Eiu'
         47        ASSIGN                                                   !5, ~27
   48    48        INIT_FCALL                                               'preg_replace_callback'
         49        SEND_VAR                                                 !5
         50        DECLARE_LAMBDA_FUNCTION                          ~29     [1]
         51        BIND_LEXICAL                                             ~29, !0
         52        BIND_LEXICAL                                             ~29, !2
   50    53        SEND_VAL                                                 ~29
         54        FETCH_DIM_R                                      ~30     !1, 'post_content'
         55        SEND_VAL                                                 ~30
   48    56        DO_ICALL                                         $31     
         57        ASSIGN                                                   !6, $31
   52    58        ECHO                                                     !6
         59      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/H0gib
function name:  {closure}
number of ops:  11
compiled vars:  !0 = $c, !1 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        INIT_FCALL                                               'mb_substr'
          3        SEND_VAR                                                 !1
          4        SEND_VAL                                                 0
          5        SEND_VAL                                                 1
          6        DO_ICALL                                         $3      
          7        ASSIGN_DIM                                               !0
          8        OP_DATA                                                  $3
          9      > RETURN                                                   !0
         10*     > RETURN                                                   null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/H0gib
function name:  {closure}
number of ops:  16
compiled vars:  !0 = $m, !1 = $keywords_external_path, !2 = $base
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   48     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        BIND_STATIC                                              !2
   49     3        CONCAT                                           ~3      '%3Ca+href%3D%22', !2
          4        INIT_FCALL                                               'mb_strtolower'
          5        FETCH_DIM_R                                      ~4      !0, 0
          6        SEND_VAL                                                 ~4
          7        DO_ICALL                                         $5      
          8        FETCH_DIM_R                                      ~6      !1, $5
          9        CONCAT                                           ~7      ~3, ~6
         10        CONCAT                                           ~8      ~7, '%22%3E'
         11        FETCH_DIM_R                                      ~9      !0, 0
         12        CONCAT                                           ~10     ~8, ~9
         13        CONCAT                                           ~11     ~10, '%3C%2Fa%3E'
         14      > RETURN                                                   ~11
   50    15*     > RETURN                                                   null

End of Dynamic Function 1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.6 ms | 1465 KiB | 24 Q