Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将perl正则表达式转换为php时,无法获得与php等效的代码_Php_Perl - Fatal编程技术网

将perl正则表达式转换为php时,无法获得与php等效的代码

将perl正则表达式转换为php时,无法获得与php等效的代码,php,perl,Php,Perl,我已经给出了一个将Perl代码转换为PHP代码的任务 在进行转换时,我得到了一个Perl语法的正则表达式&正则表达式的工作就像我们将动态计数传递给表达式,在动态计数之后,它会将一个标记添加到字符串中。我想在PHP中实现同样的功能,但我无法在PHP中使用preg_replace进行转换 Perl代码: $msg = 'Testing a string testing it again Testing'; $count =7; $msg =~ s/([A-Za-z0-9\_\

我已经给出了一个将Perl代码转换为PHP代码的任务

在进行转换时,我得到了一个Perl语法的正则表达式&正则表达式的工作就像我们将动态计数传递给表达式,在动态计数之后,它会将一个标记添加到字符串中。我想在PHP中实现同样的功能,但我无法在PHP中使用preg_replace进行转换

Perl代码:

    $msg = 'Testing a string testing it again Testing';
    $count =7;
    $msg =~ s/([A-Za-z0-9\_\-\=\.]{$count})/$1<wbr>\n/ig;

    print $msg;

    Its Output is 

    Testing<wbr>                                                                                                                                                                                                              
    a string testing<wbr>                                                                                                                                                                                                    
    it again Testing<wbr> 
$msg='testingastring再次测试它Testing';
$count=7;
$msg=~s/([A-Za-z0-9\\-\=\.]{$count})/$1\n/ig;
打印$msg;
它的产量是
测试
字符串测试
它再次测试

有人能帮我完成这件事吗?那将是一个很大的帮助。

这可能就是你想要的

$msg = preg_replace('/([A-Za-z0-9\_\-\=\.]{' . $count . '})/i', '\1<wbr>' . "\n", $msg);
$msg=preg\u replace('/([A-Za-z0-9\\\-\=\.]{.$count.})/i'.\1'.\n'.$msg);

您可以轻松地在上测试PHP正则表达式(请参见链接下的此表达式)。

您被困在哪一部分?可能是@user3381968的副本。请您接受答案,而不仅仅是投票?谢谢