在字符串中查找 " 的索引

Finding the index of " in a string

我遇到了一个(希望是愚蠢的)问题,我想知道是否有人可以提供帮助。

我正在尝试确定字符串是否以 " 开头,即:

"-------- Original Message

我已经尝试了所有方法--strpos($str, '"') === 0strpos(html_entity_decode($str), '"') === 0,但是无论如何,我总是发现 strpos(***, '"') 是错误的--而不是 0。

这里有更多上下文(从网络表单解析 csv 行,试图找到引用消息的开始位置),但我空手而归。

我正在使用 php 7。来自 JS/TS 背景,所以其中一些细微差别可能只是我的头脑。

有没有人对可能发生的事情有任何直觉?如果需要,我可以提供 code/more 上下文。昨晚试着盯着它看了几个小时,但没有成功。

也许这可以帮助...函数 htmlspecialchars_decode 将 "放入引号

<?php
$str = "&quot;--------";
echo "Position is: ";
echo strpos(htmlspecialchars_decode($str), '"'); 
echo "\n";
echo "Is quotation mark at the beginning?";
echo strpos(htmlspecialchars_decode($str), '"')==0; 
echo "\n"; 
?>

输出:

Position is: 0
Is quotation mark at the beginning? 1