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.

Bookmark and Share

Story pulse

WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE 1=1 AND post_id = 1082 GROUP BY hit_date' at line 5]
SELECT SUM(hit_count) AS hits, hit_date FROM WHERE 1=1 AND post_id = 1082 GROUP BY hit_date


Leave a comment