Jump to content


Photo

Is it possible too...


  • Please log in to reply
6 replies to this topic

#1 JordanStreet

JordanStreet
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 31 March 2006 - 02:09 AM

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 bunch
Jordan

#2 bqallover

bqallover
  • Members
  • PipPipPip
  • Advanced Member
  • 111 posts
  • LocationLeeds, UK

Posted 31 March 2006 - 02:42 AM

Try this, using regular expressions.

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... }

Hope that helps! Note: using the preg equivalents will be faster, but hey...

#3 JordanStreet

JordanStreet
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 31 March 2006 - 01:30 PM

okay awsome :D so the eregi looks at the first letter ?

#4 bqallover

bqallover
  • Members
  • PipPipPip
  • Advanced Member
  • 111 posts
  • LocationLeeds, UK

Posted 31 March 2006 - 02:17 PM

[!--quoteo(post=360348:date=Mar 31 2006, 02:30 PM:name=JordanStreet)--][div class=\'quotetop\']QUOTE(JordanStreet @ Mar 31 2006, 02:30 PM) View Post[/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! :)

#5 JordanStreet

JordanStreet
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 01 April 2006 - 12:55 PM

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 like

checking to see if two variables are the same is ($variable1 == $variable2)

#6 bqallover

bqallover
  • Members
  • PipPipPip
  • Advanced Member
  • 111 posts
  • LocationLeeds, UK

Posted 01 April 2006 - 04:08 PM

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]. :)

#7 JordanStreet

JordanStreet
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 01 April 2006 - 04:56 PM

alright thanks bro ill cya around




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users