I’ve been having a (hopefully stupid) issue, and I was wondering if anyone could help.
I’m trying to determine if a string begins with "
, i.e.:
"-------- Original Message
I’ve tried everything–strpos($str, '"') === 0
, strpos(html_entity_decode($str), '"') === 0
, but, no matter what, I’m always finding that strpos(***, '"')
is false–not 0.
There’s more context here (parsing csv rows from a webform, trying to find where a quoted message begins), but I’m coming up empty handed.
I’m using php 7. Coming from a JS/TS background, so some of these nuances might just be going over my head.
Does anyone have any intuition as to what might be going on? I can provide code/more context if need-be. Tried staring this down for a few hours last night, but no dice.
Advertisement
Answer
perhaps this can help… function htmlspecialchars_decode converts " into a quotation mark
<?php $str = ""--------"; 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