dongxian8272
dongxian8272
2015-03-14 06:18
浏览 43
已采纳

如何使用preg_replace与维度模式和PHP中的替换?

This is my code:

$search = array 
    (
    array('/iked$/', '/ked$/', '/sed$/', '/hed$/', '/xed$/', '/ated$/', '/ited$/', '/ted$/', '/nded$/', '/red$/', '/zed$/', '/led$/', '/med$/', '/ned$/', '/wed$/', '/ied$/', '/bbed$/', '/nged$/', '/gged$/', '/ged$/', '/cided$/', '/luded$/', '/ded$/', '/eeded$/', '/pped$/', '/ced$/', '/ved$/', '/yed/'),

    array('/ying$/')
);

$replace = array
    (
    array('ike', 'k', 'se', 'h', 'x', 'ate', 'ite', 't', 'nd', 'r', 'z', 'l', 'm', 'n', 'w', 'y', 'b', 'ng', 'g', 'ge', 'cide', 'lude', 'd', 'eed', 'p', 'ce', 've', 'y'),

    array('y')
);

$kd = preg_replace($search, $replace, $_GET['verb2']);

I want to convert verb forms into Infinitives, e.g. worked to work, studying to study. Does anyone know why my code doesn't work?

Is there any other solution?

图片转代码服务由CSDN问答提供 功能建议

这是我的代码:

  $ search = array \  n(
 array('/ iked $ /','/ ked $ /','/ sed $ /','/ hed $ /','/ xed $ /','/ ated $ /','/  ited $ /','/ ted $ /','/ nded $ /','/ red $ /','/ zed $ /','/ led $ /','/ med $ /','/ ned  $ /','/ wed $ /','/ ied $ /','/ bbed $ /','/ nged $ /','/ gged $ /','/ ged $ /','/ cided $  /','/ luded $ /','/ ded $ /','/ eeded $ /','/ pped $ /','/ ced $ /','/ ved $ /','/ yed /'  ),
 
 array('/ ying $ /')
); 
 
 $ replace = array 
(
 array('ike','k','se','h',  'x','ate','ite','t','nd','r','z','l','m','n','w','y','b  ','ng','g','ge','cide','lude','d','eed','p','ce','ve','y'),
 \  n array('y')
); 
 
 $ kd = preg_replace($ search,$ replace,$ _GET ['verb2']); 
   
 
 < 我希望将动词形式转换为不定式,例如 工作工作学习 study 。
有谁知道为什么我的代码不起作用? 
 
 

还有其他解决方案吗?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongyanfeng0546
    dongyanfeng0546 2015-03-14 06:38
    已采纳

    Try with this example and correct your code:

    <?php
    
    $search = array('/ked$/', '/ying$/');
    
    $replace = array('k', 'y');
    
    $w = preg_replace($search, $replace, 'worked');
    $s = preg_replace($search, $replace, 'studying');
    
    print_r($w);
    echo '<br>';
    print_r($s);
    
    ?>
    

    If you want have a multidimensional array pattern, see this:

    Using preg_replace on a array

    点赞 评论

相关推荐