Jump to content

Is it possible too...


JordanStreet

Recommended Posts

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
Link to comment
Share on other sites

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
Share on other sites

[!--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
Share on other sites

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)
Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.