Answers

May 19, 2007 - 04:21 AM
From other forums and experts I've learned that there is no way to do what I wanted with a simple regex modifer.
However, I've found a solution that is not very complicated.
Here is a detailed description of my PHP approach:
// First I make a string of characters grouped together, which should be treated as equivalent
$equiv = "aàáâãäå,eéèêë,iìíîï,oòóôõö,uùúûü,yýÿ,nñ,cç";
// The groups are split into an array and each group is processed
$equiv = explode(",", $equiv);
foreach ($equiv as $e)
{
// If either of the characters of a group is found in my search term, they will be replaced by the
// entire group (in [] brackets) before matching the search term against the search result text
// I use the /u modifier because my document is utf-8 encoded
$term = preg_replace("/[$e]/iu", "[$e]", $term);
}
// The modified search term will now match similar terms of the search result text $str
// and wrap them in a 'highlighting' tag
$str = preg_replace("/$term/iu", "$0", $str);
Example:
- term = "leon"
- "leon" will not match "léon"
- therefore "leon" will be substituted with "l[eéèêë]on"
- "l[eéèêë]on" will now match "léon"
Hope it's useful :-)
Jakob
However, I've found a solution that is not very complicated.
Here is a detailed description of my PHP approach:
// First I make a string of characters grouped together, which should be treated as equivalent
$equiv = "aàáâãäå,eéèêë,iìíîï,oòóôõö,uùúûü,yýÿ,nñ,cç";
// The groups are split into an array and each group is processed
$equiv = explode(",", $equiv);
foreach ($equiv as $e)
{
// If either of the characters of a group is found in my search term, they will be replaced by the
// entire group (in [] brackets) before matching the search term against the search result text
// I use the /u modifier because my document is utf-8 encoded
$term = preg_replace("/[$e]/iu", "[$e]", $term);
}
// The modified search term will now match similar terms of the search result text $str
// and wrap them in a 'highlighting' tag
$str = preg_replace("/$term/iu", "$0", $str);
Example:
- term = "leon"
- "leon" will not match "léon"
- therefore "leon" will be substituted with "l[eéèêë]on"
- "l[eéèêë]on" will now match "léon"
Hope it's useful :-)
Jakob

May 19, 2007 - 04:22 AM
Shit, I see that some of my characters were not well received by quomon, so please ignore the strange parts of this:
$equiv = "aàáâãäå,eéèêë,iì
237;îï,oòóôõö,uùúûü,y
53;ÿ,nñ,cç";
The numbers should have been shown as foreign characters.
$equiv = "aàáâãäå,eéèêë,iì
237;îï,oòóôõö,uùúûü,y
53;ÿ,nñ,cç";
The numbers should have been shown as foreign characters.
Add New Comment