Hi,
Ok, I’m trying to search forward in a string for the next non-whitespace character. The old school way is pretty standard but I’m looking for a better or, shall we say, a method more inline with native PHP advantages.
There’s a lot online, and please, don’t think I’ve not searched, but most of the junk I’ve tried to wade through contains too many assumptions. Either the OP wasn’t as completely clear, or as is more common, writer’s tend to assume facts not in evidence.
Here’s my task,
I’ve got some character data held in a big string. Say I’m at position 900 and I’ve moved forward into a block of whitespace that I need to walk past to find the next non-whitespace character. Now I’ve never completely gotten my head wrapped around RegEx expressions and was not really sure this is the way to go since almost EVERY discussion revolves primarily around determining whether or not a match is present, but I recently found the PREG_OFFSET_CAPTURE flag which is precisely what I need.
At its simplest, I’ve tried,
[php]
if (preg_match(’[^\s]’, $configcpp, $m, PREG_OFFSET_CAPTURE, $tpos)) {
EchoLog("…Next Char found at [{$m[0][1]}]");
} else {
EchoLog('...preg_match FAILED');
}
[/php]
but this always fails. Surely, this is a common task. Especially in language parsing. Hell, I don’t know anymore, with today’s php I’d not be surprised if an entire text file could be exploded into a array of non-whitespace character blocks in one line!
Thanks for any thoughts.