3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * This is the body field of my database article table. $body * "<p style="margin:20px auto; font-size:20px;">每天都有好心情,我真的很开心 Very happy! oh yes</p>" * * */ $body = '<p style="margin:20px auto; font-size:20px;">每天都有好心情,我真的很开心 Very happy! oh yes</p>'; $str = htmlspecialchars_decode($body); $keywords = [ 0=>['id'=>1,'slug'=>'好心情','url'=>'https://www.example.com/goodMood'], 1=>['id'=>2,'slug'=>'开心','url'=>'https://www.example.com/happy'], 2=>['id'=>3,'slug'=>'happy','url'=>'https://www.example.com/happy1'], ]; //I want to convert to this format: $result = '<p style="margin:20px auto; font-size:20px;">每天都有<a href="https://www.example.com/goodMood">好心情</a>,我真的很<a href="https://www.example.com/happy">开心</a> Very <a href="https://www.example.com/happy1">happy</a>! oh yes</p>'; $reps = array_combine(array_column($keywords, 'slug'), array_map(function ($k) { return '<a href="' . $k['url'] .'">' . $k['slug'] . '</a>'; }, $keywords )); $newstr = strtr($str, $reps); echo "$newstr\n$result";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/r1LpD
function name:  (null)
number of ops:  31
compiled vars:  !0 = $body, !1 = $str, !2 = $keywords, !3 = $result, !4 = $reps, !5 = $newstr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   ASSIGN                                                   !0, '%3Cp+style%3D%22margin%3A20px+auto%3B+font-size%3A20px%3B%22%3E%E6%AF%8F%E5%A4%A9%E9%83%BD%E6%9C%89%E5%A5%BD%E5%BF%83%E6%83%85%EF%BC%8C%E6%88%91%E7%9C%9F%E7%9A%84%E5%BE%88%E5%BC%80%E5%BF%83+Very+happy%21+oh+yes%3C%2Fp%3E'
    8     1        INIT_FCALL                                               'htmlspecialchars_decode'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $7      
          4        ASSIGN                                                   !1, $7
   10     5        ASSIGN                                                   !2, <array>
   18     6        ASSIGN                                                   !3, '%3Cp+style%3D%22margin%3A20px+auto%3B+font-size%3A20px%3B%22%3E%E6%AF%8F%E5%A4%A9%E9%83%BD%E6%9C%89%3Ca+href%3D%22https%3A%2F%2Fwww.example.com%2FgoodMood%22%3E%E5%A5%BD%E5%BF%83%E6%83%85%3C%2Fa%3E%EF%BC%8C%E6%88%91%E7%9C%9F%E7%9A%84%E5%BE%88%3Ca+href%3D%22https%3A%2F%2Fwww.example.com%2Fhappy%22%3E%E5%BC%80%E5%BF%83%3C%2Fa%3E+Very+%3Ca+href%3D%22https%3A%2F%2Fwww.example.com%2Fhappy1%22%3Ehappy%3C%2Fa%3E%21+oh+yes%3C%2Fp%3E'
   20     7        INIT_FCALL                                               'array_combine'
          8        INIT_FCALL                                               'array_column'
          9        SEND_VAR                                                 !2
         10        SEND_VAL                                                 'slug'
         11        DO_ICALL                                         $11     
         12        SEND_VAR                                                 $11
   21    13        INIT_FCALL                                               'array_map'
         14        DECLARE_LAMBDA_FUNCTION                          ~12     [0]
         15        SEND_VAL                                                 ~12
         16        SEND_VAR                                                 !2
         17        DO_ICALL                                         $13     
         18        SEND_VAR                                                 $13
   20    19        DO_ICALL                                         $14     
         20        ASSIGN                                                   !4, $14
   23    21        INIT_FCALL                                               'strtr'
         22        SEND_VAR                                                 !1
         23        SEND_VAR                                                 !4
         24        DO_ICALL                                         $16     
         25        ASSIGN                                                   !5, $16
   24    26        ROPE_INIT                                     3  ~19     !5
         27        ROPE_ADD                                      1  ~19     ~19, '%0A'
         28        ROPE_END                                      2  ~18     ~19, !3
         29        ECHO                                                     ~18
         30      > 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/r1LpD
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
          1        FETCH_DIM_R                                      ~1      !0, 'url'
          2        CONCAT                                           ~2      '%3Ca+href%3D%22', ~1
          3        CONCAT                                           ~3      ~2, '%22%3E'
          4        FETCH_DIM_R                                      ~4      !0, 'slug'
          5        CONCAT                                           ~5      ~3, ~4
          6        CONCAT                                           ~6      ~5, '%3C%2Fa%3E'
          7      > RETURN                                                   ~6
          8*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.19 ms | 1446 KiB | 18 Q