PHP: 如何提取base64编码的消息?

PHP: how to pull base64 encoded messages?

我有一些基本的原始 base64 编码电子邮件,我想将其解码并转换为 PDF 格式。我 运行 遇到的问题是 $str 变量。那行代码是我所有电子邮件中的前 76 个字符,但我想不出将其用作扫描/收集/收集其余加密代码的起始基础。

所以基本上 $str 是起点,但是还有 1000 多行 base64 加密编码,我想说,如果你找到这个,然后开始提取代码的所有其余部分。我查看了 strpos 和 substr,但它们使用直接数值。是否可以使用字符作为起始位置?

总结一下:我基本上想说的是,如果您在文档中找到 $str,请从找到它的位置开始复制其余代码。

$str = "JVBERi0xLjcKJeTjz9IKNCAwIG9iago8PC9MZW5ndGggMyAwIFIvRmlsdGVy";

$pdf_base64 = "base64pdf.txt";
//Get File content from txt file
$pdf_base64_handler = fopen($pdf_base64,'r');
$pdf_content = fread ($pdf_base64_handler,filesize($pdf_base64));

if (strpos($pdf_content, $str) !== false) {
    echo 'true';
}


fclose ($pdf_base64_handler);
//Decode pdf content
$pdf_decoded = base64_decode ($pdf_content);
//Write data back to pdf file
$pdf = fopen ('test.pdf','w');
fwrite ($pdf, $pdf_decoded);
//close output file
fclose ($pdf);
echo 'Done';

以下将 return $str 之后 $pdf_content 中的所有内容,包括 $str.

if (strpos($pdf_content, $str) !== false) {
   $foundContent = substr($pdf_content, strpos($pdf_content, $str));
}

strpos会return大海捞针($str)开始的数值($str),然后就可以拔出来了乌丁 substr.