HOWTO: replace “st.” with “saint” with PHP
occasionally, you might need to lookup something based on a user-specified piece of info like “city”. Don’t let the lazy ones prevent you from performing at your best.
<?php
$echothis = strtolower(str_ireplace("st.","saint",$_GET['string']));
echo $echothis;
?>
<form action"<?php echo $_SERVER['phpself'];?>" method="get">
<input type="text" name="string">
<input type="submit">
</form>
What this does is replace an abbreviated “st.” with the fully spelled out “saint”. I found it useful, maybe you will too. “strtolower” is added to just normalize the string so that str_ireplace… Oh, that’s funny. I probably don’t need to strtolower the string, because str_ireplace is case “i”nsensitive. str_i(nsensitive)replace. Oh well, live and learn.
Leave a comment