PHP
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   Web Development Archives Mailing Lists PHP

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Web Development Archives Sponsor:
  #1  
Old July 14th, 2008, 01:41 PM
Giulio Mastrosanti
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
case and accent - insensitive regular expression?

>

Brilliant !!!

so you replace every occurence of every accent variation with all the
accent variations

K, that's it!

only some more doubts ( regex are still an headhache for me )

preg_replace('/[Ź*źŻ©«*ݱ]/iu', -- what's the meaning of
iu after the match string?

preg_replace('/[*ĄąŁ€„»ƒ…](?!e)/iu', whats (?!e) for?
-- every occurence of *ĄąŁ€„»ƒ… NT followed by e?

Many thanks again for your effort,

I'm definitely on the good way

Giulio


>

I was intrigued by your example, so I played around with it some more
this morning. My own quick web search yielded a lot of results for
highlighting search terms, but none that I found did what you're
after. (I admit I didn't look very deep.) I was up to something like
this before your reply came in. It's still by no means complete. It
even handles simple English plurals (words ending in 's' or 'es'), but
not variations that require changing the word base (like 'daisy' to
'daisies').
>

<?php
function highlight_search_terms($phrase, $string) {
$non_letter_chars = '/[^\pL]/iu';
$words = preg_split($non_letter_chars, $phrase);
>

$search_words = array();
foreach ($words as $word) {
if (strlen($word) 2 && !preg_match($non_letter_chars,
$word)) {
$search_words[] = $word;
}
}
>

$search_words = array_unique($search_words);
>

foreach ($search_words as $word) {
$search = preg_quote($word);
>

/* repeat for each possible accented character */
$search = preg_replace('/(ae|Š|œ)/iu', '(ae|Š|œ)',
$search);
$search = preg_replace('/(oe|“)/iu', '(oe|“)', $search);
$search = preg_replace('/[*ĄąŁ€„»ƒ…](?!e)/iu',
'[*ĄąŁ€„»ƒ…]', $search);
$search = preg_replace('/[§‡‰‹]/iu', '[§‡‰‹]',
$search);
$search = preg_replace('/[‘]/iu', '[‘]', $search);
$search = preg_replace('/(?<![ao])[š©Ș«“•—™›]/iu',
'[š©Ș«“•—™›]', $search);
$search = preg_replace('/[ŸĄŁ]/iu', '[ŸĄŁ]',
$search);
$search = preg_replace('/[„§]/iu', '[„§]', $search);
$search = preg_replace('/[Ź*źŻ©«*ݱ]/iu',
'[Ź*źŻ©«*ݱ]', $search);
$search = preg_replace('/[”]/iu', '[”]', $search);
$search = preg_replace('/[·ž]/iu', '[·ž]', $search);
$search = preg_replace('/[șŒŸ€‚]/iu', '[șŒŸ€‚]',
$search);
$search = preg_replace('/[±„†ˆ‰‹]/iu',
'[±„†ˆ‰‹]', $search);
$search = preg_replace('/[ČłŽ”¶‘żĄ](?!e)/iu',
'[ČłŽ”¶‘żĄ]', $search);
$search = preg_replace('/[•—™]/iu', '[•—™]', $search);
$search = preg_replace('/[›ŸĄ]/iu', '[›ŸĄ]',
$search);
$search = preg_replace('/[Ł„§]/iu', '[Ł„§]', $search);
$search = preg_replace('/[čș»Œ©«*ݱł”–˜šœ]/iu',
'[čș»Œ©«*ݱł”–˜šœ]', $search);
$search = preg_replace('/[”]/iu', '[”]', $search);
$search = preg_replace('/[œż·]/iu', '[œż·]', $search);
$search = preg_replace('/[șŒŸ]/iu', '[șŒŸ]', $search);
>
>

$string = preg_replace('/\b' . $search . '(e?s)?\b/iu', '<span
class="keysearch">$0</span>', $string);
}
>

return $string;
>

}
?>
>

I still can't help feeling there must be some better way, though.
>
>>

>well, i think I'm on the good way now, unfortunately I have some
>other
>urgent work and can't try it immediately, but I'll let you know :)
>>

>thank you!
>>

>Giulio
>
>

Andrew
>
>

Reply With Quote
Reply

Viewing: Web Development Archives Mailing Lists PHP > case and accent - insensitive regular expression?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
Stay green...Green IT