Find the boundary of a word that starts åäö
This is how you find a whole word by its boundary when the word is starting with åäö. The usual boundary expression can handle if Swedish characters is in the string but not if it starts (or ends) the word. That means that a word like "öknen" can't be found but a word like "behöver" will be found.
<?php
$text = "I öknen behöver man vatten";
$keyword = "öknen";
//$keyword = "behöver";
?>This is the usual boundary expression
<?php
preg_match("/\b".$keyword."\b/ui", $text, $matches, PREG_OFFSET_CAPTURE);
?>This solution solves boundary expression for initial Swedish characters
<?php
preg_match("/(?<=[^\p{L}\p{N}_]|^){$keyword}(?=[^\p{L}\p{N}_]|$)/ui", $text, $matches, PREG_OFFSET_CAPTURE);
?>This expression finds all exact matches of keyword
<?php
preg_match_all("/(^|[^\p{L}])$keyword([^\p{L}]|$)/ui", $text, $exact_matches, PREG_OFFSET_CAPTURE);
?>This preg_match expression finds the end of all sentences, based on the position of punctation point.
<?php
preg_match_all("/\./ui", $text, $exact_matches, PREG_OFFSET_CAPTURE);
?>Knowledge keywords:
