Re: [PHP] case-insensitive $_REQUEST,$_GET,$_POST keys?
On Fri, Apr 13, 2012 at 1:13 PM, tamouse mailing lists tamouse.li...@gmail.com wrote: Anyone have a quick-and-dirty way to check $_REQUEST keys that is case-insensitive? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php this what you asking? foreach ( $_REQUEST as $key = $value ) { if ( strtolower($key) in array('name','username','password')) $data[ strtolower($key) ] = $value; }
Re: [PHP] case-insensitive $_REQUEST,$_GET,$_POST keys?
On Fri, Apr 13, 2012 at 12:22 PM, David OBrien dgobr...@gmail.com wrote: On Fri, Apr 13, 2012 at 1:13 PM, tamouse mailing lists tamouse.li...@gmail.com wrote: Anyone have a quick-and-dirty way to check $_REQUEST keys that is case-insensitive? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php this what you asking? foreach ( $_REQUEST as $key = $value ) { if ( strtolower($key) in array('name','username','password')) $data[ strtolower($key) ] = $value; } That would do it! Thanks. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Case Insensativity in String Comparisons
Is there a simple to way to compare two strings with case insensitivity so that the following will return true? $foo = Arnold; $bar = arnold; If($foo == $bar) { } Thanks. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Case Insensativity in String Comparisons
On Tue, Aug 25, 2009 at 12:48 PM, Ben Millerbiprel...@gmail.com wrote: Is there a simple to way to compare two strings with case insensitivity so that the following will return true? $foo = Arnold; $bar = arnold; If($foo == $bar) { } Thanks. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php http://www.php.net/manual/en/function.strcasecmp.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Case Conversion of US Person Names
Hi, All -- -- - - I occasionally find myself in need of a utility to do case conversion of people's names, especially when I am converting data from an old to a new system. This is the first such occasion in PHP. I know about ucwords() and mb_convert_case(). They do not accommodate names with middle capitalization. Does anybody have such a utility to share, or know of one posted by someone out there that you have used? I am not looking for perfection -- I know that such is not possible. I just want to pick off the easy ones -- Mc, Mac, O', de, de la, van, vander, van der, d' and others like that. I see some novel attempts to do parts of this on the PHP ucwords() User Notes area, but I bet someone out there has something more comprehensive. I'd rather not roll my own as I have done in other languages. I have Googled without success. Many thanks, Ken -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RES: [PHP] Case Conversion of US Person Names
U can try this: function fNme($n){ $tN=count($n=explode(' ',strtolower($n))); $nR=''; for($i=0;$i$tN;$i++){if($i==0){$nR.=strlen($n[$i])3?ucwords($n[$i]):$n[$i] ;}else{$nR.=strlen($n[$i])3?' '.ucwords($n[$i]):' '.$n[$i];}} return $nR; } echo fNme('a aaa aa aa '); And also make an array inside this function for exceptions like 'vander' or other words which the srtlen is 3. Zechim -Mensagem original- De: phphelp -- kbk [mailto:phph...@comcast.net] Enviada em: quinta-feira, 16 de julho de 2009 15:00 Para: PHP General List Assunto: [PHP] Case Conversion of US Person Names Hi, All -- -- - - I occasionally find myself in need of a utility to do case conversion of people's names, especially when I am converting data from an old to a new system. This is the first such occasion in PHP. I know about ucwords() and mb_convert_case(). They do not accommodate names with middle capitalization. Does anybody have such a utility to share, or know of one posted by someone out there that you have used? I am not looking for perfection -- I know that such is not possible. I just want to pick off the easy ones -- Mc, Mac, O', de, de la, van, vander, van der, d' and others like that. I see some novel attempts to do parts of this on the PHP ucwords() User Notes area, but I bet someone out there has something more comprehensive. I'd rather not roll my own as I have done in other languages. I have Googled without success. Many thanks, Ken -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: RES: [PHP] Case Conversion of US Person Names
On Jul 16, 2009, at 1:19 PM, Jônatas Zechim wrote: U can try this: function fNme($n){ $tN=count($n=explode(' ',strtolower($n))); $nR=''; for($i=0;$i$tN;$i++){if($i==0){$nR.=strlen($n[$i])3?ucwords($n [$i]):$n[$i] ;}else{$nR.=strlen($n[$i])3?' '.ucwords($n[$i]):' '.$n[$i];}} return $nR; } echo fNme('a aaa aa aa '); And also make an array inside this function for exceptions like 'vander' or other words which the srtlen is 3. Thank you. If I roll my own function, that could be useful. I'd still rather find one that exists, though. Ken -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Case Conversion of US Person Names
On Jul 16, 2009, at 4:06 PM, Leonard Burton wrote: Try this class here: http://code.google.com/p/lastname/ Oo! That looks *very* interesting. Thank you. Have you tried it? Ken -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] case and accent - insensitive regular expression?
I dont think using all these regular expressions is a very efficient way to do so. As i previously pointed out there are many users who had a similar problem, which can be viewed at: http://it.php.net/manual/en/function.strtr.php One of my favourites is what derernst at gmx dot ch used. derernst at gmx dot ch wrote on 20-Sep-2005 07:29 This works for me to remove accents for some characters of Latin-1, Latin-2 and Turkish in a UTF-8 environment, where the htmlentities-based solutions fail: ?php function remove_accents($string, $german=false) { // Single letters $single_fr = explode( , � � � � � � #260; #258; � #262; #268; #270; #272; � � � � � #280; #282; #286; � � � � #304; #321; #317; #313; � #323; #327; � � � � � � #336; #340; #344; � #346; #350; #356; #354; � � � � #366; #368; � � #377; #379; � � � � � � #261; #259; � #263; #269; #271; #273; � � � � #281; #283; #287; � � � � #305; #322; #318; #314; � #324; #328; � � � � � � � #337; #341; #345; #347; � #351; #357; #355; � � � � #367; #369; � � � #378; #380;); $single_to = explode( , A A A A A A A A C C C D D D E E E E E E G I I I I I L L L N N N O O O O O O O R R S S S T T U U U U U U Y Z Z Z a a a a a a a a c c c d d e e e e e e g i i i i i l l l n n n o o o o o o o o r r s s s t t u u u u u u y y z z z); $single = array(); for ($i=0; $icount($single_fr); $i++) { $single[$single_fr[$i]] = $single_to[$i]; } // Ligatures $ligatures = array(�=Ae, �=ae, �=Oe, �=oe, �=ss); // German umlauts $umlauts = array(�=Ae, �=ae, �=Oe, �=oe, �=Ue, �=ue); // Replace $replacements = array_merge($single, $ligatures); if ($german) $replacements = array_merge($replacements, $umlauts); $string = strtr($string, $replacements); return $string; } ? I would change this function a bit ... ?php //echo rawurlencode(áàéèíìóòúùÁÀÉÈÍÌÓÒÚÙ); // RFC 1738 codes; NOTE: One might use UTF-8 as this documents encoding function remove_accents($string) { $string = rawurlencode($string); $replacements = array( '%C3%A1' = 'a', '%C3%A0' = 'a', '%C3%A9' = 'e', '%C3%A8' = 'e', '%C3%AD' = 'i', '%C3%AC' = 'i', '%C3%B3' = 'o', '%C3%B2' = 'o', '%C3%BA' = 'u', '%C3%B9' = 'u', '%C3%81' = 'A', '%C3%80' = 'A', '%C3%89' = 'E', '%C3%88' = 'E', '%C3%8D' = 'I', '%C3%8C' = 'I', '%C3%93' = 'O', '%C3%92' = 'O', '%C3%9A' = 'U', '%C3%99' = 'U' ); return strtr($string, $replacements); } //echo remove_accents(CÀfé); // I know it's not spelled right echo remove_accents(áàéèíìóòúùÁÀÉÈÍÌÓÒÚÙ); //OUTPUT (again: i used UTF-8 for document): aaeeiioouuAAEEIIOOUU ? Ciao Yeti On Mon, Jul 14, 2008 at 8:20 PM, Andrew Ballard [EMAIL PROTECTED] wrote: On Mon, Jul 14, 2008 at 1:35 PM, Giulio Mastrosanti [EMAIL PROTECTED] wrote: Brilliant !!! so you replace every occurence of every accent variation with all the accent variations... OK, that's it! only some more doubts ( regex are still an headhache for me... ) preg_replace('/[iìíîïĩīĭįı]/iu',... -- what's the meaning of iu after the match string? This page explains them both. http://us.php.net/manual/en/reference.pcre.pattern.modifiers.php preg_replace('/[aàáâãäåǻāăą](?!e)/iu',... whats (?!e) for? -- every occurence of aàáâãäåǻāăą NOT followed by e? Yes. It matches any character based on the latin 'a' that is not followed by an 'e'. It keeps the pattern from matching the 'a' when it immediately precedes an 'e' for the character 'ae' for words like these: http://en.wikipedia.org/wiki/List_of_words_that_may_be_spelled_with_a_ligature (However, that may cause problems with words that have other variants of 'ae' in them. I'll leave that to you to resolve.) http://us.php.net/manual/en/regexp.reference.php 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);
Re: [PHP] case and accent - insensitive regular expression?
Oh, and i forgot about this one ... jorge at seisbits dot com wrote on 11-Jul-2008 09:04 If you try to make a strtr of not usual charafters when you are in a utf8 enviroment, you can do that: function normaliza ($string){ $string = utf8_decode($string); $string = strtr($string, utf8_decode( ÂÊÎÔÛÀ), -AEIOU); $string = strtolower($string); return $string; } On Tue, Jul 15, 2008 at 11:38 AM, Yeti [EMAIL PROTECTED] wrote: I dont think using all these regular expressions is a very efficient way to do so. As i previously pointed out there are many users who had a similar problem, which can be viewed at: http://it.php.net/manual/en/function.strtr.php One of my favourites is what derernst at gmx dot ch used. derernst at gmx dot ch wrote on 20-Sep-2005 07:29 This works for me to remove accents for some characters of Latin-1, Latin-2 and Turkish in a UTF-8 environment, where the htmlentities-based solutions fail: ?php function remove_accents($string, $german=false) { // Single letters $single_fr = explode( , � � � � � � #260; #258; � #262; #268; #270; #272; � � � � � #280; #282; #286; � � � � #304; #321; #317; #313; � #323; #327; � � � � � � #336; #340; #344; � #346; #350; #356; #354; � � � � #366; #368; � � #377; #379; � � � � � � #261; #259; � #263; #269; #271; #273; � � � � #281; #283; #287; � � � � #305; #322; #318; #314; � #324; #328; � � � � � � � #337; #341; #345; #347; � #351; #357; #355; � � � � #367; #369; � � � #378; #380;); $single_to = explode( , A A A A A A A A C C C D D D E E E E E E G I I I I I L L L N N N O O O O O O O R R S S S T T U U U U U U Y Z Z Z a a a a a a a a c c c d d e e e e e e g i i i i i l l l n n n o o o o o o o o r r s s s t t u u u u u u y y z z z); $single = array(); for ($i=0; $icount($single_fr); $i++) { $single[$single_fr[$i]] = $single_to[$i]; } // Ligatures $ligatures = array(�=Ae, �=ae, �=Oe, �=oe, �=ss); // German umlauts $umlauts = array(�=Ae, �=ae, �=Oe, �=oe, �=Ue, �=ue); // Replace $replacements = array_merge($single, $ligatures); if ($german) $replacements = array_merge($replacements, $umlauts); $string = strtr($string, $replacements); return $string; } ? I would change this function a bit ... ?php //echo rawurlencode(áàéèíìóòúùÁÀÉÈÍÌÓÒÚÙ); // RFC 1738 codes; NOTE: One might use UTF-8 as this documents encoding function remove_accents($string) { $string = rawurlencode($string); $replacements = array( '%C3%A1' = 'a', '%C3%A0' = 'a', '%C3%A9' = 'e', '%C3%A8' = 'e', '%C3%AD' = 'i', '%C3%AC' = 'i', '%C3%B3' = 'o', '%C3%B2' = 'o', '%C3%BA' = 'u', '%C3%B9' = 'u', '%C3%81' = 'A', '%C3%80' = 'A', '%C3%89' = 'E', '%C3%88' = 'E', '%C3%8D' = 'I', '%C3%8C' = 'I', '%C3%93' = 'O', '%C3%92' = 'O', '%C3%9A' = 'U', '%C3%99' = 'U' ); return strtr($string, $replacements); } //echo remove_accents(CÀfé); // I know it's not spelled right echo remove_accents(áàéèíìóòúùÁÀÉÈÍÌÓÒÚÙ); //OUTPUT (again: i used UTF-8 for document): aaeeiioouuAAEEIIOOUU ? Ciao Yeti On Mon, Jul 14, 2008 at 8:20 PM, Andrew Ballard [EMAIL PROTECTED] wrote: On Mon, Jul 14, 2008 at 1:35 PM, Giulio Mastrosanti [EMAIL PROTECTED] wrote: Brilliant !!! so you replace every occurence of every accent variation with all the accent variations... OK, that's it! only some more doubts ( regex are still an headhache for me... ) preg_replace('/[iìíîïĩīĭįı]/iu',... -- what's the meaning of iu after the match string? This page explains them both. http://us.php.net/manual/en/reference.pcre.pattern.modifiers.php preg_replace('/[aàáâãäåǻāăą](?!e)/iu',... whats (?!e) for? -- every occurence of aàáâãäåǻāăą NOT followed by e? Yes. It matches any character based on the latin 'a' that is not followed by an 'e'. It keeps the pattern from matching the 'a' when it immediately precedes an 'e' for the character 'ae' for words like these: http://en.wikipedia.org/wiki/List_of_words_that_may_be_spelled_with_a_ligature (However, that may cause problems with words that have other variants of 'ae' in them. I'll leave that to you to resolve.) http://us.php.net/manual/en/regexp.reference.php 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);
Re: [PHP] case and accent - insensitive regular expression?
On Tue, Jul 15, 2008 at 5:38 AM, Yeti [EMAIL PROTECTED] wrote: I dont think using all these regular expressions is a very efficient way to do so. As i previously pointed out there are many users who had a similar problem, which can be viewed at: http://it.php.net/manual/en/function.strtr.php One of my favourites is what derernst at gmx dot ch used. derernst at gmx dot ch wrote on 20-Sep-2005 07:29 This works for me to remove accents for some characters of Latin-1, Latin-2 and Turkish in a UTF-8 environment, where the htmlentities-based solutions fail: ?php function remove_accents($string, $german=false) { // Single letters $single_fr = explode( , � � � � � � #260; #258; � #262; #268; #270; #272; � � � � � #280; #282; #286; � � � � #304; #321; #317; #313; � #323; #327; � � � � � � #336; #340; #344; � #346; #350; #356; #354; � � � � #366; #368; � � #377; #379; � � � � � � #261; #259; � #263; #269; #271; #273; � � � � #281; #283; #287; � � � � #305; #322; #318; #314; � #324; #328; � � � � � � � #337; #341; #345; #347; � #351; #357; #355; � � � � #367; #369; � � � #378; #380;); $single_to = explode( , A A A A A A A A C C C D D D E E E E E E G I I I I I L L L N N N O O O O O O O R R S S S T T U U U U U U Y Z Z Z a a a a a a a a c c c d d e e e e e e g i i i i i l l l n n n o o o o o o o o r r s s s t t u u u u u u y y z z z); $single = array(); for ($i=0; $icount($single_fr); $i++) { $single[$single_fr[$i]] = $single_to[$i]; } // Ligatures $ligatures = array(�=Ae, �=ae, �=Oe, �=oe, �=ss); // German umlauts $umlauts = array(�=Ae, �=ae, �=Oe, �=oe, �=Ue, �=ue); // Replace $replacements = array_merge($single, $ligatures); if ($german) $replacements = array_merge($replacements, $umlauts); $string = strtr($string, $replacements); return $string; } ? I would change this function a bit ... ?php //echo rawurlencode(áàéèíìóòúùÁÀÉÈÍÌÓÒÚÙ); // RFC 1738 codes; NOTE: One might use UTF-8 as this documents encoding function remove_accents($string) { $string = rawurlencode($string); $replacements = array( '%C3%A1' = 'a', '%C3%A0' = 'a', '%C3%A9' = 'e', '%C3%A8' = 'e', '%C3%AD' = 'i', '%C3%AC' = 'i', '%C3%B3' = 'o', '%C3%B2' = 'o', '%C3%BA' = 'u', '%C3%B9' = 'u', '%C3%81' = 'A', '%C3%80' = 'A', '%C3%89' = 'E', '%C3%88' = 'E', '%C3%8D' = 'I', '%C3%8C' = 'I', '%C3%93' = 'O', '%C3%92' = 'O', '%C3%9A' = 'U', '%C3%99' = 'U' ); return strtr($string, $replacements); } //echo remove_accents(CÀfé); // I know it's not spelled right echo remove_accents(áàéèíìóòúùÁÀÉÈÍÌÓÒÚÙ); //OUTPUT (again: i used UTF-8 for document): aaeeiioouuAAEEIIOOUU ? Ciao Yeti On Mon, Jul 14, 2008 at 8:20 PM, Andrew Ballard [EMAIL PROTECTED] wrote: On Mon, Jul 14, 2008 at 1:35 PM, Giulio Mastrosanti [EMAIL PROTECTED] wrote: Brilliant !!! so you replace every occurence of every accent variation with all the accent variations... OK, that's it! only some more doubts ( regex are still an headhache for me... ) preg_replace('/[iìíîïĩīĭįı]/iu',... -- what's the meaning of iu after the match string? This page explains them both. http://us.php.net/manual/en/reference.pcre.pattern.modifiers.php preg_replace('/[aàáâãäåǻāăą](?!e)/iu',... whats (?!e) for? -- every occurence of aàáâãäåǻāăą NOT followed by e? Yes. It matches any character based on the latin 'a' that is not followed by an 'e'. It keeps the pattern from matching the 'a' when it immediately precedes an 'e' for the character 'ae' for words like these: http://en.wikipedia.org/wiki/List_of_words_that_may_be_spelled_with_a_ligature (However, that may cause problems with words that have other variants of 'ae' in them. I'll leave that to you to resolve.) http://us.php.net/manual/en/regexp.reference.php 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
Re: [PHP] case and accent - insensitive regular expression?
On Tue, Jul 15, 2008 at 9:46 AM, Andrew Ballard [EMAIL PROTECTED] wrote: On Tue, Jul 15, 2008 at 5:38 AM, Yeti [EMAIL PROTECTED] wrote: I dont think using all these regular expressions is a very efficient way to do so. As i previously pointed out there are many users who had a similar problem, which can be viewed at: http://it.php.net/manual/en/function.strtr.php One of my favourites is what derernst at gmx dot ch used. derernst at gmx dot ch wrote on 20-Sep-2005 07:29 This works for me to remove accents for some characters of Latin-1, Latin-2 and Turkish in a UTF-8 environment, where the htmlentities-based solutions fail: ?php function remove_accents($string, $german=false) { // Single letters $single_fr = explode( , � � � � � � #260; #258; � #262; #268; #270; #272; � � � � � #280; #282; #286; � � � � #304; #321; #317; #313; � #323; #327; � � � � � � #336; #340; #344; � #346; #350; #356; #354; � � � � #366; #368; � � #377; #379; � � � � � � #261; #259; � #263; #269; #271; #273; � � � � #281; #283; #287; � � � � #305; #322; #318; #314; � #324; #328; � � � � � � � #337; #341; #345; #347; � #351; #357; #355; � � � � #367; #369; � � � #378; #380;); $single_to = explode( , A A A A A A A A C C C D D D E E E E E E G I I I I I L L L N N N O O O O O O O R R S S S T T U U U U U U Y Z Z Z a a a a a a a a c c c d d e e e e e e g i i i i i l l l n n n o o o o o o o o r r s s s t t u u u u u u y y z z z); $single = array(); for ($i=0; $icount($single_fr); $i++) { $single[$single_fr[$i]] = $single_to[$i]; } // Ligatures $ligatures = array(�=Ae, �=ae, �=Oe, �=oe, �=ss); // German umlauts $umlauts = array(�=Ae, �=ae, �=Oe, �=oe, �=Ue, �=ue); // Replace $replacements = array_merge($single, $ligatures); if ($german) $replacements = array_merge($replacements, $umlauts); $string = strtr($string, $replacements); return $string; } ? I would change this function a bit ... ?php //echo rawurlencode(áàéèíìóòúùÁÀÉÈÍÌÓÒÚÙ); // RFC 1738 codes; NOTE: One might use UTF-8 as this documents encoding function remove_accents($string) { $string = rawurlencode($string); $replacements = array( '%C3%A1' = 'a', '%C3%A0' = 'a', '%C3%A9' = 'e', '%C3%A8' = 'e', '%C3%AD' = 'i', '%C3%AC' = 'i', '%C3%B3' = 'o', '%C3%B2' = 'o', '%C3%BA' = 'u', '%C3%B9' = 'u', '%C3%81' = 'A', '%C3%80' = 'A', '%C3%89' = 'E', '%C3%88' = 'E', '%C3%8D' = 'I', '%C3%8C' = 'I', '%C3%93' = 'O', '%C3%92' = 'O', '%C3%9A' = 'U', '%C3%99' = 'U' ); return strtr($string, $replacements); } //echo remove_accents(CÀfé); // I know it's not spelled right echo remove_accents(áàéèíìóòúùÁÀÉÈÍÌÓÒÚÙ); //OUTPUT (again: i used UTF-8 for document): aaeeiioouuAAEEIIOOUU ? Ciao Yeti On Mon, Jul 14, 2008 at 8:20 PM, Andrew Ballard [EMAIL PROTECTED] wrote: On Mon, Jul 14, 2008 at 1:35 PM, Giulio Mastrosanti [EMAIL PROTECTED] wrote: Brilliant !!! so you replace every occurence of every accent variation with all the accent variations... OK, that's it! only some more doubts ( regex are still an headhache for me... ) preg_replace('/[iìíîïĩīĭįı]/iu',... -- what's the meaning of iu after the match string? This page explains them both. http://us.php.net/manual/en/reference.pcre.pattern.modifiers.php preg_replace('/[aàáâãäåǻāăą](?!e)/iu',... whats (?!e) for? -- every occurence of aàáâãäåǻāăą NOT followed by e? Yes. It matches any character based on the latin 'a' that is not followed by an 'e'. It keeps the pattern from matching the 'a' when it immediately precedes an 'e' for the character 'ae' for words like these: http://en.wikipedia.org/wiki/List_of_words_that_may_be_spelled_with_a_ligature (However, that may cause problems with words that have other variants of 'ae' in them. I'll leave that to you to resolve.) http://us.php.net/manual/en/regexp.reference.php 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 =
Re: [PHP] case and accent - insensitive regular expression?
At 10:15 AM -0400 7/15/08, Andrew Ballard wrote: On TueWell, OK, I can think of one optimization. This takes advantage of the fact that preg_replace can accept arrays as parameters. In a couple very quick tests this version is roughly 30% faster than my previous version: -snip- Hey, when you finally get finished with that function, please let me know I would like to copy it. :-) Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] case and accent - insensitive regular expression?
On Tue, Jul 15, 2008 at 12:30 PM, tedd [EMAIL PROTECTED] wrote: At 10:15 AM -0400 7/15/08, Andrew Ballard wrote: On TueWell, OK, I can think of one optimization. This takes advantage of the fact that preg_replace can accept arrays as parameters. In a couple very quick tests this version is roughly 30% faster than my previous version: -snip- Hey, when you finally get finished with that function, please let me know I would like to copy it. :-) Cheers, tedd All yours. I figure I'm done with it. (At least until I actually need to use it for something and then I have to test it for real. :-) ) Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] case and accent - insensitive regular expression?
The original problem was User X submits a character string A. A PHP scripts uses A to search for it's occurences in a DB, ignoring special characters. The result of ze search is a list of character strings M-LIST with matches. This list gets outputted to the user X, but before that all the matching strings should be replaced with 'span style=color: #FF'..'/span' If i clearly got the OP then he is using MySQL to perform the search. I guess he is doing it with MATCH. So MySQL already found the match and in PHP it has to be done again ... eg. The table has 2 entries, string1 and string2 .. string1 = 'Thís ís an éxámplè stríng wíth áccénts.' string2 = 'This is an example string without accents.' Now the user searches for ample: search = '*ample*' Both string have matches due to accent-insensitivity (AI). Now the result is outputted with highlighting .. *Thís ís an éx*span style=color: #FF*ámplè*/span* stríng wíth áccénts.* *This is an ex*span style=color: #FF*ample*/span* string without accents.* So since MySQL already did the job, why not get the occurances from it? I'm not an MySQL expert, but I know google and found something called string functions. Especially a locate function got my interest. http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_locate Now shouldnt it be possible to create a query that searches the db for matches and additionally uses the string function? I have no idea, but maybe some MySQL-expert out there has ... Yeti On Tue, Jul 15, 2008 at 7:17 PM, Andrew Ballard [EMAIL PROTECTED] wrote: On Tue, Jul 15, 2008 at 12:30 PM, tedd [EMAIL PROTECTED] wrote: At 10:15 AM -0400 7/15/08, Andrew Ballard wrote: On TueWell, OK, I can think of one optimization. This takes advantage of the fact that preg_replace can accept arrays as parameters. In a couple very quick tests this version is roughly 30% faster than my previous version: -snip- Hey, when you finally get finished with that function, please let me know I would like to copy it. :-) Cheers, tedd All yours. I figure I'm done with it. (At least until I actually need to use it for something and then I have to test it for real. :-) ) Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] case and accent - insensitive regular expression?
On Tue, Jul 15, 2008 at 2:07 PM, Yeti [EMAIL PROTECTED] wrote: The original problem was User X submits a character string A. A PHP scripts uses A to search for it's occurences in a DB, ignoring special characters. The result of ze search is a list of character strings M-LIST with matches. This list gets outputted to the user X, but before that all the matching strings should be replaced with 'span style=color: #FF'..'/span' If i clearly got the OP then he is using MySQL to perform the search. I guess he is doing it with MATCH. So MySQL already found the match and in PHP it has to be done again ... eg. The table has 2 entries, string1 and string2 .. string1 = 'Thís ís an éxámplè stríng wíth áccénts.' string2 = 'This is an example string without accents.' Now the user searches for ample: search = 'ample' Both string have matches due to accent-insensitivity (AI). Now the result is outputted with highlighting .. Thís ís an éxspan style=color: #FFámplè/span stríng wíth áccénts. This is an exspan style=color: #FFample/span string without accents. Correct. So since MySQL already did the job, why not get the occurances from it? I'm not an MySQL expert, but I know google and found something called string functions. Especially a locate function got my interest. http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_locate Now shouldnt it be possible to create a query that searches the db for matches and additionally uses the string function? I have no idea, but maybe some MySQL-expert out there has ... Yeti There are definitely possibilities there. Personally, I tend to be biased against using the database to format output for presentation, so I'd rather not push the task off there. Still, I know lots of developers do not share this bias, so I'll address a couple other issues I see with this approach: 1) If the search word appears multiple times, LOCATE() will only find it once. I'd probably use REPLACE() instead. This leads to the next problem: 2) I'm not sure if the OP wants this or not, but if he wants to highlight each of multiple search terms the way many sites do, he would have to split the terms and build a SQL phrase that like this (there are probably other approaches available in MySQL to do the same thing): -- search phrase 'quaint french cafe' SELECT REPLACE(REPLACE(REPLACE(`my_column`, 'quaint', 'span class=keysearchquaint/span'), 'french', 'span class=keysearchfrench/span'), 'cafe', 'span class=keysearchcafe/span') FROM ... In this case, he should get all instances of each word highlighted, but the accented characters would again be replaced with a particular style. (Not to mention the size and complexity of the query being passed from PHP to the database or the potential size of the result being passed from the database to PHP since it now could have lots of formatting text embedded in it.) Andrew
Re: [PHP] case and accent - insensitive regular expression?
First of all thank you all for your answers, and thank you for your time and yes Tedd, my question was quite ambiguous in that point. Andrew is right, i don't want to change in any way the list of keys I show in the result, I just want to find the way to higlight the matching words, regardless of their accent variations. So I think his Andrew's suggestion could be a good solution, and I'll try it ASAP... let me se if i correctly understood: $search = preg_quote($word); -- quotes chars that could be intrepreted like regex special chars $search = str_replace('e', '[eèéêë]', $search); -- trasforms i.e. cafe in caf[eèéêë], so matches all the accented variations return preg_replace('/\b' ... -- replaces all the occurences adding the tags, you use \b as word boundary, right? it seems a fine soultion to the problem! the only thing i must add is, befor calling highlight_search_terms, to 'normalize' the word string ( the word used for the search) to transform it removing the accentated versions of the chars: $word = preg_replace('[èé]{1}','e',$word); $word = preg_replace('[à]{1}','a',$word); that because also the search string could contain an accented char, and this way I avoid to perform str_replace in the highlight_search_terms function for every combination of accented chars 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 I may be mistaken (and if I am, then just ignore this as ignorant rambling), but I don't think he's wanting to replace the accented characters in the original string. I think he's just wanting the pattern to find all variations of the same string and highlight them without changing them. For example, his last paragraph would look like this: [quote] now my problem is to find a way ( I imagine with some kind of regular expression ) to achieve in php a search and replace accent-insensitive, so that i can find the word 'span class=keysearchcafe/span' in a string also if it is 'span class=keysearchcafé/span', or 'span class=keysearchCAFÉ/span', or 'span class=keysearchCAFE/span', and vice-versa. [/quote] The best I can think of right now is something like this: ?php function highlight_search_terms($word, $string) { $search = preg_quote($word); $search = str_replace('a', '[aàáâãäå]', $search); $search = str_replace('e', '[eèéêë]', $search); /* repeat for each possible accented character */ return preg_replace('/\b' . $search . '\b/i', 'span class=keysearch$0/span', $string); } $string = now my problem is to find a way ( I imagine with some kind of regular expression ) to achieve in php a search and replace accent-insensitive, so that i can find the word 'cafe' in a string also if it is 'café', or 'CAFÉ', or 'CAFE', and vice-versa.; echo highlight_search_terms('cafe', $string); ? Andrew Andrew: You may be right -- it's ambiguous now that I review it again. He does say search and replace but I'm not sure if that's what he really wants. It looks more like search with one string and highlight all like-strings. Cheers, tedd -- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] case and accent - insensitive regular expression?
On Mon, Jul 14, 2008 at 11:06 AM, Giulio Mastrosanti [EMAIL PROTECTED] wrote: First of all thank you all for your answers, and thank you for your time and yes Tedd, my question was quite ambiguous in that point. Andrew is right, i don't want to change in any way the list of keys I show in the result, I just want to find the way to higlight the matching words, regardless of their accent variations. So I think his Andrew's suggestion could be a good solution, and I'll try it ASAP... let me se if i correctly understood: $search = preg_quote($word); -- quotes chars that could be intrepreted like regex special chars $search = str_replace('e', '[eטיךכ]', $search); -- trasforms i.e. cafe in caf[eטיךכ], so matches all the accented variations return preg_replace('/\b' ... -- replaces all the occurences adding the tags, you use \b as word boundary, right? Yes, yes, and yes. :-) it seems a fine soultion to the problem! the only thing i must add is, befor calling highlight_search_terms, to 'normalize' the word string ( the word used for the search) to transform it removing the accentated versions of the chars: $word = preg_replace('[טי]{1}','e',$word); $word = preg_replace('[א]{1}','a',$word); that because also the search string could contain an accented char, and this way I avoid to perform str_replace in the highlight_search_terms function for every combination of accented chars 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('/[aàáâãäåǻāăą](?!e)/iu', '[aàáâãäåǻāăą]', $search); $search = preg_replace('/[cçćĉċč]/iu', '[cçćĉċč]', $search); $search = preg_replace('/[dďđ]/iu', '[dďđ]', $search); $search = preg_replace('/(?![ao])[eèéêëēĕėęě]/iu', '[eèéêëēĕėęě]', $search); $search = preg_replace('/[gĝğġģ]/iu', '[gĝğġģ]', $search); $search = preg_replace('/[hĥħ]/iu', '[hĥħ]', $search); $search = preg_replace('/[iìíîïĩīĭįı]/iu', '[iìíîïĩīĭįı]', $search); $search = preg_replace('/[jĵ]/iu', '[jĵ]', $search); $search = preg_replace('/[kķĸ]/iu', '[kķĸ]', $search); $search = preg_replace('/[lĺļľŀł]/iu', '[lĺļľŀł]', $search); $search = preg_replace('/[nñńņňʼnŋ]/iu', '[nñńņňʼnŋ]', $search); $search = preg_replace('/[oòóôõöōŏőǿơ](?!e)/iu', '[oòóôõöōŏőǿơ]', $search); $search = preg_replace('/[rŕŗř]/iu', '[rŕŗř]', $search); $search = preg_replace('/[sśŝşš]/iu', '[sśŝşš]', $search); $search = preg_replace('/[tţťŧ]/iu', '[tţťŧ]', $search); $search = preg_replace('/[uùúûüũūŭůűųǔǖǘǚǜ]/iu', '[uùúûüũūŭůűųǔǖǘǚǜ]', $search); $search = preg_replace('/[wŵ]/iu', '[wŵ]', $search); $search = preg_replace('/[yýÿŷ]/iu', '[yýÿŷ]', $search); $search = preg_replace('/[zźżž]/iu', '[zźżž]', $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
Re: [PHP] case and accent - insensitive regular expression?
Brilliant !!! so you replace every occurence of every accent variation with all the accent variations... OK, that's it! only some more doubts ( regex are still an headhache for me... ) preg_replace('/[iìíîïĩīĭįı]/iu',... -- what's the meaning of iu after the match string? preg_replace('/[aàáâãäåǻāăą](?!e)/iu',... whats (?!e) for? -- every occurence of aàáâãäåǻāăą NOT 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('/[aàáâãäåǻāăą](?!e)/iu', '[aàáâãäåǻāăą]', $search); $search = preg_replace('/[cçćĉċč]/iu', '[cçćĉċč]', $search); $search = preg_replace('/[dďđ]/iu', '[dďđ]', $search); $search = preg_replace('/(?![ao])[eèéêëēĕėęě]/iu', '[eèéêëēĕėęě]', $search); $search = preg_replace('/[gĝğġģ]/iu', '[gĝğġģ]', $search); $search = preg_replace('/[hĥħ]/iu', '[hĥħ]', $search); $search = preg_replace('/[iìíîïĩīĭįı]/iu', '[iìíîïĩīĭįı]', $search); $search = preg_replace('/[jĵ]/iu', '[jĵ]', $search); $search = preg_replace('/[kķĸ]/iu', '[kķĸ]', $search); $search = preg_replace('/[lĺļľŀł]/iu', '[lĺļľŀł]', $search); $search = preg_replace('/[nñńņňʼnŋ]/iu', '[nñńņňʼnŋ]', $search); $search = preg_replace('/[oòóôõöōŏőǿơ](?!e)/iu', '[oòóôõöōŏőǿơ]', $search); $search = preg_replace('/[rŕŗř]/iu', '[rŕŗř]', $search); $search = preg_replace('/[sśŝşš]/iu', '[sśŝşš]', $search); $search = preg_replace('/[tţťŧ]/iu', '[tţťŧ]', $search); $search = preg_replace('/[uùúûüũūŭůűųǔǖǘǚǜ]/iu', '[uùúûüũūŭůűųǔǖǘǚǜ]', $search); $search = preg_replace('/[wŵ]/iu', '[wŵ]', $search); $search = preg_replace('/[yýÿŷ]/iu', '[yýÿŷ]', $search); $search = preg_replace('/[zźżž]/iu', '[zźżž]', $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
Re: [PHP] case and accent - insensitive regular expression?
On Mon, Jul 14, 2008 at 1:35 PM, Giulio Mastrosanti [EMAIL PROTECTED] wrote: Brilliant !!! so you replace every occurence of every accent variation with all the accent variations... OK, that's it! only some more doubts ( regex are still an headhache for me... ) preg_replace('/[iìíîïĩīĭįı]/iu',... -- what's the meaning of iu after the match string? This page explains them both. http://us.php.net/manual/en/reference.pcre.pattern.modifiers.php preg_replace('/[aàáâãäåǻāăą](?!e)/iu',... whats (?!e) for? -- every occurence of aàáâãäåǻāăą NOT followed by e? Yes. It matches any character based on the latin 'a' that is not followed by an 'e'. It keeps the pattern from matching the 'a' when it immediately precedes an 'e' for the character 'ae' for words like these: http://en.wikipedia.org/wiki/List_of_words_that_may_be_spelled_with_a_ligature (However, that may cause problems with words that have other variants of 'ae' in them. I'll leave that to you to resolve.) http://us.php.net/manual/en/regexp.reference.php 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('/[aàáâãäåǻāăą](?!e)/iu', '[aàáâãäåǻāăą]', $search); $search = preg_replace('/[cçćĉċč]/iu', '[cçćĉċč]', $search); $search = preg_replace('/[dďđ]/iu', '[dďđ]', $search); $search = preg_replace('/(?![ao])[eèéêëēĕėęě]/iu', '[eèéêëēĕėęě]', $search); $search = preg_replace('/[gĝğġģ]/iu', '[gĝğġģ]', $search); $search = preg_replace('/[hĥħ]/iu', '[hĥħ]', $search); $search = preg_replace('/[iìíîïĩīĭįı]/iu', '[iìíîïĩīĭįı]', $search); $search = preg_replace('/[jĵ]/iu', '[jĵ]', $search); $search = preg_replace('/[kķĸ]/iu', '[kķĸ]', $search); $search = preg_replace('/[lĺļľŀł]/iu', '[lĺļľŀł]', $search); $search = preg_replace('/[nñńņňʼnŋ]/iu', '[nñńņňʼnŋ]', $search); $search = preg_replace('/[oòóôõöōŏőǿơ](?!e)/iu', '[oòóôõöōŏőǿơ]', $search); $search = preg_replace('/[rŕŗř]/iu', '[rŕŗř]', $search); $search = preg_replace('/[sśŝşš]/iu', '[sśŝşš]', $search); $search = preg_replace('/[tţťŧ]/iu', '[tţťŧ]', $search); $search = preg_replace('/[uùúûüũūŭůűųǔǖǘǚǜ]/iu', '[uùúûüũūŭůűųǔǖǘǚǜ]', $search); $search = preg_replace('/[wŵ]/iu', '[wŵ]', $search); $search = preg_replace('/[yýÿŷ]/iu', '[yýÿŷ]', $search); $search = preg_replace('/[zźżž]/iu', '[zźżž]', $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
Re: [PHP] case and accent - insensitive regular expression?
On Sat, Jul 12, 2008 at 10:29 AM, tedd [EMAIL PROTECTED] wrote: At 9:36 AM +0200 7/12/08, Giulio Mastrosanti wrote: Hi, I have a php page that asks user for a key ( or a list of keys ) and then shows a list of items matching the query. every item in the list shows its data, and the list of keys it has ( a list of comma-separated words ) I would like to higlight, in the list of keys shown for every item, the words matching the query, this can be easily achieved with a search and replace, for every search word, i search it in the key list and replace it adding a style tag to higlight it such as for example to have it in red color: if ( @stripos($keylist,$keysearch!== false ) { $keylist = str_ireplace($keysearch,'span style=color: #FF'.$keysearch.'/span',$keylist); } but i have some problem with accented characters: i have mysql with character encoding utf8, and all the php pages are declared as utf8 mysql in configured to perform queries in a case and accent insensitive way. this mean that if you search for the word 'cafe', you have returned rows that contains in the keyword list 'cafe', but also 'café' with the accent. ( I think it has to do with 'collation' settings, but I'm not investigating at the moment because it is OK for me the way it works ). now my problem is to find a way ( I imagine with some kind of regular expression ) to achieve in php a search and replace accent-insensitive, so that i can find the word 'cafe' in a string also if it is 'café', or 'CAFÉ', or 'CAFE', and vice-versa. hope the problem is clear and well-explained in english, thank you for any tip, Giulio Giulio: Three things: 1. Your English is fine. 2. Try using mb_ereg_replace() http://www.php.net/mb_ereg_replace Place the accents you want to change in that and change them to whatever you want. 3. Change: span style=color: #FF'.$keysearch.'/span' to span class=keysearch'.$keysearch.'/span' and add .keysearch { color: #FF; } to your css. Cheers, tedd I may be mistaken (and if I am, then just ignore this as ignorant rambling), but I don't think he's wanting to replace the accented characters in the original string. I think he's just wanting the pattern to find all variations of the same string and highlight them without changing them. For example, his last paragraph would look like this: [quote] now my problem is to find a way ( I imagine with some kind of regular expression ) to achieve in php a search and replace accent-insensitive, so that i can find the word 'span class=keysearchcafe/span' in a string also if it is 'span class=keysearchcafé/span', or 'span class=keysearchCAFÉ/span', or 'span class=keysearchCAFE/span', and vice-versa. [/quote] The best I can think of right now is something like this: ?php function highlight_search_terms($word, $string) { $search = preg_quote($word); $search = str_replace('a', '[aàáâãäå]', $search); $search = str_replace('e', '[eèéêë]', $search); /* repeat for each possible accented character */ return preg_replace('/\b' . $search . '\b/i', 'span class=keysearch$0/span', $string); } $string = now my problem is to find a way ( I imagine with some kind of regular expression ) to achieve in php a search and replace accent-insensitive, so that i can find the word 'cafe' in a string also if it is 'café', or 'CAFÉ', or 'CAFE', and vice-versa.; echo highlight_search_terms('cafe', $string); ? Andrew
Re: [PHP] case and accent - insensitive regular expression?
At 8:31 AM -0400 7/13/08, Andrew Ballard wrote: On Sat, Jul 12, 2008 at 10:29 AM, tedd [EMAIL PROTECTED] wrote: At 9:36 AM +0200 7/12/08, Giulio Mastrosanti wrote: Hi, I have a php page that asks user for a key ( or a list of keys ) and then shows a list of items matching the query. every item in the list shows its data, and the list of keys it has ( a list of comma-separated words ) I would like to higlight, in the list of keys shown for every item, the words matching the query, this can be easily achieved with a search and replace, for every search word, i search it in the key list and replace it adding a style tag to higlight it such as for example to have it in red color: if ( @stripos($keylist,$keysearch!== false ) { $keylist = str_ireplace($keysearch,'span style=color: #FF'.$keysearch.'/span',$keylist); } but i have some problem with accented characters: i have mysql with character encoding utf8, and all the php pages are declared as utf8 mysql in configured to perform queries in a case and accent insensitive way. this mean that if you search for the word 'cafe', you have returned rows that contains in the keyword list 'cafe', but also 'café' with the accent. ( I think it has to do with 'collation' settings, but I'm not investigating at the moment because it is OK for me the way it works ). now my problem is to find a way ( I imagine with some kind of regular expression ) to achieve in php a search and replace accent-insensitive, so that i can find the word 'cafe' in a string also if it is 'café', or 'CAFÉ', or 'CAFE', and vice-versa. hope the problem is clear and well-explained in english, thank you for any tip, Giulio Giulio: Three things: 1. Your English is fine. 2. Try using mb_ereg_replace() http://www.php.net/mb_ereg_replace Place the accents you want to change in that and change them to whatever you want. 3. Change: span style=color: #FF'.$keysearch.'/span' to span class=keysearch'.$keysearch.'/span' and add .keysearch { color: #FF; } to your css. Cheers, tedd I may be mistaken (and if I am, then just ignore this as ignorant rambling), but I don't think he's wanting to replace the accented characters in the original string. I think he's just wanting the pattern to find all variations of the same string and highlight them without changing them. For example, his last paragraph would look like this: [quote] now my problem is to find a way ( I imagine with some kind of regular expression ) to achieve in php a search and replace accent-insensitive, so that i can find the word 'span class=keysearchcafe/span' in a string also if it is 'span class=keysearchcafé/span', or 'span class=keysearchCAFÉ/span', or 'span class=keysearchCAFE/span', and vice-versa. [/quote] The best I can think of right now is something like this: ?php function highlight_search_terms($word, $string) { $search = preg_quote($word); $search = str_replace('a', '[aàáâãäå]', $search); $search = str_replace('e', '[eèéêë]', $search); /* repeat for each possible accented character */ return preg_replace('/\b' . $search . '\b/i', 'span class=keysearch$0/span', $string); } $string = now my problem is to find a way ( I imagine with some kind of regular expression ) to achieve in php a search and replace accent-insensitive, so that i can find the word 'cafe' in a string also if it is 'café', or 'CAFÉ', or 'CAFE', and vice-versa.; echo highlight_search_terms('cafe', $string); ? Andrew Andrew: You may be right -- it's ambiguous now that I review it again. He does say search and replace but I'm not sure if that's what he really wants. It looks more like search with one string and highlight all like-strings. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] case and accent - insensitive regular expression?
Hi, I have a php page that asks user for a key ( or a list of keys ) and then shows a list of items matching the query. every item in the list shows its data, and the list of keys it has ( a list of comma-separated words ) I would like to higlight, in the list of keys shown for every item, the words matching the query, this can be easily achieved with a search and replace, for every search word, i search it in the key list and replace it adding a style tag to higlight it such as for example to have it in red color: if ( @stripos($keylist,$keysearch!== false ) { $keylist = str_ireplace($keysearch,'span style=color: #FF'. $keysearch.'/span',$keylist); } but i have some problem with accented characters: i have mysql with character encoding utf8, and all the php pages are declared as utf8 mysql in configured to perform queries in a case and accent insensitive way. this mean that if you search for the word 'cafe', you have returned rows that contains in the keyword list 'cafe', but also 'café' with the accent. ( I think it has to do with 'collation' settings, but I'm not investigating at the moment because it is OK for me the way it works ). now my problem is to find a way ( I imagine with some kind of regular expression ) to achieve in php a search and replace accent- insensitive, so that i can find the word 'cafe' in a string also if it is 'café', or 'CAFÉ', or 'CAFE', and vice-versa. hope the problem is clear and well-explained in english, thank you for any tip, Giulio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] case and accent - insensitive regular expression?
At 9:36 AM +0200 7/12/08, Giulio Mastrosanti wrote: Hi, I have a php page that asks user for a key ( or a list of keys ) and then shows a list of items matching the query. every item in the list shows its data, and the list of keys it has ( a list of comma-separated words ) I would like to higlight, in the list of keys shown for every item, the words matching the query, this can be easily achieved with a search and replace, for every search word, i search it in the key list and replace it adding a style tag to higlight it such as for example to have it in red color: if ( @stripos($keylist,$keysearch!== false ) { $keylist = str_ireplace($keysearch,'span style=color: #FF'.$keysearch.'/span',$keylist); } but i have some problem with accented characters: i have mysql with character encoding utf8, and all the php pages are declared as utf8 mysql in configured to perform queries in a case and accent insensitive way. this mean that if you search for the word 'cafe', you have returned rows that contains in the keyword list 'cafe', but also 'café' with the accent. ( I think it has to do with 'collation' settings, but I'm not investigating at the moment because it is OK for me the way it works ). now my problem is to find a way ( I imagine with some kind of regular expression ) to achieve in php a search and replace accent-insensitive, so that i can find the word 'cafe' in a string also if it is 'café', or 'CAFÉ', or 'CAFE', and vice-versa. hope the problem is clear and well-explained in english, thank you for any tip, Giulio Giulio: Three things: 1. Your English is fine. 2. Try using mb_ereg_replace() http://www.php.net/mb_ereg_replace Place the accents you want to change in that and change them to whatever you want. 3. Change: span style=color: #FF'.$keysearch.'/span' to span class=keysearch'.$keysearch.'/span' and add .keysearch { color: #FF; } to your css. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Case sensitive password
В сообщении от Friday 20 June 2008 23:05:55 Andrew Ballard написал(а): if(preg_match('/^'.$_SESSION['userpass'].'$/i',$login)) { So, why you use /i ? :-) -- === С уважением, Манылов Павел aka [R-k] icq: 949-388-0 mailto:[EMAIL PROTECTED] === А ещё говорят так: The higher the higher-ups are who have come to see your demo, the lower your chances are of giving a successful one -- Fundamental Law of Thermodynamics n?4 [fortune]
Re: [PHP] Case sensitive password
On Thu, Jun 19, 2008 at 7:29 PM, Kyle Browning [EMAIL PROTECTED] wrote: Why not md5 the password, and store the md5 encryption. Then when they type something in, md5 it and compare the md5 strings. That will ensure that it is Case Sensitive On Thu, Jun 19, 2008 at 2:04 PM, R.C. [EMAIL PROTECTED] wrote: Thank you Daniel, I think that did the trick. Am checking this out now... Best R.C. Daniel Brown [EMAIL PROTECTED] wrote in message session_start(); $_SESSION ['userpass'] = $_POST ['pass']; $_SESSION ['authuser'] = 0; $login = VIDEO; $login2 = video; if (($_SESSION['userpass'] == $login) or ($_SESSION['userpass'] == $login2)) { $_SESSION['authuser'] = 1; ? Try this: ?php if(preg_match('/^'.$_SESSION['userpass'].'$/i',$login)) { echo Good.\n; } else { echo Bad.\n; } ? Because that would make the password comparison case-sensitive (as one might reasonably infer from the subject of the message). However, the OP wanted the password to be case-INsensitive. Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Case sensitive password
At 9:36 PM -0700 6/18/08, R.C. wrote: I have coded a php page that accepts a password. What is the code to make sure the password entered is NOT case-sensitive? Thanks much R.C. Why? If a user has selected a password, then leave it alone and don't change it -- it's their password. If a user has difficulty remembering their password, then make sure there's a forgot password option in the sign on. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Case sensitive password
On Thu, Jun 19, 2008 at 12:45 AM, Nathan Nobbe [EMAIL PROTECTED] wrote: i hate posting the same answer to a given question thats already been posted, but i had this all typed in when chris submitted his answer, so here it is again.. One of the very, very few things that pisses me off about Gmail, in fact. You take the time to type out a long, well-thought-out response, only to see that damned yellow box pop up in the bottom right indicating that someone else just responded to the thread. You'd swear we were getting paid to be the first to respond sometimes. ;-P -- /Daniel P. Brown Dedicated Servers - Intel 2.4GHz w/2TB bandwidth/mo. starting at just $59.99/mo. with no contract! Dedicated servers, VPS, and hosting from $2.50/mo. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Case sensitive password
Chris, Thank you. That worked good. Appreciate the assistance. Best R.C. Chris [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] R.C. wrote: Thank you for your reply. The password is not stored, actually, like in a databse. We're only dealing with one password. When the user inputs the password, he/she should be able to input either in lower or upper case or both abd they should have access to the protected file in this case. As Nathan mentioned, just compare them in the same way. $stored_password = strtolower($stored_password); $user_password = strtolower($user_password); if ($stored_password == $user_password) { echo Yay!; } else { echo No :(; } -- Postgresql php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Case sensitive password
Nathan, Thank you ... very thorough. Best R.C. Nathan Nobbe [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] i hate posting the same answer to a given question thats already been posted, but i had this all typed in when chris submitted his answer, so here it is again.. On Wed, Jun 18, 2008 at 10:36 PM, R.C. [EMAIL PROTECTED] wrote: I have coded a php page that accepts a password. What is the code to make sure the password entered is NOT case-sensitive? when you store the password, you can store it as all upper or all lowercase, then when comparing against the stored value, do the same operation to the value supplied from the user, and compare those. and you dont have to modify the original value if you dont want to, when you store it. just remember to alter both the stored value and the user-supplied value when doing comparisons. /// here is an example comparison // get password value from db for user, put it in $storedPassword // suppose the value the user supplied in a form is in variable $userSuppliedPassword // now for the case insensitive comparison if(strtolower($storedPassword) == strtolower($userSuppliedPassword)) // passwords are the same else // passwords are different also note in the above example, there is no encryption of the password, which you almost certainly want to have ;) -nathan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Case sensitive password
Tedd, thank you for your input but it's the site client who wants the user to input this ONE password either upper or lower case...it's for accessing a protected page... nothing major. But generally I agree... if the user has selected a password, that is what he/she wants and it should be left alone. BTW: I used Chris' and Nathan's code and it's working fine. Best R.C. tedd [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Why? If a user has selected a password, then leave it alone and don't change it -- it's their password. If a user has difficulty remembering their password, then make sure there's a forgot password option in the sign on. Cheers, tedd -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Case sensitive password
I've tried some of the methods mentioned in earlier posts, but I don't understand this correctly. Here is the code I have to validate a hard corded password to access a page, which is in upper case WHERE do I input the code to make sure that whatever case a user inputs this word, it will still validate? Thank you for your patience. I'm learning Best R.C. ?php session_start(); $_SESSION ['userpass'] = $_POST ['pass']; $_SESSION ['authuser'] = 0; $login = VIDEOS; if (($_SESSION['userpass'] == $login)) { $_SESSION['authuser'] = 1; ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Case sensitive password
At 8:59 AM -0700 6/19/08, R.C. wrote: Tedd, thank you for your input but it's the site client who wants the user to input this ONE password either upper or lower case...it's for accessing a protected page... nothing major. Nothing major until it is. As for the client, I always said Everyone has the right to be wrong. Ask the client this -- if two users have Cat and cAt for their passwords, what do you think the client's lability would be for changing them both to be identical when neither user approved? As I get older, I think about how to avoid lability more. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Case sensitive password
Hi Tedd, It is NOT the user who determines this ONE password, it's the client... he gives it out to selected folks to input For example: he says to a few people: use video to access this page okay? He would like to make this word case-insensitive so the few people can type in either Video or VIDEO or video. Now in the below code auth snippet WHERE do I input some code to make this one word case-insensitive UPON INPUT. thanks R.C. ?php session_start(); $_SESSION ['userpass'] = $_POST ['pass']; $_SESSION ['authuser'] = 0; $login = VIDEO; if (($_SESSION['userpass'] == $login)) { $_SESSION['authuser'] = 1; tedd [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] At 8:59 AM -0700 6/19/08, R.C. wrote: Tedd, thank you for your input but it's the site client who wants the user to input this ONE password either upper or lower case...it's for accessing a protected page... nothing major. Nothing major until it is. As for the client, I always said Everyone has the right to be wrong. Ask the client this -- if two users have Cat and cAt for their passwords, what do you think the client's lability would be for changing them both to be identical when neither user approved? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Case sensitive password
On Thu, Jun 19, 2008 at 3:11 PM, tedd [EMAIL PROTECTED] wrote: At 8:59 AM -0700 6/19/08, R.C. wrote: Tedd, thank you for your input but it's the site client who wants the user to input this ONE password either upper or lower case...it's for accessing a protected page... nothing major. Nothing major until it is. As for the client, I always said Everyone has the right to be wrong. Ask the client this -- if two users have Cat and cAt for their passwords, what do you think the client's lability would be for changing them both to be identical when neither user approved? As I get older, I think about how to avoid lability more. Cheers, tedd I could be wrong, but I didn't see anything about a username. It sounds to me more like it is a single password shared with all the people who should have access to a specific, non-personalized area of the site. It certainly wouldn't be my preferred way to set up security, but depending on the level of risk involved it may be sufficient. Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Case sensitive password
Andrew, That is correct. Only ONE password to access a restricted page for selected people. But... they want to make that ONE password case-insensitive. I added the following code with 2 variables now, one being upper case, one being lower case but that, of course, doesn't cover all the variatons on the video word. I'm looking for the code to make this whole word case-insensitive, no matter which letter is cap or not can you add to this code below please? Thanks much R.C. session_start(); $_SESSION ['userpass'] = $_POST ['pass']; $_SESSION ['authuser'] = 0; $login = VIDEO; $login2 = video; if (($_SESSION['userpass'] == $login) or ($_SESSION['userpass'] == $login2)) { $_SESSION['authuser'] = 1; ? Andrew Ballard [EMAIL PROTECTED] wrote in message I could be wrong, but I didn't see anything about a username. It sounds to me more like it is a single password shared with all the people who should have access to a specific, non-personalized area of the site. It certainly wouldn't be my preferred way to set up security, but depending on the level of risk involved it may be sufficient. Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Case sensitive password
On Thu, Jun 19, 2008 at 4:18 PM, R.C. [EMAIL PROTECTED] wrote: Andrew, That is correct. Only ONE password to access a restricted page for selected people. But... they want to make that ONE password case-insensitive. I added the following code with 2 variables now, one being upper case, one being lower case but that, of course, doesn't cover all the variatons on the video word. I'm looking for the code to make this whole word case-insensitive, no matter which letter is cap or not can you add to this code below please? session_start(); $_SESSION ['userpass'] = $_POST ['pass']; $_SESSION ['authuser'] = 0; $login = VIDEO; $login2 = video; if (($_SESSION['userpass'] == $login) or ($_SESSION['userpass'] == $login2)) { $_SESSION['authuser'] = 1; ? Try this: ?php if(preg_match('/^'.$_SESSION['userpass'].'$/i',$login)) { echo Good.\n; } else { echo Bad.\n; } ? -- /Daniel P. Brown Dedicated Servers - Intel 2.4GHz w/2TB bandwidth/mo. starting at just $59.99/mo. with no contract! Dedicated servers, VPS, and hosting from $2.50/mo. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Case sensitive password
Thank you Daniel, I think that did the trick. Am checking this out now... Best R.C. Daniel Brown [EMAIL PROTECTED] wrote in message session_start(); $_SESSION ['userpass'] = $_POST ['pass']; $_SESSION ['authuser'] = 0; $login = VIDEO; $login2 = video; if (($_SESSION['userpass'] == $login) or ($_SESSION['userpass'] == $login2)) { $_SESSION['authuser'] = 1; ? Try this: ?php if(preg_match('/^'.$_SESSION['userpass'].'$/i',$login)) { echo Good.\n; } else { echo Bad.\n; } ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Case sensitive password
Why not md5 the password, and store the md5 encryption. Then when they type something in, md5 it and compare the md5 strings. That will ensure that it is Case Sensitive On Thu, Jun 19, 2008 at 2:04 PM, R.C. [EMAIL PROTECTED] wrote: Thank you Daniel, I think that did the trick. Am checking this out now... Best R.C. Daniel Brown [EMAIL PROTECTED] wrote in message session_start(); $_SESSION ['userpass'] = $_POST ['pass']; $_SESSION ['authuser'] = 0; $login = VIDEO; $login2 = video; if (($_SESSION['userpass'] == $login) or ($_SESSION['userpass'] == $login2)) { $_SESSION['authuser'] = 1; ? Try this: ?php if(preg_match('/^'.$_SESSION['userpass'].'$/i',$login)) { echo Good.\n; } else { echo Bad.\n; } ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Case sensitive password
At 4:06 PM -0400 6/19/08, Andrew Ballard wrote: I could be wrong, but I didn't see anything about a username. It sounds to me more like it is a single password shared with all the people who should have access to a specific, non-personalized area of the site. It certainly wouldn't be my preferred way to set up security, but depending on the level of risk involved it may be sufficient. Andrew Andrew: I had the exact same case with a client. My client teaches classes and wanted to provide the attendees with a url where they could download PDF files for the class. In this case, they only needed a password AND the password was identical for everyone. Sure attendees could distribute the url and password, but requiring a password makes it just a bit harder than just giving out the url and allowing everyone/thing to download the files. The file were delivered to the user by a password protected script, so no one could bookmark the files. And doing it this way required no effort by my client to keep track of user names. He just taught the class, gave out the url/password, and the software did the rest. So, in this case it made sense. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Case sensitive password
I have coded a php page that accepts a password. What is the code to make sure the password entered is NOT case-sensitive? Thanks much R.C. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Case sensitive password
R.C. wrote: I have coded a php page that accepts a password. What is the code to make sure the password entered is NOT case-sensitive? Before you store the password, make it all lowercase (or uppercase, whatever you prefer). $password = strtolower($password); When you compare the passwords, turn it all to lower (or upper) case before you compare it. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Case sensitive password
i hate posting the same answer to a given question thats already been posted, but i had this all typed in when chris submitted his answer, so here it is again.. On Wed, Jun 18, 2008 at 10:36 PM, R.C. [EMAIL PROTECTED] wrote: I have coded a php page that accepts a password. What is the code to make sure the password entered is NOT case-sensitive? when you store the password, you can store it as all upper or all lowercase, then when comparing against the stored value, do the same operation to the value supplied from the user, and compare those. and you dont have to modify the original value if you dont want to, when you store it. just remember to alter both the stored value and the user-supplied value when doing comparisons. /// here is an example comparison // get password value from db for user, put it in $storedPassword // suppose the value the user supplied in a form is in variable $userSuppliedPassword // now for the case insensitive comparison if(strtolower($storedPassword) == strtolower($userSuppliedPassword)) // passwords are the same else // passwords are different also note in the above example, there is no encryption of the password, which you almost certainly want to have ;) -nathan
Re: [PHP] Case sensitive password
Thank you for your reply. The password is not stored, actually, like in a databse. We're only dealing with one password. When the user inputs the password, he/she should be able to input either in lower or upper case or both abd they should have access to the protected file in this case. Is this what you are recommending below? Best R.C. Chris [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] R.C. wrote: I have coded a php page that accepts a password. What is the code to make sure the password entered is NOT case-sensitive? Before you store the password, make it all lowercase (or uppercase, whatever you prefer). $password = strtolower($password); When you compare the passwords, turn it all to lower (or upper) case before you compare it. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Case sensitive password
R.C. wrote: Thank you for your reply. The password is not stored, actually, like in a databse. We're only dealing with one password. When the user inputs the password, he/she should be able to input either in lower or upper case or both abd they should have access to the protected file in this case. As Nathan mentioned, just compare them in the same way. $stored_password = strtolower($stored_password); $user_password = strtolower($user_password); if ($stored_password == $user_password) { echo Yay!; } else { echo No :(; } -- Postgresql php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Case insensitive ksort
Christoph Boget wrote: I looked in the docs but didn't see anything regarding case insensitivity and I fear the functionality doesn't exist. I'm just hoping I'm looking in the wrong place. Is there a way to get ksort to work without regard to case? When I sort an array using ksort, all the upper case keys end up at the top (sorted) and all the lower case keys end up at the bottom (sorted). Ideally, I'd like to see all the keys sorted (and intermixed) regardless of case. Am I going to have to do this manually? Or is there an internal php command that will do it for me? thnx, Christoph Is this what you are looking for? ?php $yourarray = array(); $sorted = natcasesort(array_keys($yourarray)); foreach ( $sorted AS $key ) { echo $yourarray[$key]; } ? -- Jim Lucas Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them. Twelfth Night, Act II, Scene V by William Shakespeare -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Case insensitive ksort
I looked in the docs but didn't see anything regarding case insensitivity and I fear the functionality doesn't exist. I'm just hoping I'm looking in the wrong place. Is there a way to get ksort to work without regard to case? When I sort an array using ksort, all the upper case keys end up at the top (sorted) and all the lower case keys end up at the bottom (sorted). Ideally, I'd like to see all the keys sorted (and intermixed) regardless of case. Am I going to have to do this manually? Or is there an internal php command that will do it for me? thnx, Christoph -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Case insensitive ksort
On 18/09/2007, Christoph Boget [EMAIL PROTECTED] wrote: I looked in the docs but didn't see anything regarding case insensitivity and I fear the functionality doesn't exist. I'm just hoping I'm looking in the wrong place. Is there a way to get ksort to work without regard to case? When I sort an array using ksort, all the upper case keys end up at the top (sorted) and all the lower case keys end up at the bottom (sorted). Ideally, I'd like to see all the keys sorted (and intermixed) regardless of case. Am I going to have to do this manually? Or is there an internal php command that will do it for me? uksort($array, 'strcasecmp'); -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Case insensitive ksort
I don't have time to look up in the manual but I don't remember a case insensitive ksort(). I think there's a uksort() where you could specify your own sorting parameters for the keys. Also, you could create the array with keys run through strtoupper() or strtolower(). If you need the proper upper/lowercase version too, you could store that separately within the array. Just some thoughts on how you could do this. good luck! -TG - Original Message - From: Christoph Boget [EMAIL PROTECTED] To: php-general@lists.php.net Date: Tue, 18 Sep 2007 11:37:01 -0400 Subject: [PHP] Case insensitive ksort I looked in the docs but didn't see anything regarding case insensitivity and I fear the functionality doesn't exist. I'm just hoping I'm looking in the wrong place. Is there a way to get ksort to work without regard to case? When I sort an array using ksort, all the upper case keys end up at the top (sorted) and all the lower case keys end up at the bottom (sorted). Ideally, I'd like to see all the keys sorted (and intermixed) regardless of case. Am I going to have to do this manually? Or is there an internal php command that will do it for me? thnx, Christoph -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] [Case Closed - Idiot Found Behind Keyboard] Re: [PHP] APC - problems with CLI odd return values from apc_clear_cache()
Jon Anderson wrote: Just replying to the list on this one 'cause I'm pretty sure you're on it. :-) AFAIK, with many caches the web server cache and CLI caches are exclusive to each process. The APC manual seems to suggest that the CLI cache is not connected to the web server cache: From: http://ca.php.net/manual/en/ref.apc.php apc.enable_cli *integer* http://ca.php.net/manual/en/language.types.integer.php Mostly for testing and debugging. Setting this enables APC for the CLI version of PHP. Normally you wouldn't want to create, populate and tear down the APC cache on every CLI request, but for various test scenarios it is handy to be able to enable APC for the CLI version of APC easily. thanks, you are right - what I thought had been working all this time had not, or atleast the code did work but it was clearing the cache belonging to the CLI, which was a pointless act! I'm an idiot. but wanting to clear the webservers APC cache from a cmdline script doesn't seem like such a stupid thing to want to do. but there is no nice way of doing it; so now I do this at the end of my cmdline script instead: exec('apachectl -k graceful'); which sucks in so many ways it hurts but it does clear the APC cache :-/ jon Jochem Maas wrote: hi people, PHP version:5.1.1(last built: Dec 28 2005 16:03:22) APC version: 3.8.10 Apache version:2.0.54(last built: Dec 29 2005 14:04:16) OS:debian I have a script that runs via the cmdline, it's used to import/update data in a database, after the script is run the APC cache needs to be cleared so that that the new/updated data is visible on the website. to do this I call a static method of my cache management class which effectively performs the following: apc_clear_cache(); apc_clear_cache(user); this used to work, but now it does not (atleast not on the cmdline; calling the above mentioned method via a webrequest still works). I have not recently updated php, apc or apache, neither have made any changes to the php.ini configuration. someone else may have updated the OS/system (and I can't rule out that . to test the problem I ran the following code at the cmdline: # php -r 'var_dump( ini_get(apc.enable_cli), apc_clear_cache(), apc_clear_cache(user) );' this is the output I get: string(1) 1 NULL bool(true) so apc is enabled for the cli, cache clearance seems to work but when I checking the output of the apc.php file (shipped with the apc package) I see that nothing has been cleared; performing the same apc_clear_cache() calls (by way of pressing the buttons on the page output by apc.php) via the webserver module *does* clear the cache. it seems all of a sudden that the CLI and then apache SAPI are looking at different caches - running apc_cache_info() apc_sma_info() on the commandline show nothing in the cache whereas viewing the stats produced by apc.php (via the webserver) shows plenty of stuff in the cache (both before and after running apc_cache_info() apc_sma_info() on the commandline) can anyone offer some help/idea/etc? Another Thing: === although the manual states that apc_clear_cache() should always return a boolean calling it calling the function without any args *always* returns NULL. can anyone say whether this is a bug or a documentation problem? My APC ini settings (as defined in a seperate apc.ini): === ; Enable APC extension module extension = apc.so [APC] apc.enabled = 1 apc.shm_segments= 2 apc.shm_size= 128 apc.optimization= 0 apc.num_files_hint = 2000 ; ? apc.ttl = 180 apc.gc_ttl = 0 apc.slam_defense= 0 apc.file_update_protection = 0 ; 1 apc.cache_by_default= 1 apc.enable_cli = 1 apc.filters = -.*\.class\.php ; +\.tpl\.php,+.*\.interface\.php,+.*\.funcs\.php ; +.*\.class\.php ;apc.max_file_size = 8M apc.user_entries_hint = 0 apc.user_ttl= 0 ; this fixes a bug that causes $_SERVER not to be defined on 2nd/subsequent requests auto_globals_jit= Off -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] [Case Closed - Idiot Found Behind Keyboard] Re: [PHP] APC - problems with CLI odd return values from apc_clear_cache()
On Saturday 29 July 2006 05:47, Jochem Maas wrote: Jon Anderson wrote: Just replying to the list on this one 'cause I'm pretty sure you're on it. :-) AFAIK, with many caches the web server cache and CLI caches are exclusive to each process. The APC manual seems to suggest that the CLI cache is not connected to the web server cache: From: http://ca.php.net/manual/en/ref.apc.php apc.enable_cli *integer* http://ca.php.net/manual/en/language.types.integer.php Mostly for testing and debugging. Setting this enables APC for the CLI version of PHP. Normally you wouldn't want to create, populate and tear down the APC cache on every CLI request, but for various test scenarios it is handy to be able to enable APC for the CLI version of APC easily. thanks, you are right - what I thought had been working all this time had not, or atleast the code did work but it was clearing the cache belonging to the CLI, which was a pointless act! I'm an idiot. but wanting to clear the webservers APC cache from a cmdline script doesn't seem like such a stupid thing to want to do. but there is no nice way of doing it; so now I do this at the end of my cmdline script instead: exec('apachectl -k graceful'); which sucks in so many ways it hurts but it does clear the APC cache You could create a script that basically just does apc_clear_cache() et all. and call it from lynx, curl, wget, etc. and throw that into a cron job. That would technically get you to call the script from the cli, but it should clear the webserver cache. Ray -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] [Case Closed - Idiot Found Behind Keyboard] Re: [PHP] APC - problems with CLI odd return values from apc_clear_cache()
Ray Hauge wrote: On Saturday 29 July 2006 05:47, Jochem Maas wrote: Jon Anderson wrote: Just replying to the list on this one 'cause I'm pretty sure you're on it. :-) AFAIK, with many caches the web server cache and CLI caches are exclusive to each process. The APC manual seems to suggest that the CLI cache is not connected to the web server cache: From: http://ca.php.net/manual/en/ref.apc.php apc.enable_cli *integer* http://ca.php.net/manual/en/language.types.integer.php Mostly for testing and debugging. Setting this enables APC for the CLI version of PHP. Normally you wouldn't want to create, populate and tear down the APC cache on every CLI request, but for various test scenarios it is handy to be able to enable APC for the CLI version of APC easily. thanks, you are right - what I thought had been working all this time had not, or atleast the code did work but it was clearing the cache belonging to the CLI, which was a pointless act! I'm an idiot. but wanting to clear the webservers APC cache from a cmdline script doesn't seem like such a stupid thing to want to do. but there is no nice way of doing it; so now I do this at the end of my cmdline script instead: exec('apachectl -k graceful'); which sucks in so many ways it hurts but it does clear the APC cache You could create a script that basically just does apc_clear_cache() et all. and call it from lynx, curl, wget, etc. and throw that into a cron job. That would technically get you to call the script from the cli, but it should clear the webserver cache. I thought about that but it means dealing with my own login system and apart from having to figure that out, it's seems like a kludge ... in the end hitting apache with a 'graceful' was alot quicker to get running ;-) Ray -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Case issue with eregi_replace in text highlight function
Hi all! I have a text highlight function which does not behave exactly as needed. Behavior is logical but result is cumbersome. Instead of replacing the portion of the text with the same portion of text with some highlighting code added before and after, it replaces the said text with the chunk of text looked for (highlight), which is an issue when there is a difference in case. It is used in a product search engine and it is important to keep the case the same. Here is the function: function highlight_text($text, $highlight) { return eregi_replace($highlight, span class=highlight . $highlight . /span, $text); } In this case, if the text to highglight is: MacOS X Super Gizmo And a client searches for the string macos, the result will be: span class=highlightmacos/span X Super Gizmo Not very pritty. How complicated would it be to prevent this from happening? Thanks a lot in advance! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Case issue with eregi_replace in text highlight function
Here is the function: function highlight_text($text, $highlight) { return eregi_replace($highlight, span class=highlight . $highlight . /span, $text); } In this case, if the text to highglight is: MacOS X Super Gizmo And a client searches for the string macos, the result will be: span class=highlightmacos/span X Super Gizmo You're using the eregi_replace function - which does case insensitive replaces (read the man page). Change it to use ereg_replace -- Postgresql php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Case issue with eregi_replace in text highlight function
That's not where the issue is. Eregi_replace conducts a case insensitive SEARCH but how the REPLACE operates has nothing to do with it. If you use ereg_replace, then it is most obviously not going to replace MacOS with span class=highlightmacos/span or even span class=highlightMacOS/span, because the string searched for is of a different case. But thanks for helping. -Original Message- From: Chris [mailto:[EMAIL PROTECTED] Sent: Wednesday, February 22, 2006 5:39 PM To: Nicolas Verhaeghe Cc: php-general@lists.php.net Subject: Re: [PHP] Case issue with eregi_replace in text highlight function Here is the function: function highlight_text($text, $highlight) { return eregi_replace($highlight, span class=highlight . $highlight . /span, $text); } In this case, if the text to highglight is: MacOS X Super Gizmo And a client searches for the string macos, the result will be: span class=highlightmacos/span X Super Gizmo You're using the eregi_replace function - which does case insensitive replaces (read the man page). Change it to use ereg_replace -- Postgresql php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Case issue with eregi_replace in text highlight function
Nicolas Verhaeghe wrote: That's not where the issue is. Eregi_replace conducts a case insensitive SEARCH but how the REPLACE operates has nothing to do with it. If you use ereg_replace, then it is most obviously not going to replace MacOS with span class=highlightmacos/span or even span class=highlightMacOS/span, because the string searched for is of a different case. Good point, I had it around the wrong way. function highlight_text($text, $highlight) { return eregi_replace($highlight, span class=highlight . $highlight . /span, $text); } So where does 'highlight' come from when you pass it in ? -- Postgresql php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Case issue with eregi_replace in text highlight function
How about function highlight_text($text, $highlight) { return preg_replace('/(' . $highlight . ')/i', 'span class=highlight$1/span', $text); } Case should be retained and the search is case insensitive HTH Dan --- http://chrome.me.uk -Original Message- From: Nicolas Verhaeghe [mailto:[EMAIL PROTECTED] Sent: 23 February 2006 00:55 To: 'Chris' Cc: php-general@lists.php.net Subject: RE: [PHP] Case issue with eregi_replace in text highlight function That's not where the issue is. Eregi_replace conducts a case insensitive SEARCH but how the REPLACE operates has nothing to do with it. If you use ereg_replace, then it is most obviously not going to replace MacOS with span class=highlightmacos/span or even span class=highlightMacOS/span, because the string searched for is of a different case. But thanks for helping. -Original Message- From: Chris [mailto:[EMAIL PROTECTED] Sent: Wednesday, February 22, 2006 5:39 PM To: Nicolas Verhaeghe Cc: php-general@lists.php.net Subject: Re: [PHP] Case issue with eregi_replace in text highlight function Here is the function: function highlight_text($text, $highlight) { return eregi_replace($highlight, span class=highlight . $highlight . /span, $text); } In this case, if the text to highglight is: MacOS X Super Gizmo And a client searches for the string macos, the result will be: span class=highlightmacos/span X Super Gizmo You're using the eregi_replace function - which does case insensitive replaces (read the man page). Change it to use ereg_replace -- Postgresql php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php __ NOD32 1.1416 (20060222) Information __ This message was checked by NOD32 antivirus system. http://www.eset.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Case issue with eregi_replace in text highlight function
This does not highlight anything... Sorry! Thanks for the help -Original Message- From: Chrome [mailto:[EMAIL PROTECTED] Sent: Wednesday, February 22, 2006 6:19 PM To: 'Nicolas Verhaeghe'; 'Chris' Cc: php-general@lists.php.net Subject: RE: [PHP] Case issue with eregi_replace in text highlight function How about function highlight_text($text, $highlight) { return preg_replace('/(' . $highlight . ')/i', 'span class=highlight$1/span', $text); } Case should be retained and the search is case insensitive HTH Dan --- http://chrome.me.uk -Original Message- From: Nicolas Verhaeghe [mailto:[EMAIL PROTECTED] Sent: 23 February 2006 00:55 To: 'Chris' Cc: php-general@lists.php.net Subject: RE: [PHP] Case issue with eregi_replace in text highlight function That's not where the issue is. Eregi_replace conducts a case insensitive SEARCH but how the REPLACE operates has nothing to do with it. If you use ereg_replace, then it is most obviously not going to replace MacOS with span class=highlightmacos/span or even span class=highlightMacOS/span, because the string searched for is of a different case. But thanks for helping. -Original Message- From: Chris [mailto:[EMAIL PROTECTED] Sent: Wednesday, February 22, 2006 5:39 PM To: Nicolas Verhaeghe Cc: php-general@lists.php.net Subject: Re: [PHP] Case issue with eregi_replace in text highlight function Here is the function: function highlight_text($text, $highlight) { return eregi_replace($highlight, span class=highlight . $highlight . /span, $text); } In this case, if the text to highglight is: MacOS X Super Gizmo And a client searches for the string macos, the result will be: span class=highlightmacos/span X Super Gizmo You're using the eregi_replace function - which does case insensitive replaces (read the man page). Change it to use ereg_replace -- Postgresql php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php __ NOD32 1.1416 (20060222) Information __ This message was checked by NOD32 antivirus system. http://www.eset.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Case-Insensitive include on linux.
Hi, this is very stupid because you can have files in a directory named: PleaSeINCLUDeMe.php pleaseincludeme.php and if you do a case insensitive include which one should be included? The include stuff works insensitive under windows great because the filesystem does not permit 2 file with the same name in a directory. The example above is not possible. -- Marco 2006/1/11, Albert [EMAIL PROTECTED]: Mathijs wrote: Is there a way to have include() be case-insensitive? Linux file systems are case sensitive. The include() and require() functions try to open the file specified. If you enter the wrong case the file system will return that the file does not exist. Albert -- No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.1.371 / Virus Database: 267.14.17/226 - Release Date: 2006/01/10 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Marco Kaiser
RE: [PHP] Case-Insensitive include on linux.
Mathijs wrote: Is there a way to have include() be case-insensitive? If you are know that all your file and directory names are lower case, but users may input mixed case responses that will be used to determine the include, you can set the case of the user input to lower case with strtolower(). Or strtoupper() - the choice is yours. If you have been a bit careless in naming your directories or filenames, then I'd do some site maintenance and get that sorted first. George -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Case-Insensitive include on linux.
George Pitcher wrote: Mathijs wrote: Is there a way to have include() be case-insensitive? If you are know that all your file and directory names are lower case, but users may input mixed case responses that will be used to determine the include, you can set the case of the user input to lower case with strtolower(). Or strtoupper() - the choice is yours. If you have been a bit careless in naming your directories or filenames, then I'd do some site maintenance and get that sorted first. George Owkay, its clear :). I just wondered if it was possible, would save some other trouble :). Thx for the help. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Case-Insensitive include on linux.
Hello there, Is there a way to have include() be case-insensitive? This would be very handy. Thx in advanced. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Case-Insensitive include on linux.
Mathijs wrote: Is there a way to have include() be case-insensitive? Linux file systems are case sensitive. The include() and require() functions try to open the file specified. If you enter the wrong case the file system will return that the file does not exist. Albert -- No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.1.371 / Virus Database: 267.14.17/226 - Release Date: 2006/01/10 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] CASE Tool For PHP OO Programming
DIA with the estension xml2php5 Le Mon, 11 Jul 2005 15:22:32 +0200, Pascual De Ruvo [EMAIL PROTECTED] a écrit: Hi, Can someone suggest a free CASE Tool for UML modelling that generates PHP 5 code? Thanks in advance, Pascual De Ruvo -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] CASE Tool For PHP OO Programming
I have been using Sparx Systems Enterprise Architect. david forums [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] DIA with the estension xml2php5 Le Mon, 11 Jul 2005 15:22:32 +0200, Pascual De Ruvo [EMAIL PROTECTED] a écrit: Hi, Can someone suggest a free CASE Tool for UML modelling that generates PHP 5 code? Thanks in advance, Pascual De Ruvo -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] CASE Tool For PHP OO Programming
Hi, Can someone suggest a free CASE Tool for UML modelling that generates PHP 5 code? Thanks in advance, Pascual De Ruvo
[PHP] [case closed][Fwd: Re: [PHP-DEV] [Fwd: [PHP] constant() - php5]]
thanks for that explanation, case closed. :-) Original Message Return-Path: [EMAIL PROTECTED] X-Original-To: [EMAIL PROTECTED] Subject: Re: [PHP-DEV] [Fwd: [PHP] constant() - php5] X-Virus-Scanned: amavisd-new at moulin.nl Due to PHPs dynamic typing, unquoted strings are treated as strings unless a constant by that name exists. Thankfully it's clever enough to raise a notice to tell you it couldn't find a constant by that name, which makes debugging much easier. The reason constant() throws a warning rather than a notice is because PHP knows you're looking for a constant by that name and flags it as a more serious error, wheras before, it could just be that you want to use an unquoted string :) If you think it's a bit strange, it may seem so, but logically, if an unquoted number is equivilent to it's quoted counter-part, the same must be true for strings. Nicholas Telford Jochem Maas wrote: Derick Rethans wrote: On Fri, 1 Jul 2005, Jochem Maas wrote: echo constant('CNST'); when: echo CNST; only triggers an E_NOTICE. (assuming, in both cases that CNST is not defined). IMHO it should at most trigger an E_NOTICE. Did you compare the output of the two statements? I did. echo constant('CNST'); shows nothing (except the warning) echo CNST; shows CNST (and a notice). This makes perfect sense to me to differentiate between them like this. ok - agreed that the echo behaviour is logical - but I wasn't actually pertaining to the echo behaviour (and what was being echo'ed wasn't relevant to my original question). my point is that using a constant directly in your code when that constant doesn't exist only causes an E_NOTICE but passing a string to constant() when a constant of the given name doesn't exist causes an E_WARNING. I would either expect both to cause the same level of error OR that trying to use an undefined constant directly in code would cause a lower level of error. but if you say the error output behaviour is expected/correct/desired then I'm happy to except it (and adjust my expectations accordingly) - if you (anyone) could explain why (because I don't grok the logic behind this behaviour) I would be very grateful, maybe it will bring me one step closer to being able to call myself a real programmer. :-/ anyway thanks for taking the time to reply, I gather that you, Derick (amongst others!), have a plate full of PHP work in the form of unicode and date related stuff (which I am very much looking forward to!) - i.e. you are busy-busy, time is short, etc etc. kind rgds, Jochem Derick -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] CASE tool
Hello, can anybody here tell me if there is a (open souce) CASE tool which supports PHP code generation? I could not find anything like this yet. What's the best way designing PHP applikations? I guess anybody knows a whitepaper or tutorial URI ?! Thanks Krid -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] case insensitive sort
I am using the following function for a sort on an array. I hope someone can help me out here and let me know how to change it to make it a case insensitivie sort. Right now, it is case sensitive so the sort of the array will put the Capital letters first. Here are the results of the search: Buehler, Steve Buehler, Steve Teste, Teste a, a asdf, adsf asdf, asdf dsdlkj, sd Here is the code to sort: $GLOBALS[sortterm]=cont_name; usort($logins, cmp); function cmp ($a, $b) { GLOBAL $sortterm; return strcmp($a[$sortterm], $b[$sortterm]); } Thanks Steve -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] case insensitive sort
Ok. Now I REALLY feel like an idiot. Thanks so much for your help. Steve At 05:46 PM 8/26/2003 +0200, you wrote: It right there under your nose: strcasecmp() Steve Buehler wrote: I am using the following function for a sort on an array. I hope someone can help me out here and let me know how to change it to make it a case insensitivie sort. Right now, it is case sensitive so the sort of the array will put the Capital letters first. Here are the results of the search: Buehler, Steve Buehler, Steve Teste, Teste a, a asdf, adsf asdf, asdf dsdlkj, sd Here is the code to sort: $GLOBALS[sortterm]=cont_name; usort($logins, cmp); function cmp ($a, $b) { GLOBAL $sortterm; return strcmp($a[$sortterm], $b[$sortterm]); } Thanks Steve -- This message has been scanned for viruses and dangerous content by the MailScanner at ow4, and is believed to be clean. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] case insensitive sort
It right there under your nose: strcasecmp() Steve Buehler wrote: I am using the following function for a sort on an array. I hope someone can help me out here and let me know how to change it to make it a case insensitivie sort. Right now, it is case sensitive so the sort of the array will put the Capital letters first. Here are the results of the search: Buehler, Steve Buehler, Steve Teste, Teste a, a asdf, adsf asdf, asdf dsdlkj, sd Here is the code to sort: $GLOBALS[sortterm]=cont_name; usort($logins, cmp); function cmp ($a, $b) { GLOBAL $sortterm; return strcmp($a[$sortterm], $b[$sortterm]); } Thanks Steve -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Case Matching
Not really sure if this would be a PHP or a MySQL issue. I'm using a database to store username for authentication purposes. Is there a way to make the user entry match case in the mysql database? Right now I have some users with all uppercase usernames that are able to login typing their username in all lower case letters. TIA, Ed -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Case Matching
What field type did you make the usernames? TEXT types are case incensitives use VARCHAR *** REPLY SEPARATOR *** On 06/01/2003 at 2:09 PM [EMAIL PROTECTED] wrote: Not really sure if this would be a PHP or a MySQL issue. I'm using a database to store username for authentication purposes. Is there a way to make the user entry match case in the mysql database? Right now I have some users with all uppercase usernames that are able to login typing their username in all lower case letters. TIA, Ed -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Cheers, Mike - Hlade's Law:If you have a difficult task, give it to a lazy person -- they will find an easier way to do it. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] case statement?
Hi- I was wondering if php had a case function? Instead of building a large if/elseif/else block I would like to do a case $page in (list). Thanks in advance, Max -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Fw: [PHP] case statement?
switch() { case a: case b: case c: default: } RTFM - Original Message - From: Max Clark [EMAIL PROTECTED] To: Sent: Thursday, December 19, 2002 12:19 PM Subject: [PHP] case statement? Hi- I was wondering if php had a case function? Instead of building a large if/elseif/else block I would like to do a case $page in (list). Thanks in advance, Max -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] case statement?
On Thu, 19 Dec 2002, Max Clark wrote: I was wondering if php had a case function? Instead of building a large if/elseif/else block I would like to do a case $page in (list). switch function ... http://www.php.net/manual/en/control-structures.switch.php ~Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] case statement?
-Original Message- From: Max Clark [mailto:[EMAIL PROTECTED]] Sent: 19 December 2002 18:19 I was wondering if php had a case function? Instead of building a large if/elseif/else block I would like to do a case $page in (list). http://www.php.net/control-structures.switch Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] case statement?
Yes, It's called SWITCH Just go to www.php.net and lookup switch in the function list Max Clark [EMAIL PROTECTED] wrote:Hi- I was wondering if php had a case function? Instead of building a large if/elseif/else block I would like to do a case $page in (list). Thanks in advance, Max -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] case statement?
On Thu, 19 Dec 2002, Max Clark wrote: Hi- I was wondering if php had a case function? Instead of building a large if/elseif/else block I would like to do a case $page in (list). The documentation and search capabilities at http://www.php.net are your frientd. It would behhove you to at least read the basic language statemants. mark C. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] == case-sensitive?
I've never really payed attention to this before, but now I noticed that == is case-sensitive, how do I make it == with different cases ? Håkan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] == case-sensitive?
I've never really payed attention to this before, but now I noticed that == is case-sensitive, how do I make it == with different cases ? if(strtolower($a) == strtolower($b)) -- Krzysztof Dziekiewicz -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] == case-sensitive?
Hi Hawk, I've never really payed attention to this before, but now I noticed that == is case-sensitive, how do I make it == with different cases ? Just force the case while you're comparing the two: if (strtolower($a) == strtolower($b)) { echo case-insensitive match; } else { echo no match; } Cheers Jon -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] == case-sensitive?
-Original Message- From: Hawk [mailto:[EMAIL PROTECTED]] Sent: 23 September 2002 12:33 To: [EMAIL PROTECTED] Subject: [PHP] == case-sensitive? I've never really payed attention to this before, but now I noticed that == is case-sensitive, how do I make it == with different cases ? Use strcasecmp(): strcasecmp($a, $b) // returns 0 if strings match case-insensitive // non-zero if not This is slightly unfortunate in that the test you have to do is counter-intuitive: if (strcasecmp($a, $b)): // strings DON'T match else: // strings match case-insensitively endif; Nonetheless, I'd prefer this over case-converting both strings and then comparing, as you're only making a single function call to do a comparison with in-line conversion, as opposed to two function calls for the conversions and then a comparison as well. (I guess I ought to benchmark that -- although it seems obvious, sometimes the obvious isn't!) Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Case Sensitivity
I've had a web site under development on my Win2k box at home. I built and tested everything with PHP 4.2.2 and Apache 1.3.24. Now, I have transitioned everything up to my host who is using a Linux box, PHP 4.2.2 and Apache 1.3.26. One of the pages I designed has code that retrieves a list of thumbnails from a directory name passed into the page then embeds a hyperlink to a full size version of the thumbnail. Incidentally, the full size version is in the same directory as the thumbnail and has a very similar filename: tn_01.jpg and 01.jpg (guess which one's the thumbnail). Here's the problem: When I run the page on the web host's server, the link to the full size image dies. I've tracked the problem to the case of the linked filename. Basically, unless the filename in the href matches the case of the target file, the link dies and I get that nice, little red X indicating the link to the image is broken. For example, the target image DSC01.JPG _MUST_ be referenced in the href as: href='../path/to/resource/DSC01.JPG' If I reference it as href='../path/to/resource/dsc01.jpg' the target image won't show up. I have temporarily resolved the issue by designating the filename used in the href as upper case using the strtoupper() function, but I can't believe that's the way it's SUPPOSED to be done. What I'd like to know is does the Linux server introduce case-sensitivity issues? It doesn't seem to matter with the elements of the path, just the target filename. Help is appreciated. Rich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Case Sensitivity
Linux file systems are case sensitive... So the file Hello.php is different to hello.php... Both can exist at the same time and contain different content, but they are different...On the windows file system files aren't case sensitive so Hello.php would be the same as hello.php... So I suggest in your PHP coding that you get all the cases (of files) the same throughout your app, or if you want to be lazy do what you are doing at the moment (ie changing the case with strtoupper()) Andrew - Original Message - From: Rich Hutchins [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, August 12, 2002 2:20 AM Subject: [PHP] Case Sensitivity I've had a web site under development on my Win2k box at home. I built and tested everything with PHP 4.2.2 and Apache 1.3.24. Now, I have transitioned everything up to my host who is using a Linux box, PHP 4.2.2 and Apache 1.3.26. One of the pages I designed has code that retrieves a list of thumbnails from a directory name passed into the page then embeds a hyperlink to a full size version of the thumbnail. Incidentally, the full size version is in the same directory as the thumbnail and has a very similar filename: tn_01.jpg and 01.jpg (guess which one's the thumbnail). Here's the problem: When I run the page on the web host's server, the link to the full size image dies. I've tracked the problem to the case of the linked filename. Basically, unless the filename in the href matches the case of the target file, the link dies and I get that nice, little red X indicating the link to the image is broken. For example, the target image DSC01.JPG _MUST_ be referenced in the href as: href='../path/to/resource/DSC01.JPG' If I reference it as href='../path/to/resource/dsc01.jpg' the target image won't show up. I have temporarily resolved the issue by designating the filename used in the href as upper case using the strtoupper() function, but I can't believe that's the way it's SUPPOSED to be done. What I'd like to know is does the Linux server introduce case-sensitivity issues? It doesn't seem to matter with the elements of the path, just the target filename. Help is appreciated. Rich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Case Sensitivity
Filesystems are meant to be case-sensitive, and yes, URL's are as well. It's an abomination that Windows and old-style Mac filesystems are not. You need to keep track of that in your code. 'a' and 'A' are just as different as 'a' and 'b'. -Rasmus On Sun, 11 Aug 2002, Rich Hutchins wrote: I've had a web site under development on my Win2k box at home. I built and tested everything with PHP 4.2.2 and Apache 1.3.24. Now, I have transitioned everything up to my host who is using a Linux box, PHP 4.2.2 and Apache 1.3.26. One of the pages I designed has code that retrieves a list of thumbnails from a directory name passed into the page then embeds a hyperlink to a full size version of the thumbnail. Incidentally, the full size version is in the same directory as the thumbnail and has a very similar filename: tn_01.jpg and 01.jpg (guess which one's the thumbnail). Here's the problem: When I run the page on the web host's server, the link to the full size image dies. I've tracked the problem to the case of the linked filename. Basically, unless the filename in the href matches the case of the target file, the link dies and I get that nice, little red X indicating the link to the image is broken. For example, the target image DSC01.JPG _MUST_ be referenced in the href as: href='../path/to/resource/DSC01.JPG' If I reference it as href='../path/to/resource/dsc01.jpg' the target image won't show up. I have temporarily resolved the issue by designating the filename used in the href as upper case using the strtoupper() function, but I can't believe that's the way it's SUPPOSED to be done. What I'd like to know is does the Linux server introduce case-sensitivity issues? It doesn't seem to matter with the elements of the path, just the target filename. Help is appreciated. Rich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] case-insensitive str_replace
Hi, I am in need of a case-insensitive str_replace. I've tried the search the archive and documentation, but the mostly suggested thing is to use eregi_replace. But this does not really solve the problem for me since the argument for eregi_replace can't be an array. The feature that I use in str_replace is to put the 'search' and 'replace' argument as an array, as described in the documentation for php = 4.0.5 Some people suggested some functions in the archive and documentation, but I cannot find anything that can receive arrays as the arguments. So I am wondering if anyone has a function that is fully compatible with str_replace for php 4.0.5, but case-insensitive (something like stri_replace). I don't really want to reinvent the wheel here. Thanks in advance. Reuben D. Budiardja -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Case Statements - lil help please
Are case statements not implemented in PHP4? If so, can someone help me debug this one, I seem to have some syntax incorrect, and am not sure what exactly is wrong with the statement. I get a parse error on the first line, but can't find any documentation on case statements in PHP4, so I am kinda stuck. thanks -Patrick # // check the error code and generate an appropriate error message switch ($e) { case -1: $message = No such user.; break; case 0: $message = Invalid username and/or password.; break; case 2: $message = Unauthorized access.; break; default: $message = An unspecified error occurred.; break; } _ Send and receive Hotmail on your mobile device: http://mobile.msn.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Case Statements - lil help please
Try the following... // check the error code and generate an appropriate error message switch($e) { case( -1): $message = No such user.; break; case(0): $message = Invalid username and/or password.; break; case(2): $message = Unauthorized access.; break; default: $message = An unspecified error occurred.; break; } - Original Message - From: Patrick Hartnett [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Sunday, March 31, 2002 12:03 AM Subject: [PHP] Case Statements - lil help please Are case statements not implemented in PHP4? If so, can someone help me debug this one, I seem to have some syntax incorrect, and am not sure what exactly is wrong with the statement. I get a parse error on the first line, but can't find any documentation on case statements in PHP4, so I am kinda stuck. thanks -Patrick # // check the error code and generate an appropriate error message switch ($e) { case -1: $message = No such user.; break; case 0: $message = Invalid username and/or password.; break; case 2: $message = Unauthorized access.; break; default: $message = An unspecified error occurred.; break; } _ Send and receive Hotmail on your mobile device: http://mobile.msn.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Case non-sensitive replacing with str_replace?
I'm doing some replacing with str_replace, but it's case sensitive. Is there any way to make it not case-sensitive? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Case non-sensitive replacing with str_replace?
use ereg_ireplace() or preg_ireplace() (the latter I'm not sure exists, but the former function does) -Original Message- From: Leif K-Brooks [mailto:[EMAIL PROTECTED]] Sent: Wednesday, March 20, 2002 4:16 PM To: [EMAIL PROTECTED] Subject: [PHP] Case non-sensitive replacing with str_replace? I'm doing some replacing with str_replace, but it's case sensitive. Is there any way to make it not case-sensitive? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Case non-sensitive replacing with str_replace?
On Wed, 20 Mar 2002, Martin Towell wrote: use ereg_ireplace() or preg_ireplace() (the latter I'm not sure exists, but the former function does) Close - it's eregi_replace(). To use preg_replace case-insensitively, just toss an 'i' at the end of your pattern. Instead of: preg_replace('/abc/', 'def', $x); use preg_replace('/abc/i', 'def', $x); miguel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Case non-sensitive replacing with str_replace?
on 3/20/02 12:24 AM, Martin Towell at [EMAIL PROTECTED] wrote: use ereg_ireplace() or preg_ireplace() (the latter I'm not sure exists, but the former function does) -Original Message- From: Leif K-Brooks [mailto:[EMAIL PROTECTED]] Sent: Wednesday, March 20, 2002 4:16 PM To: [EMAIL PROTECTED] Subject: [PHP] Case non-sensitive replacing with str_replace? I'm doing some replacing with str_replace, but it's case sensitive. Is there any way to make it not case-sensitive? First of all, the function is eregi_replace(), not ereg_ireplace(). Anyway, that one goes slower because it has regular expressions. Is there any function that does't have regular expressions, but isn't case sensitive?
RE: [PHP] case insenstive
Just substitute strstr() with stristr() The extra I in stristr() stands for Insensitive. If I was insensitive, I would say RTFM :) If you look under http://www.php.net/manual/en/function.strstr.php It tells you about stristr [TK] -Original Message- From: jtjohnston [mailto:[EMAIL PROTECTED]] Sent: Tuesday, 5 March 2002 5:08 PM To: [EMAIL PROTECTED] Subject: [PHP] case insenstive I need to make this case insensitive. This seems like over kill? if((substr($author, 0, 1) == a) or (substr($author, 0, 1) == a)) { } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] case insenstive
I need to make this case insensitive This seems like over kill? if((substr($author, 0, 1) == a) or (substr($author, 0, 1) == a)) { } -- PHP General Mailing List (http://wwwphpnet/) To unsubscribe, visit: http://wwwphpnet/unsubphp
RE: [PHP] case insenstive
I need to make this case insensitive. This seems like over kill? if((substr($author, 0, 1) == a) or (substr($author, 0, 1) == a)) { } if((strtolower(substr($author, 0, 1)) == a) { } :) J -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] case insenstive
if (eregi(^a, $author)) { print blah!; } Niklas -Original Message- From: jtjohnston [mailto:[EMAIL PROTECTED]] Sent: 5. maaliskuuta 2002 8:08 To: [EMAIL PROTECTED] Subject: [PHP] case insenstive I need to make this case insensitive. This seems like over kill? if((substr($author, 0, 1) == a) or (substr($author, 0, 1) == a)) { } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] case insenstive
Use strtolower() or strtoupper() to change the case of a string. And yes doing the same thing twice in the same statement is overkill! :) if((substr(strtolower($author), 0, 1) == a) || (substr(strtolower($author), 0, 1) == a)){} - Original Message - From: jtjohnston [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, March 04, 2002 11:08 PM Subject: [PHP] case insenstive I need to make this case insensitive. This seems like over kill? if((substr($author, 0, 1) == a) or (substr($author, 0, 1) == a)) { } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] case insenstive
if ($author[0]=='a' || $author[0]=='A') { } or (much slower) if (strtolower($author[0])=='a') { } -- PHP General Mailing List (http://wwwphpnet/) To unsubscribe, visit: http://wwwphpnet/unsubphp
[PHP] Case insensitive str_replace
Hello list. Need you help. My aim is to str_replace ($word,b$word/b,$str). But: i want str_replace not to differ uppers and lowers: Rector = bRec/btor after str_replace ('rec',brec/b,Rector) in other words. It seemes to me ereg can help, but i'm still not good at it. Help please Valentin Petruchek (aki Zliy Pes) http://zliypes.com.ua mailto:[EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]