X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=format.php;h=055e66d6eaa6234f83803d194799188fb1d17865;hb=4f94560f060a7305ea791def3950adb1bda092ec;hp=b9270bd3b17001a1333e79b573eed60bc32a90a4;hpb=3698f739c8155069451c61085ab925250c592e42;p=wfpl.git diff --git a/format.php b/format.php index b9270bd..055e66d 100644 --- a/format.php +++ b/format.php @@ -4,24 +4,44 @@ # # This file is part of wfpl. # -# wfpl is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2, or (at your option) +# wfpl is free software; you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation; either version 2.1 of the License, or (at your option) # any later version. # -# wfpl is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. +# wfpl is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for +# more details. # -# You should have received a copy of the GNU General Public License -# along with wfpl; see the file COPYING. If not, write to the -# Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -# MA 02111-1307, USA. +# You should have received a copy of the GNU Lesser General Public License +# along with wfpl; if not, write to the Free Software Foundation, Inc., 51 +# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # This file contains basic encodings +function format_int($str) { + $str = ereg_replace('[^0-9]', '', $str); + return ereg_replace('^0*([1-9])', '\1', $str); +} + +function format_zip($str) { + return ereg_replace('[^0-9]', '', $str); +} + +function format_filename($str) { + $str = strtolower($str); + $str = ereg_replace('[^a-z0-9_.-]', '_', $str); + return ereg_replace('^[.-]', '_', $str); +} + +function format_varname($str) { + $str = strtolower($str); + $str = ereg_replace('[^a-z0-9_]', '_', $str); + return ereg_replace('^[0-9]*', '', $str); +} + function format_oneline($str) { $str = str_replace("\r", '', $str); return str_replace("\n", '', $str); @@ -32,10 +52,10 @@ function format_unix($str) { } function format_yesno($str) { - if($str) { - return "Yes"; + if($str && $str != 'No') { + return 'Yes'; } else { - return "No"; + return 'No'; } } @@ -44,6 +64,11 @@ function format_email($str) { return format_oneline($str); } +function format_url($str) { + # FIXME + return format_oneline($str); +} + function format_money($str, $display_cents = true) { $str = ereg_replace('[^0-9.]', '', $str); if($display_cents) { @@ -108,24 +133,4 @@ function format_phone($str) { return $output; } - -#function ftest($val) { -# printf("$val: '%s'
\n", format_phone($val, true)); -#} -# -#echo "FORMAT TESTS

"; -#ftest("$3"); -#ftest("3.99"); -#ftest("3.5"); -#ftest("891234"); -#ftest("8221234"); -#ftest("82212334"); -#ftest("122313234"); -#ftest("1158221234"); -#ftest("1558221234"); -#ftest("12235513234"); -#ftest("122355123334"); -#ftest("1585552212334"); -#ftest("15855522123334"); - ?>