这是我的代码:
$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']);
我想将动词形式转换为不定式,例如worked
到work
,studying
到study
。
有谁知道为什么我的代码不起作用?
还有其他解决方案吗?
答案 0 :(得分:0)
尝试使用此示例并更正您的代码:
<?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);
?>
如果您想拥有多维数组模式,请参阅: