首页 > 解决方案 > PHP:在 RTF 中用 str_replace 替换不一致

问题描述

我正在使用 PHP 和 str_replace 函数来替换(在这种情况下删除)RTF 文件中的一些代码。它可以很好地替换 RTF 文件中的一些代码块,但其他代码块没有替换,我不知道为什么。

我正在尝试使用此功能从 RTF 文件中删除段落:

$document = str_replace('CODE-TO-REMOVE-GOES-HERE', '', $document);

此代码工作正常:

$document = str_replace('\par }\pard\plain \ltrpar\qc \li0\ri0\sl480\slmult1\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid5841714 \rtlch\fcs1 \af0\afs22\alang1025 \ltrch\fcs0 \f31506\fs22\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {
\rtlch\fcs1 \ab\af0\afs24 \ltrch\fcs0 \b\f0\fs24\insrsid5841714\charrsid5841714 BOLDED CENTERED HEADING}{\rtlch\fcs1 \ab\af0\afs24 \ltrch\fcs0 \b\f0\fs24\insrsid5841714 ', '', $document);

但由于某种原因,本节没有:

$document = str_replace('\par {\listtext\pard\plain\ltrpar \s15 \rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid5841714 \hich\af0\dbch\af0\loch\f0 5.\tab}}\pard\plain \ltrpar\s15\ql \fi720\li0\ri0\sl480\slmult1
\widctlpar\wrapdefault\aspalpha\aspnum\faauto\ls2\adjustright\rin0\lin0\itap0\pararsid3021950\contextualspace \rtlch\fcs1 \af0\afs22\alang1025 \ltrch\fcs0 \f31506\fs22\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 
\f0\fs24\insrsid5841714 This text in the paragraph open(s) non-broken put(s) this is additional sample text that will not remove (CPL \'a7\'a7
 100.00[1][x]; 100.23[3])', '', $document);

第一个代码块(删除 BOLDED CENTERED HEADING)工作正常并删除该行 RTF,但第二个代码块试图删除 BOLDED CENTERED HEADING 正下方的段落,没有删除或似乎做任何事情。

谁能发现这两者之间的区别导致一个替换而不是另一个?

编辑/更新:所有文件(rtf、html、php)都以 UTF-8 编码(根据 Notepad++)。php.inidefault_charset = "UTF-8"和 .htaccess 有AddDefaultCharset UTF-8

这是此时的整个 PHP 文件。这只是一个测试,看看这是否可能。它从表单中获取输入并将它们插入到 RTF 中,但也尝试删除一些段落——这是我失败的部分。我开始认为它与括号有关。

<?php


header('Content-Type: text/html; charset=UTF-8');

mb_internal_encoding('UTF-8'); 
mb_http_output('UTF-8'); 
mb_http_input('UTF-8'); 
mb_regex_encoding('UTF-8'); 



if (isset($_POST['prp'])){


$document = file_get_contents("city-omnibus-template.rtf");

$defendantphp = $_POST['defendanthtml'];
$judgephp = $_POST['judgehtml'];
$crnumphp = $_POST['crnumhtml'];
$adaphp = $_POST['adahtml'];
$attyphp = $_POST['attyhtml'];
$motargdatephp = $_POST['motargdatehtml'];
$deftodisphp = $_POST['deftodishtml'];
$crimedatephp = $_POST['crimedatehtml'];
$motsigndatephp = $_POST['motsigndatehtml'];
$accusdatephp = $_POST['accusdatehtml'];
$allcrimeschargedphp = $_POST['allcrimeschargedhtml'];

if (empty($fax)){
$fax='-';
    }

$document = str_replace("#defendantword", $defendantphp, $document);
$document = str_replace("#judgeword", $judgephp, $document);
$document = str_replace("#crnumword", $crnumphp, $document);
$document = str_replace("#adaword", $adaphp, $document);
$document = str_replace("#attyword", $attyphp, $document);
$document = str_replace("#motargdateword", $motargdatephp, $document);
$document = str_replace("#deftodisword", $deftodisphp, $document);
$document = str_replace("#crimedateword", $crimedatephp, $document);
$document = str_replace("#motargdateword", $motsigndatephp, $document);
$document = str_replace("#accusdateword", $accusdatephp, $document);
$document = str_replace("#allcrimeschargedword", $allcrimeschargedphp, $document);


// this one works
$document = str_replace('\par }\pard\plain \ltrpar\qc \li0\ri0\sl480\slmult1\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid5841714 \rtlch\fcs1 \af0\afs22\alang1025 \ltrch\fcs0 \f31506\fs22\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {
\rtlch\fcs1 \ab\af0\afs24 \ltrch\fcs0 \b\f0\fs24\insrsid5841714\charrsid5841714 PROSECUTION BY INFORMATION}{\rtlch\fcs1 \ab\af0\afs24 \ltrch\fcs0 \b\f0\fs24\insrsid5841714 ', '', $document);

//this one does not
$document = str_replace('\par {\listtext\pard\plain\ltrpar \s15 \rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid5841714 \hich\af0\dbch\af0\loch\f0 5.\tab}}\pard\plain \ltrpar\s15\ql \fi720\li0\ri0\sl480\slmult1
\widctlpar\wrapdefault\aspalpha\aspnum\faauto\ls2\adjustright\rin0\lin0\itap0\pararsid3021950\contextualspace \rtlch\fcs1 \af0\afs22\alang1025 \ltrch\fcs0 \f31506\fs22\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 
\f0\fs24\insrsid5841714 The defendant has entered a plea of not guilty to the charge(s) alleged in the accusatory instrument. To the extent that any of 
the pending non-felony charge(s) are based upon a hearsay complaint, rather than a non-hearsay information, the defendant hereby refuses to consent to be prosecuted by such complaint and demands to be prosecuted by a non-hearsay information (CPL \'a7\'a7
 170.10[4][d]; 170.65[1])', '', $document);


header("Content-type: application/msword");
header("Content-disposition: inline; filename=$defendantphp-Omnibus.doc");
header("Content-length: ".strlen($document));
echo iconv('UTF-8', 'ISO-8859-1', $document);

}
?>

链接到 RTF 文件: https ://drive.google.com/open?id=11sH7RnpuQ1YJq8GFnhclN8kxxBB_SIlo

更多编辑:

解决方法 - 这可能是一种糟糕的方法,但如果我删除括号 ( ) 和节符号 § (在 RTF 中用##118## 之类的代码替换它),它似乎可以工作 - 然后做另一个 str_replace 将代码中的(未删除的)立场更改回括号或节符号。但如果有更好的方法,我仍在寻找它。

取得了重大进展 - 一部分仍然无法正常 工作 除了最后一部分无法替换外,其他所有内容都在正常工作。我唯一能说的是它有一个嵌套列表,但我不知道为什么这很重要。

这是不会替换的块:

$search3 = <<<'EOL'
\par }\pard\plain \ltrpar\qc \li0\ri0\sl480\slmult1\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid5841714 \rtlch\fcs1 \af0\afs22\alang1025 \ltrch\fcs0 \f31506\fs22\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {
\rtlch\fcs1 \ab\af0\afs24 \ltrch\fcs0 \b\f0\fs24\insrsid5841714\charrsid5841714 DEFECTIVE INFORMATION}{\rtlch\fcs1 \ab\af0\afs24 \ltrch\fcs0 \b\f0\fs24\insrsid5841714 
\par {\listtext\pard\plain\ltrpar \s15 \rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid5841714 \hich\af0\dbch\af0\loch\f0 6.\tab}}\pard\plain \ltrpar\s15\ql \fi720\li0\ri0\sl480\slmult1
\widctlpar\wrapdefault\aspalpha\aspnum\faauto\ls2\adjustright\rin0\lin0\itap0\pararsid3021950\contextualspace \rtlch\fcs1 \af0\afs22\alang1025 \ltrch\fcs0 \f31506\fs22\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 
\f0\fs24\insrsid5841714 The defendant hereby moves, pursuant to CPL }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 \'a7}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid5841714  170.30}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 
\f0\fs24\insrsid3021950 , to dismiss the accusatory or count charging the offense}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 (}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid3021950 s}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 
\f0\fs24\insrsid14111911 )}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid3021950  of }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13307306 #deftodisword on the ground that it is defective. An accusatory instrument }{\rtlch\fcs1 \af0\afs24 
\ltrch\fcs0 \f0\fs24\insrsid14111911 (}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13307306 or count thereof}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 )}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13307306 
 is defective if it is not sufficient on it\rquote s face pursuant to the requirements of CPL }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 \'a7}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13307306  100.40 }{\rtlch\fcs1 \af0\afs24 
\ltrch\fcs0 \f0\fs24\insrsid14111911 (}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13307306 CPL }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 \'a7}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13307306  170.35[1][a]}{
\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 )}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13307306 ;}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid5841714 
\par {\listtext\pard\plain\ltrpar \s15 \rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid13307306 \hich\af0\dbch\af0\loch\f0 7.\tab}}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13307306 
To be sufficient on its face, a local criminal court accusatory which purports to qualify as an \'93information\'94 must satisfy the requirements set forth below:
\par {\listtext\pard\plain\ltrpar \s15 \rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid13307306 \hich\af0\dbch\af0\loch\f0 a.\tab}}\pard \ltrpar
\s15\ql \fi-360\li1440\ri0\widctlpar\wrapdefault\aspalpha\aspnum\faauto\ls2\ilvl1\adjustright\rin0\lin1440\itap0\pararsid13446461\contextualspace {\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13307306 An information \'93
must contain an accusatory part and a factual part. The complainant\rquote s verification of the instrument is deemed to apply only to the }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461 factual part thereof and not to the accusatory part.
\'94 }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 (}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461 CPL }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 \'a7}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 
\f0\fs24\insrsid13446461  100.15[1]}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 )}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461 ;\line }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13307306 
\par {\listtext\pard\plain\ltrpar \s15 \rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid13446461 \hich\af0\dbch\af0\loch\f0 b.\tab}}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461 The accusatory part \'93must designate the offense or offenses charged\'94 }{
\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 (}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461 CPL }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 \'a7}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461 
 100.15[2]}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 )}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461 ;\line 
\par {\listtext\pard\plain\ltrpar \s15 \rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid13446461 \hich\af0\dbch\af0\loch\f0 c.\tab}The factual part \'93
must contain a statement of the complainant alleging facts of an evidentiary character supporting or tending to support the charges\'94 }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 (}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 
\f0\fs24\insrsid13446461 CPL }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 \'a7}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461  100.15[3]; see also }{\rtlch\fcs1 \ai\af0\afs24 \ltrch\fcs0 
\i\f0\fs24\insrsid13446461\charrsid13446461 People v. Dumas}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461 , 68 NY2d [1986]}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 )}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 
\f0\fs24\insrsid13446461 ;\line 
\par {\listtext\pard\plain\ltrpar \s15 \rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid13446461 \hich\af0\dbch\af0\loch\f0 d.\tab}The allegations of the factual part, together with those of any supporting depositions which may accompany it, must \'93
provide reasonable cause to believe that the defendant committed the offense charged in the accusatory part of the information\'94 }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 (}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 
\f0\fs24\insrsid13446461 CPL }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 \'a7}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461  100.40[1][b]}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 )}{\rtlch\fcs1 
\af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461 ;\line 
\par {\listtext\pard\plain\ltrpar \s15 \rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid13446461 \hich\af0\dbch\af0\loch\f0 e.\tab}Finally, every element of the offense charged and the defendant\rquote s commission thereof must be established by \'93
non-hearsay allegations of the factual part of the information and/or of any supporting depositions\'94 }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 (}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461 CPL }{\rtlch\fcs1 
\af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 \'a7}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461  100.40[1][c]; }{\rtlch\fcs1 \ai\af0\afs24 \ltrch\fcs0 \i\f0\fs24\insrsid13446461\charrsid13446461 see also People v. Alejandro}{\rtlch\fcs1 
\af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461 , 70 NY2d 133 [1987]}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 )}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461 .
\par }\pard\plain \ltrpar\ql \li0\ri0\sl480\slmult1\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid13446461 \rtlch\fcs1 \af0\afs22\alang1025 \ltrch\fcs0 \f31506\fs22\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {
\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461 
EOL;
$document = str_replace($search3, '', $document);

这是 PHP 的更新版本,其中包括 fyrye 的修复:

<?php

header('Content-Type: text/html; charset=UTF-8');


if (isset($_POST['prp'])){


$document = file_get_contents("city-omnibus-template.rtf");

// not sure what this does - changes all line endings?
$document = str_replace(["\r\n", "\n"], ["\n", "\r\n"], $document);


$defendantphp = $_POST['defendanthtml'];
$judgephp = $_POST['judgehtml'];
$crnumphp = $_POST['crnumhtml'];
$adaphp = $_POST['adahtml'];
$attyphp = $_POST['attyhtml'];
$motargdatephp = $_POST['motargdatehtml'];
$deftodisphp = $_POST['deftodishtml'];
$crimedatephp = $_POST['crimedatehtml'];
$motsigndatephp = $_POST['motsigndatehtml'];
$accusdatephp = $_POST['accusdatehtml'];
$allcrimeschargedphp = $_POST['allcrimeschargedhtml'];

if (empty($fax)){
$fax='-';
    }

$document = str_replace("#defendantword", $defendantphp, $document);
$document = str_replace("#judgeword", $judgephp, $document);
$document = str_replace("#crnumword", $crnumphp, $document);
$document = str_replace("#adaword", $adaphp, $document);
$document = str_replace("#attyword", $attyphp, $document);
$document = str_replace("#motargdateword", $motargdatephp, $document);
$document = str_replace("#deftodisword", $deftodisphp, $document);
$document = str_replace("#crimedateword", $crimedatephp, $document);
$document = str_replace("#motargdateword", $motsigndatephp, $document);
$document = str_replace("#accusdateword", $accusdatephp, $document);
$document = str_replace("#allcrimeschargedword", $allcrimeschargedphp, $document);


// this one is working now
$search1 = <<<'EOL'
\par }\pard\plain \ltrpar\qc \li0\ri0\sl480\slmult1\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid5841714 \rtlch\fcs1 \af0\afs22\alang1025 \ltrch\fcs0 \f31506\fs22\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {
\rtlch\fcs1 \ab\af0\afs24 \ltrch\fcs0 \b\f0\fs24\insrsid5841714\charrsid5841714 PROSECUTION BY INFORMATION}{\rtlch\fcs1 \ab\af0\afs24 \ltrch\fcs0 \b\f0\fs24\insrsid5841714 
EOL;
$document = str_replace($search1, '', $document);


// this one is also working now - thanks fyrye
$search2 = <<<'EOL'
\par {\listtext\pard\plain\ltrpar \s15 \rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid5841714 \hich\af0\dbch\af0\loch\f0 5.\tab}}\pard\plain \ltrpar\s15\ql \fi720\li0\ri0\sl480\slmult1
\widctlpar\wrapdefault\aspalpha\aspnum\faauto\ls2\adjustright\rin0\lin0\itap0\pararsid3021950\contextualspace \rtlch\fcs1 \af0\afs22\alang1025 \ltrch\fcs0 \f31506\fs22\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 
\f0\fs24\insrsid5841714 The defendant has entered a plea of not guilty to the charge}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 (}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid5841714 s}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 
\f0\fs24\insrsid14111911 )}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid5841714  alleged in the accusatory instrument. To the extent that any of the pending non-felony charge}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 (}{
\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid5841714 s}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 )}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid5841714 
 are based upon a hearsay complaint, rather than a non-hearsay information, the defendant hereby refuses to consent to be prosecuted by such complaint and demands to be prosecuted by a non-hearsay information }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 
\f0\fs24\insrsid14111911 (}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid5841714 CPL }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 \'a7\'a7}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid5841714  170.10[4][d]; 170.65[1]}{
\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 )}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid5841714 
EOL;
$document = str_replace($search2, '', $document);

// leaving this in even though it doesn't seem to make a difference
$search3 = str_replace(["\r\n", "\n"], ["\n", "\r\n"], $search3);




// This one still not replacing - most complicated

$search3 = <<<'EOL'
\par }\pard\plain \ltrpar\qc \li0\ri0\sl480\slmult1\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid5841714 \rtlch\fcs1 \af0\afs22\alang1025 \ltrch\fcs0 \f31506\fs22\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {
\rtlch\fcs1 \ab\af0\afs24 \ltrch\fcs0 \b\f0\fs24\insrsid5841714\charrsid5841714 DEFECTIVE INFORMATION}{\rtlch\fcs1 \ab\af0\afs24 \ltrch\fcs0 \b\f0\fs24\insrsid5841714 
\par {\listtext\pard\plain\ltrpar \s15 \rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid5841714 \hich\af0\dbch\af0\loch\f0 6.\tab}}\pard\plain \ltrpar\s15\ql \fi720\li0\ri0\sl480\slmult1
\widctlpar\wrapdefault\aspalpha\aspnum\faauto\ls2\adjustright\rin0\lin0\itap0\pararsid3021950\contextualspace \rtlch\fcs1 \af0\afs22\alang1025 \ltrch\fcs0 \f31506\fs22\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 
\f0\fs24\insrsid5841714 The defendant hereby moves, pursuant to CPL }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 \'a7}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid5841714  170.30}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 
\f0\fs24\insrsid3021950 , to dismiss the accusatory or count charging the offense}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 (}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid3021950 s}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 
\f0\fs24\insrsid14111911 )}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid3021950  of }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13307306 #deftodisword on the ground that it is defective. An accusatory instrument }{\rtlch\fcs1 \af0\afs24 
\ltrch\fcs0 \f0\fs24\insrsid14111911 (}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13307306 or count thereof}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 )}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13307306 
 is defective if it is not sufficient on it\rquote s face pursuant to the requirements of CPL }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 \'a7}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13307306  100.40 }{\rtlch\fcs1 \af0\afs24 
\ltrch\fcs0 \f0\fs24\insrsid14111911 (}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13307306 CPL }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 \'a7}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13307306  170.35[1][a]}{
\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 )}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13307306 ;}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid5841714 
\par {\listtext\pard\plain\ltrpar \s15 \rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid13307306 \hich\af0\dbch\af0\loch\f0 7.\tab}}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13307306 
To be sufficient on its face, a local criminal court accusatory which purports to qualify as an \'93information\'94 must satisfy the requirements set forth below:
\par {\listtext\pard\plain\ltrpar \s15 \rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid13307306 \hich\af0\dbch\af0\loch\f0 a.\tab}}\pard \ltrpar
\s15\ql \fi-360\li1440\ri0\widctlpar\wrapdefault\aspalpha\aspnum\faauto\ls2\ilvl1\adjustright\rin0\lin1440\itap0\pararsid13446461\contextualspace {\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13307306 An information \'93
must contain an accusatory part and a factual part. The complainant\rquote s verification of the instrument is deemed to apply only to the }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461 factual part thereof and not to the accusatory part.
\'94 }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 (}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461 CPL }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 \'a7}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 
\f0\fs24\insrsid13446461  100.15[1]}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 )}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461 ;\line }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13307306 
\par {\listtext\pard\plain\ltrpar \s15 \rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid13446461 \hich\af0\dbch\af0\loch\f0 b.\tab}}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461 The accusatory part \'93must designate the offense or offenses charged\'94 }{
\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 (}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461 CPL }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 \'a7}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461 
 100.15[2]}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 )}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461 ;\line 
\par {\listtext\pard\plain\ltrpar \s15 \rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid13446461 \hich\af0\dbch\af0\loch\f0 c.\tab}The factual part \'93
must contain a statement of the complainant alleging facts of an evidentiary character supporting or tending to support the charges\'94 }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 (}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 
\f0\fs24\insrsid13446461 CPL }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 \'a7}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461  100.15[3]; see also }{\rtlch\fcs1 \ai\af0\afs24 \ltrch\fcs0 
\i\f0\fs24\insrsid13446461\charrsid13446461 People v. Dumas}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461 , 68 NY2d [1986]}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 )}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 
\f0\fs24\insrsid13446461 ;\line 
\par {\listtext\pard\plain\ltrpar \s15 \rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid13446461 \hich\af0\dbch\af0\loch\f0 d.\tab}The allegations of the factual part, together with those of any supporting depositions which may accompany it, must \'93
provide reasonable cause to believe that the defendant committed the offense charged in the accusatory part of the information\'94 }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 (}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 
\f0\fs24\insrsid13446461 CPL }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 \'a7}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461  100.40[1][b]}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 )}{\rtlch\fcs1 
\af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461 ;\line 
\par {\listtext\pard\plain\ltrpar \s15 \rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid13446461 \hich\af0\dbch\af0\loch\f0 e.\tab}Finally, every element of the offense charged and the defendant\rquote s commission thereof must be established by \'93
non-hearsay allegations of the factual part of the information and/or of any supporting depositions\'94 }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 (}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461 CPL }{\rtlch\fcs1 
\af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 \'a7}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461  100.40[1][c]; }{\rtlch\fcs1 \ai\af0\afs24 \ltrch\fcs0 \i\f0\fs24\insrsid13446461\charrsid13446461 see also People v. Alejandro}{\rtlch\fcs1 
\af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461 , 70 NY2d 133 [1987]}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 )}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461 .
\par }\pard\plain \ltrpar\ql \li0\ri0\sl480\slmult1\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid13446461 \rtlch\fcs1 \af0\afs22\alang1025 \ltrch\fcs0 \f31506\fs22\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {
\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461 
EOL;
$document = str_replace($search3, '', $document);


header("Content-type: application/msword");
header("Content-disposition: inline; filename=$defendantphp-Omnibus.doc");
echo ($document);
}
?>

标签: phprtf

解决方案


在 php 中,反斜杠是一个转义序列,与单引号或双引号封装无关。

由于您使用的是单引号封装,因此您的搜索参数为:

\'a7\'a7

只是转义单引号字符,导致:

'a7'a7

但实际上是\'a7\'a7在 RTF 文件中。

要解决此问题,您需要使用以下命令转义反斜杠和引号字符:

\\\'a7\\\'a7

这将转义反斜杠和单引号导致:

\'a7\'a7

此外,最好的做法是始终通过使用双反斜杠来转义文字反斜杠\\,以避免出现您遇到的复杂情况。

要指定文字单引号,请使用反斜杠 ( \) 对其进行转义。要指定文字反斜杠,请将其加倍 ( \\)。所有其他反斜杠实例将被视为文字反斜杠:这意味着您可能习惯使用的其他转义序列,例如 \r 或 \n,将按指定的字面输出而不是具有任何特殊含义。[原文如此]

$document = str_replace([
    // this one works
    '\\par }\\pard\\plain \\ltrpar\\qc \\li0\\ri0\\sl480\\slmult1\\widctlpar\\wrapdefault\\aspalpha\\aspnum\\faauto\\adjustright\\rin0\\lin0\\itap0\\pararsid5841714 \\rtlch\\fcs1 \\af0\\afs22\\alang1025 \\ltrch\\fcs0 \\f31506\\fs22\\lang1033\\langfe1033\\cgrid\\langnp1033\\langfenp1033 {
\\rtlch\\fcs1 \\ab\\af0\\afs24 \\ltrch\\fcs0 \\b\\f0\\fs24\\insrsid5841714\\charrsid5841714 PROSECUTION BY INFORMATION}{\\rtlch\\fcs1 \\ab\\af0\\afs24 \\ltrch\\fcs0 \\b\\f0\\fs24\\insrsid5841714 ',
    //this one does not (it does now...)
    '\\par {\\listtext\\pard\\plain\\ltrpar \\s15 \\rtlch\\fcs1 \\af0 \\ltrch\\fcs0 \\insrsid5841714 \\hich\\af0\\dbch\\af0\\loch\\f0 5.\\tab}}\\pard\\plain \\ltrpar\\s15\\ql \\fi720\\li0\\ri0\\sl480\\slmult1
\\widctlpar\\wrapdefault\\aspalpha\\aspnum\\faauto\\ls2\\adjustright\\rin0\\lin0\\itap0\\pararsid3021950\\contextualspace \\rtlch\\fcs1 \\af0\\afs22\\alang1025 \\ltrch\\fcs0 \\f31506\\fs22\\lang1033\\langfe1033\\cgrid\\langnp1033\\langfenp1033 {\\rtlch\\fcs1 \\af0\\afs24 \\ltrch\\fcs0 
\\f0\\fs24\\insrsid5841714 The defendant has entered a plea of not guilty to the charge(s) alleged in the accusatory instrument. To the extent that any of 
the pending non-felony charge(s) are based upon a hearsay complaint, rather than a non-hearsay information, the defendant hereby refuses to consent to be prosecuted by such complaint and demands to be prosecuted by a non-hearsay information (CPL \\\'a7\\\'a7
 170.10[4][d]; 170.65[1])',
], '', $document);

或者,为了避免转义反斜杠和引号的需要,您可以将搜索参数转换为NOWDOC语法。

该构造非常适合嵌入 PHP 代码或其他大型文本块而无需转义。[原文如此]

使用 nowdoc 语法,反斜杠总是按字面意思处理。

$search = <<<'EOL'
\par }\pard\plain \ltrpar\qc \li0\ri0\sl480\slmult1\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid5841714 \rtlch\fcs1 \af0\afs22\alang1025 \ltrch\fcs0 \f31506\fs22\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {
\rtlch\fcs1 \ab\af0\afs24 \ltrch\fcs0 \b\f0\fs24\insrsid5841714\charrsid5841714 PROSECUTION BY INFORMATION}{\rtlch\fcs1 \ab\af0\afs24 \ltrch\fcs0 \b\f0\fs24\insrsid5841714 
EOL;
$document = str_replace($search, '', $document);

$search = <<<'EOL'
\par {\listtext\pard\plain\ltrpar \s15 \rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid5841714 \hich\af0\dbch\af0\loch\f0 5.\tab}}\pard\plain \ltrpar\s15\ql \fi720\li0\ri0\sl480\slmult1
\widctlpar\wrapdefault\aspalpha\aspnum\faauto\ls2\adjustright\rin0\lin0\itap0\pararsid3021950\contextualspace \rtlch\fcs1 \af0\afs22\alang1025 \ltrch\fcs0 \f31506\fs22\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 
\f0\fs24\insrsid5841714 The defendant has entered a plea of not guilty to the charge(s) alleged in the accusatory instrument. To the extent that any of 
the pending non-felony charge(s) are based upon a hearsay complaint, rather than a non-hearsay information, the defendant hereby refuses to consent to be prosecuted by such complaint and demands to be prosecuted by a non-hearsay information (CPL \'a7\'a7
 170.10[4][d]; 170.65[1])
EOL;
$document = str_replace($search, '', $document);

结果文件:https ://drive.google.com/file/d/1Qw8C1S0AAjgZg8xEy5onmSCptNvRGmuh/view?usp=sharing

确保您的 PHP 编辑器使用 DOS 行尾 CRLF,就像您的 RTF 文件使用的那样CRLF

为确保正确的行结尾,您可以使用 将搜索参数从 DOS 转换为 UNIX,然后从 UNIX 转换为 DOS。

$search = <<<'EOL'
EOL;
$search = str_replace(["\r\n", "\n"], ["\n", "\r\n"], $search);

这用于在执行替换之前修复搜索文本。不要在文档字符串上使用。


附加建议

您不需要使用echo iconv('UTF-8', 'ISO-8859-1', $document);,因为您的源文档位于UTF-8. iconv如果无法将 UTF-8 编码字符转换为 ISO-8859-1,则使用可能会导致复杂性。

你的用法mb_http_input('UTF-8');不正确。用于检索指定类型的输入编码。参数应该是 GET的type“G”、POST 的“P”、COOKIE 的“C”、字符串的“S”、列表的“L”和整个列表的“I”之一(将返回数组)。

除非您的服务器配置发生更改,否则 PHP 在 5.6+ 版本中默认使用 UTF-8。因此,您可以删除多字节字符串函数。

//mb_internal_encoding('UTF-8'); 
//mb_http_output('UTF-8'); 
//mb_regex_encoding('UTF-8'); 

您可以使用以下方法在执行此操作之前验证设置:

示例https://3v4l.org/bZukb

var_dump(array(
    mb_internal_encoding(),
    mb_http_output(),
    mb_regex_encoding(),
));

您还可以删除Content-Length标头,因为它们在大多数环境中通常是多余的,因为 Web 服务器在将响应发送给用户代理之前处理响应,并且包含它可能会导致某些用户代理出现问题,当长度与发送的实际内容。

//header("Content-length: ".strlen($document));

在您当前的脚本中,strlen正在处理UTF-8编码字符串,但响应是ISO-8859-1编码字符串。导致指定的Content-length标头大于实际响应。这可能会导致某些用户代理挂起期待额外的内容。


使用更新的范围进行编辑

您似乎更新了 RTF 内容,因为我找不到search3文本的几个部分。

但是,该问题似乎是由在应用搜索文本替换之前应用占位符替换( #deftodisword#judgeword#crnumword、等)引起的。#adaword

这会更改文档字符串的内容,导致您的搜索文本不再匹配。例如下面的行包含#deftodisword

\f0\fs24\insrsid14111911 )}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid3021950 of }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13307306 #deftodisword on the ground that it is defective. An accusatory instrument }{\rtlch\fcs1 \af0\afs24

要解决此问题,请在对文档执行搜索替换后替换占位符。

作为稍微提高性能的最后一个建议,您可以str_replace使用字符串数组来组合调用。

示例:https ://3v4l.org/TbFa4

//returns an array of the combined sanitized search texts
$search = str_replace(["\r\n", "\n"], ["\n", "\r\n"], [$search1, $search2, $search3]);

$document = str_replace($search, '', $document);

$document = str_replace(['#defendantword', '#judgeword'], [$defendantphp, $judgephp], $document);

完整示例:

$search1 = <<<'EOL'
\par }\pard\plain \ltrpar\qc \li0\ri0\sl480\slmult1\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid5841714 \rtlch\fcs1 \af0\afs22\alang1025 \ltrch\fcs0 \f31506\fs22\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {
\rtlch\fcs1 \ab\af0\afs24 \ltrch\fcs0 \b\f0\fs24\insrsid5841714\charrsid5841714 PROSECUTION BY INFORMATION}{\rtlch\fcs1 \ab\af0\afs24 \ltrch\fcs0 \b\f0\fs24\insrsid5841714 
EOL;
$search2 = <<<'EOL'
\par {\listtext\pard\plain\ltrpar \s15 \rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid5841714 \hich\af0\dbch\af0\loch\f0 5.\tab}}\pard\plain \ltrpar\s15\ql \fi720\li0\ri0\sl480\slmult1
\widctlpar\wrapdefault\aspalpha\aspnum\faauto\ls2\adjustright\rin0\lin0\itap0\pararsid3021950\contextualspace \rtlch\fcs1 \af0\afs22\alang1025 \ltrch\fcs0 \f31506\fs22\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 
\f0\fs24\insrsid5841714 The defendant has entered a plea of not guilty to the charge}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 (}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid5841714 s}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 
\f0\fs24\insrsid14111911 )}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid5841714  alleged in the accusatory instrument. To the extent that any of the pending non-felony charge}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 (}{
\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid5841714 s}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 )}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid5841714 
 are based upon a hearsay complaint, rather than a non-hearsay information, the defendant hereby refuses to consent to be prosecuted by such complaint and demands to be prosecuted by a non-hearsay information }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 
\f0\fs24\insrsid14111911 (}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid5841714 CPL }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 \'a7\'a7}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid5841714  170.10[4][d]; 170.65[1]}{
\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 )}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid5841714 
EOL;
$search3 = <<<'EOL'
\par }\pard\plain \ltrpar\qc \li0\ri0\sl480\slmult1\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid5841714 \rtlch\fcs1 \af0\afs22\alang1025 \ltrch\fcs0 \f31506\fs22\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {
\rtlch\fcs1 \ab\af0\afs24 \ltrch\fcs0 \b\f0\fs24\insrsid5841714\charrsid5841714 DEFECTIVE INFORMATION}{\rtlch\fcs1 \ab\af0\afs24 \ltrch\fcs0 \b\f0\fs24\insrsid5841714 
\par {\listtext\pard\plain\ltrpar \s15 \rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid5841714 \hich\af0\dbch\af0\loch\f0 6.\tab}}\pard\plain \ltrpar\s15\ql \fi720\li0\ri0\sl480\slmult1
\widctlpar\wrapdefault\aspalpha\aspnum\faauto\ls2\adjustright\rin0\lin0\itap0\pararsid3021950\contextualspace \rtlch\fcs1 \af0\afs22\alang1025 \ltrch\fcs0 \f31506\fs22\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 
\f0\fs24\insrsid5841714 The defendant hereby moves, pursuant to CPL }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 \'a7}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid5841714  170.30}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 
\f0\fs24\insrsid3021950 , to dismiss the accusatory or count charging the offense}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 (}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid3021950 s}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 
\f0\fs24\insrsid14111911 )}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid3021950  of }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13307306 #deftodisword on the ground that it is defective. An accusatory instrument }{\rtlch\fcs1 \af0\afs24 
\ltrch\fcs0 \f0\fs24\insrsid14111911 (}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13307306 or count thereof}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 )}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13307306 
 is defective if it is not sufficient on it\rquote s face pursuant to the requirements of CPL }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 \'a7}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13307306  100.40 }{\rtlch\fcs1 \af0\afs24 
