/[dtapublic]/to_be_filed/webprojs/php_libraries/php_library/pamc_gen_a/string/strfunc_htmlformat.inc
ViewVC logotype

Contents of /to_be_filed/webprojs/php_libraries/php_library/pamc_gen_a/string/strfunc_htmlformat.inc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 35 - (show annotations) (download)
Sat Oct 8 23:35:33 2016 UTC (8 years, 1 month ago) by dashley
File size: 4978 byte(s)
Initial commit.
1 <?php
2 //$Header: /hl/cvsroots/gpl01/gpl01/webprojs/pamc/gen_a/sw/phplib/string/strfunc_htmlformat.inc,v 1.1 2007/06/21 23:34:03 dashley Exp $
3 //--------------------------------------------------------------------------------
4 //strfunc_htmlformat.inc -- PAMC string functions related to HTML formatting.
5 //Copyright (C) 2007 David T. Ashley
6 //--------------------------------------------------------------------------------
7 //This program is free software; you can redistribute it and/or
8 //modify it under the terms of the GNU General Public License
9 //as published by the Free Software Foundation; either version 2
10 //of the License, or (at your option) any later version.
11 //
12 //This program is distributed in the hope that it will be useful,
13 //but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 //GNU General Public License for more details.
16 //
17 //You should have received a copy of the GNU General Public License
18 //along with this program; if not, write to the Free Software
19 //Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 //--------------------------------------------------------------------------------
21 //Author contact information:
22 // David T. Ashley
23 // P.O. Box 918
24 // Marshall, Michigan, 49068
25 // dta@e3ft.com
26 //--------------------------------------------------------------------------------
27 //For the passed string, will return a string of "&nbsp;"'s that approximately
28 //equals the length when displayed in a table.
29 //
30 function STRFUNC_nbsp_padding($arg)
31 {
32 $n = (int)(1.95 * strlen($arg));
33
34 $rv = "";
35
36 for ($i = 0; $i < $n; $i++)
37 {
38 $rv .= "&nbsp;";
39 }
40
41 return($rv);
42 }
43 //
44 //--------------------------------------------------------------------------------
45 //Escapes a JavaScript internal string that is delimited by single quotes.
46 //This allows the use of contractions and other constructs within the
47 //string.
48 //
49 //The string is not truncated in any way (it should be known in advance
50 //that the string is of a suitable length).
51 //
52 //This function is used to preprocess strings (usually from a database) that
53 //will occur embedded in JavaScript within single quotes.
54 //
55 function STRFUNC_js_escape_sglquote_notrunc($arg)
56 {
57 //Be sure no funky stuff in string.
58 $temp = STRFUNC_force_into_subset
59 (
60 $arg,
61 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ;.,()<>{}:'\"-*+/0123456789"
62 );
63 //
64 //For each single quote in string, replace it with \'. For each double-quote,
65 //since I haven't figured out how to properly escape it, it is turned into an
66 //escaped single quote.
67 $rv = "";
68 $count = strlen($temp);
69 for ($i=0; $i<$count; $i++)
70 {
71 $c = SubStr($temp, $i, 1);
72 if ($c == "'")
73 $rv .= "\\'";
74 else if ($c == "\"")
75 $rv .= "\\'";
76 else
77 $rv .= $c;
78 }
79
80 return($rv);
81 }
82 //
83 //--------------------------------------------------------------------------------
84 //Escapes an HTML "title" string that is delimited by double quotes.
85 //This allows the use of quoted text and other constructs within the
86 //string.
87 //
88 //The string is not truncated in any way (it should be known in advance
89 //that the string is of a suitable length).
90 //
91 function STRFUNC_html_title_escape_dblquote_notrunc($arg)
92 {
93 //Be sure no funky stuff in string.
94 $temp = STRFUNC_force_into_subset
95 (
96 $arg,
97 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ;.,()<>{}:'\"-*+/0123456789"
98 );
99 //
100 //For each double quote in string, replace it with \".
101 $rv = "";
102 $count = strlen($temp);
103 for ($i=0; $i<$count; $i++)
104 {
105 $c = SubStr($temp, $i, 1);
106 if ($c == "\"")
107 $rv .= "&quot;";
108 else
109 $rv .= $c;
110 }
111
112 return($rv);
113 }
114 //
115 //--------------------------------------------------------------------------------
116 //Creates a GET string (including the ?) that should be appended to a URL to
117 //pass the date and time.
118 //
119 function STRFUNC_datetime_get_url_trailer($sddt, $sdtim)
120 {
121 if (($sddt === FALSE) && ($sdtim === FALSE))
122 {
123 //Nothing to append.
124 return("");
125 }
126 else if (($sddt === FALSE) && ($sdtim !== FALSE))
127 {
128 //Time only.
129 return("?sdtim=" . $sdtim);
130 }
131 else if (($sddt !== FALSE) && ($sdtim === FALSE))
132 {
133 //Date only.
134 return("?sddt=" . $sddt);
135 }
136 else
137 {
138 //Both date and time.
139 return("?sddt=" . $sddt . "&sdtim=" . $sdtim);
140 }
141 }
142 //
143 //--------------------------------------------------------------------------------
144 //End of $RCSfile: strfunc_htmlformat.inc,v $.
145 //--------------------------------------------------------------------------------
146 ?>

dashley@gmail.com
ViewVC Help
Powered by ViewVC 1.1.25