Hi everybody!
I am trying to extract (delete) some characters that may appear at the end of the string. Here is the logic: If the string ends with "&" or "&a" or "&am" or "&" then delete those.
Any help?
<?php if (preg_match("/(\w+)(&|&a|&am)$/",$str)){ $str=preg_replace("/(\w+)(&|&a|&am)$/","\1",$str); } ?>
The above code should be able to handle it. however, it just pops out my mind in a split second. So, give it a try and tell me the result. =)
It works like a charm. Thanks a lot. Now tell me, what do I have to do in order to know regular expressions as you do? Buy a book, find an online tutorial, practice? This is a field that I have problems with.
PHP.net documentation should be a good start. Books with example can greatly help and of course, his forum!