\ltrch\fcs0 \f0\fs24\insrsid14111911 (}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13307306 CPL }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 \'a7}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13307306  170.35[1][a]}{
\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 )}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13307306 ;}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid5841714 
\par {\listtext\pard\plain\ltrpar \s15 \rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid13307306 \hich\af0\dbch\af0\loch\f0 7.\tab}}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13307306 
To be sufficient on its face, a local criminal court accusatory which purports to qualify as an \'93information\'94 must satisfy the requirements set forth below:
\par {\listtext\pard\plain\ltrpar \s15 \rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid13307306 \hich\af0\dbch\af0\loch\f0 a.\tab}}\pard \ltrpar
\s15\ql \fi-360\li1440\ri0\widctlpar\wrapdefault\aspalpha\aspnum\faauto\ls2\ilvl1\adjustright\rin0\lin1440\itap0\pararsid13446461\contextualspace {\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13307306 An information \'93
must contain an accusatory part and a factual part. The complainant\rquote s verification of the instrument is deemed to apply only to the }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461 factual part thereof and not to the accusatory part.
\'94 }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 (}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461 CPL }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 \'a7}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 
\f0\fs24\insrsid13446461  100.15[1]}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 )}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461 ;\line }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13307306 
\par {\listtext\pard\plain\ltrpar \s15 \rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid13446461 \hich\af0\dbch\af0\loch\f0 b.\tab}}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461 The accusatory part \'93must designate the offense or offenses charged\'94 }{
\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 (}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461 CPL }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 \'a7}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461 
 100.15[2]}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 )}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461 ;\line 
\par {\listtext\pard\plain\ltrpar \s15 \rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid13446461 \hich\af0\dbch\af0\loch\f0 c.\tab}The factual part \'93
must contain a statement of the complainant alleging facts of an evidentiary character supporting or tending to support the charges\'94 }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 (}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 
\f0\fs24\insrsid13446461 CPL }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 \'a7}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461  100.15[3]; see also }{\rtlch\fcs1 \ai\af0\afs24 \ltrch\fcs0 
\i\f0\fs24\insrsid13446461\charrsid13446461 People v. Dumas}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461 , 68 NY2d [1986]}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 )}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 
\f0\fs24\insrsid13446461 ;\line 
\par {\listtext\pard\plain\ltrpar \s15 \rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid13446461 \hich\af0\dbch\af0\loch\f0 d.\tab}The allegations of the factual part, together with those of any supporting depositions which may accompany it, must \'93
provide reasonable cause to believe that the defendant committed the offense charged in the accusatory part of the information\'94 }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 (}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 
\f0\fs24\insrsid13446461 CPL }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 \'a7}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461  100.40[1][b]}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 )}{\rtlch\fcs1 
\af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461 ;\line 
\par {\listtext\pard\plain\ltrpar \s15 \rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid13446461 \hich\af0\dbch\af0\loch\f0 e.\tab}Finally, every element of the offense charged and the defendant\rquote s commission thereof must be established by \'93
non-hearsay allegations of the factual part of the information and/or of any supporting depositions\'94 }{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 (}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461 CPL }{\rtlch\fcs1 
\af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 \'a7}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461  100.40[1][c]; }{\rtlch\fcs1 \ai\af0\afs24 \ltrch\fcs0 \i\f0\fs24\insrsid13446461\charrsid13446461 see also People v. Alejandro}{\rtlch\fcs1 
\af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461 , 70 NY2d 133 [1987]}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid14111911 )}{\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461 .
\par }\pard\plain \ltrpar\ql \li0\ri0\sl480\slmult1\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid13446461 \rtlch\fcs1 \af0\afs22\alang1025 \ltrch\fcs0 \f31506\fs22\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {
\rtlch\fcs1 \af0\afs24 \ltrch\fcs0 \f0\fs24\insrsid13446461 
EOL;

//ensure search texts PHP line endings match RTF content
$search = str_replace(["\r\n", "\n"], ["\n", "\r\n"], [$search1, $search2, $search3]);

//replace search texts
$document = str_replace($search, '', $document);

//replace placeholders
$document = str_replace(
    ['#defendantword', '#judgeword', '#crnumword', '#adaword', '#attyword', '#motargdateword', '#deftodisword', '#crimedateword', '#motargdateword', '#accusdateword', '#allcrimeschargedword'],
    [$defendantphp, $judgephp, $crnumphp, $adaphp, $attyphp, $motargdatephp, $deftodisphp, $crimedatephp, $motsigndatephp, $accusdatephp, $allcrimeschargedphp],
    $document
);

header('Content-type: application/msword');
header(sprintf('Content-disposition: inline; filename=%s-Omnibus.doc', $defendantphp));
echo $document;

推荐阅读