JordanStreet Posted March 31, 2006 Share Posted March 31, 2006 What I am trying to do is create a script where s would = $ and w would equal @ and u would equal & etc. etc. So I know how to do that with the str_replace command. Now my question is could I make it so that if the first letter of the message was a-l it would use one set of replacements and if it was m-z it would use another set of replacements ?Thanks a bunchJordan Link to comment https://forums.phpfreaks.com/topic/6231-is-it-possible-too/ Share on other sites More sharing options...
bqallover Posted March 31, 2006 Share Posted March 31, 2006 Try this, using regular expressions.[code]if( eregi('^[a-l]', $my_message) ){ // ... do str_replace on $my_message for first set}else if( eregi('^[m-z]', $my_message) ){ // ... do str_replace on $my_message for second set}else { //... $my_message begins with a non-alphabetic char... }[/code]Hope that helps! Note: using the preg equivalents will be faster, but hey... Link to comment https://forums.phpfreaks.com/topic/6231-is-it-possible-too/#findComment-22520 Share on other sites More sharing options...
JordanStreet Posted March 31, 2006 Author Share Posted March 31, 2006 okay awsome :D so the eregi looks at the first letter ? Link to comment https://forums.phpfreaks.com/topic/6231-is-it-possible-too/#findComment-22622 Share on other sites More sharing options...
bqallover Posted March 31, 2006 Share Posted March 31, 2006 [!--quoteo(post=360348:date=Mar 31 2006, 02:30 PM:name=JordanStreet)--][div class=\'quotetop\']QUOTE(JordanStreet @ Mar 31 2006, 02:30 PM) [snapback]360348[/snapback][/div][div class=\'quotemain\'][!--quotec--]okay awsome :D so the eregi looks at the first letter ?[/quote]No worries. :)The eregi returns true if the pattern in the first string matches something in the second string. The 'i' in the function name tells you that it is case-insensitive. A quick rundown on the pattern - the caret (^) represents the beginning of the string, and the range of characters [a-l] will match any character in that range. So basically you're matching a single character in that range at the very beginning of your string. Check out pattern matching at places like [a href=\"http://www.regular-expressions.info/\" target=\"_blank\"]www.regular-expressions.info/[/a]Be aware though, that there are two forms (maybe more??) of regular expression. Normal (ereg, eregi, etc.) and Perl-compatible (preg, etc.) and there are differences between them. Hope that helps! :) Link to comment https://forums.phpfreaks.com/topic/6231-is-it-possible-too/#findComment-22641 Share on other sites More sharing options...
JordanStreet Posted April 1, 2006 Author Share Posted April 1, 2006 thanks man that help a lot ! Do you or someone know where I could find like a php cheat sheat that lists all of the functions with examples of the formula. I think im calling them right, I mean like stuff likechecking to see if two variables are the same is ($variable1 == $variable2) Link to comment https://forums.phpfreaks.com/topic/6231-is-it-possible-too/#findComment-22866 Share on other sites More sharing options...
bqallover Posted April 1, 2006 Share Posted April 1, 2006 One of the best PHP-oriented cheat sheets I've seen is at [a href=\"http://www.ilovejackdaniels.com/php/php-cheat-sheet/\" target=\"_blank\"]iLoveJackDaniels[/a]. It has general PHP stuff as well as regular expressions. Also check out the manual at [a href=\"http://www.php.net\" target=\"_blank\"]www.php.net[/a]. :) Link to comment https://forums.phpfreaks.com/topic/6231-is-it-possible-too/#findComment-22896 Share on other sites More sharing options...
JordanStreet Posted April 1, 2006 Author Share Posted April 1, 2006 alright thanks bro ill cya around Link to comment https://forums.phpfreaks.com/topic/6231-is-it-possible-too/#findComment-22907 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.