繁体   English   中英

在字符串中查找 " 的索引

[英]Finding the index of " in a string

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

我正在尝试确定一个字符串是否以"开头。 , IE:

"-------- Original Message

我已经尝试了一切strpos($str, '"') === 0 , strpos(html_entity_decode($str), '"') === 0 ,但是,无论如何,我总是发现strpos(***, '"')是假的——不是 0。

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

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

有没有人对可能发生的事情有任何直觉? 如果需要,我可以提供代码/更多上下文。 昨晚试着盯着这个看几个小时,但没有骰子。

也许这可以帮助... function 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"; 
?>

Output:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM