php-general Digest 11 Apr 2009 09:28:59 -0000 Issue 6061
Topics (messages 291347 through 291360):
Re: Caching
291347 by: ×× ××× ×× ××
Re: unknown number of inputs
291348 by: Al
291352 by: Michael A. Peters
291353 by: Phpster
291356 by: PJ
ServInt feedback
291349 by: larry.garfieldtech.com
Re: How about a saveXHTML for the DOM?
291350 by: Raymond Irving
291355 by: Michael A. Peters
291357 by: Michael A. Peters
291358 by: Raymond Irving
291359 by: Michael A. Peters
Re: A Tool For Building PHP Web Apps
291351 by: Raymond Irving
Re: Escape Data In/Out of db [solved]
291354 by: tedd
Re: concat and join stuff
291360 by: Martijn Korse
Administrivia:
To subscribe to the digest, e-mail:
[email protected]
To unsubscribe from the digest, e-mail:
[email protected]
To post to the list, e-mail:
[email protected]
----------------------------------------------------------------------
--- Begin Message ---
Hey! About " Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT" "
The problem is the files might change, lets say - every week. How can I use
" Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"" to something like
Header set Expires "today plus week"
(or X seconds / y minutes / etc...)
On Fri, Apr 10, 2009 at 12:15 PM, Richard Heyes <[email protected]> wrote:
> Hi,
>
> > I started caching some of the static files on my application,
> > I was wondering - Lets say I have an article on my website and I *want*
> to
> > cache it. How will I cache it AND will be able to make my visitors
> > "re-cache" it if it has been changed?
>
> Work from the last modified date/time on the file. When you update the
> file it will change. Though if your files really are static, then
> there's little point - the OS will do a far better job of caching them
> than you will.
>
> Also, you may also want to have a goosey at the Cache-Control: HTTP
> header over Expires:. It can give you more control.
>
> > How do I use *Header set Expires* (on htaccess) and specifying "in a
> week"?
>
> A quick Google found this:
>
> Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
>
> --
> Richard Heyes
>
> HTML5 Canvas graphing for Firefox, Chrome, Opera and Safari:
> http://www.rgraph.net (Updated March 28th)
>
--- End Message ---
--- Begin Message ---
Phpster wrote:
On Apr 10, 2009, at 12:44, Al <[email protected]> wrote:
PJ wrote:
I have a script with $_POST and <form> to load data with text input.
Situation: enter name of author(s) for book. I have the script set up to
enter first_name, last_name for Author1 and the same for Author 2.
Check if entry 1 exists then proceed accordingly
Check if entry 2 exists then proceed accordingly.
Now, If I have three or more authors to enter, is there a way to add a
radio button to add more rows for input or to skip further inputs, if I
have to enter the inputs for each additional author?
I'm looking for a simple way to do this. Could or should Ajax be
involved in this somehow?
Here's the way I do it, especially if typically the number of entries
are small. e.g., 4 or so.
Show the 4 and let the user Submit them.
Then, if they used all 4, return the page with an additional 4. Show
all 8.
Then, if they've used all 8, repeat until they leave at least one
unused. Process the page.
Make the batch size a constant that you can easily change. And
consider making the first rendering say 6 and subsequent additions 3,
or whatever.
If you want to get a little fancy. Make a simple log file for the
total number of entries. After the application has been used for a
while, you can check the log and adjust your batch size constant(s)
accordingly.
Al....
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Why, why make trips to the server when you don't need to? I have an
ongoing arguement with the vp from my company ( I'm the director of dev)
where he's done the same thing. It is a more complex app and he does it
in blocks of ten. But when the clients try to add 100 items, all the
processing he does makes that entire process take almost an hour when
all is said and done. I keep telling him it should be js only to add new
rows, with no trips to the server. But then he's as smart as the guy who
wrote the jpeg image compression ;-P
I digress but never make a trip back when you don't need to.
Bastien
Everything is a compromise. I avoid scripts on the client
side; just another thing to be concerned about for
compatibility.
Todays speeds for servers, browsers and the net are so fast
one can hardly get their finger off the mouse button before
pages are replaced.
For 100 rows, sounds to me like you need a complete
application on the client side that does all or most of the
processing. Must take an hour for your users to simple enter
data into 100 rows.
--- End Message ---
--- Begin Message ---
Phpster wrote:
On Apr 10, 2009, at 12:44, Al <[email protected]> wrote:
PJ wrote:
I have a script with $_POST and <form> to load data with text input.
Situation: enter name of author(s) for book. I have the script set up to
enter first_name, last_name for Author1 and the same for Author 2.
Check if entry 1 exists then proceed accordingly
Check if entry 2 exists then proceed accordingly.
Now, If I have three or more authors to enter, is there a way to add a
radio button to add more rows for input or to skip further inputs, if I
have to enter the inputs for each additional author?
I'm looking for a simple way to do this. Could or should Ajax be
involved in this somehow?
Here's the way I do it, especially if typically the number of entries
are small. e.g., 4 or so.
Show the 4 and let the user Submit them.
Then, if they used all 4, return the page with an additional 4. Show
all 8.
Then, if they've used all 8, repeat until they leave at least one
unused. Process the page.
Make the batch size a constant that you can easily change. And
consider making the first rendering say 6 and subsequent additions 3,
or whatever.
If you want to get a little fancy. Make a simple log file for the
total number of entries. After the application has been used for a
while, you can check the log and adjust your batch size constant(s)
accordingly.
Al....
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Why, why make trips to the server when you don't need to?
I agree.
Write a simple javascript that creates an input and adds it as a child
to the node that contains your inputs.extension) and replace it with a
virgin input.
var someInput = document.createElement("input");
someInput.setAttribute("type","file");
someInput.setAttribute("name","voucher[]");
someInput.setAttribute("style","width: 42em;");
myDiv.appendChild(myImage);
Put something like that in a function where myDiv is the parent div of
your inputs.
Then you can add as many extra inputs as you want client side by calling
the function and there is no need to mess with ajax or any other server
side tech.
--- End Message ---
--- Begin Message ---
On Apr 10, 2009, at 15:21, Al <[email protected]> wrote:
Phpster wrote:
On Apr 10, 2009, at 12:44, Al <[email protected]> wrote:
PJ wrote:
I have a script with $_POST and <form> to load data with text
input.
Situation: enter name of author(s) for book. I have the script
set up to
enter first_name, last_name for Author1 and the same for Author 2.
Check if entry 1 exists then proceed accordingly
Check if entry 2 exists then proceed accordingly.
Now, If I have three or more authors to enter, is there a way to
add a
radio button to add more rows for input or to skip further
inputs, if I
have to enter the inputs for each additional author?
I'm looking for a simple way to do this. Could or should Ajax be
involved in this somehow?
Here's the way I do it, especially if typically the number of
entries are small. e.g., 4 or so.
Show the 4 and let the user Submit them.
Then, if they used all 4, return the page with an additional 4.
Show all 8.
Then, if they've used all 8, repeat until they leave at least one
unused. Process the page.
Make the batch size a constant that you can easily change. And
consider making the first rendering say 6 and subsequent additions
3, or whatever.
If you want to get a little fancy. Make a simple log file for the
total number of entries. After the application has been used for a
while, you can check the log and adjust your batch size
constant(s) accordingly.
Al....
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Why, why make trips to the server when you don't need to? I have an
ongoing arguement with the vp from my company ( I'm the director of
dev) where he's done the same thing. It is a more complex app and
he does it in blocks of ten. But when the clients try to add 100
items, all the processing he does makes that entire process take
almost an hour when all is said and done. I keep telling him it
should be js only to add new rows, with no trips to the server. But
then he's as smart as the guy who wrote the jpeg image
compression ;-P
I digress but never make a trip back when you don't need to.
Bastien
Everything is a compromise. I avoid scripts on the client side; just
another thing to be concerned about for compatibility.
Todays speeds for servers, browsers and the net are so fast one can
hardly get their finger off the mouse button before pages are
replaced.
For 100 rows, sounds to me like you need a complete application on
the client side that does all or most of the processing. Must take
an hour for your users to simple enter data into 100 rows.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
The web app works well if slowly, but if I could rework the pages in
question, though a move to an Adobe AIR project is what I would do.
As for speed, since our app is sold as a hosted or an inhouse version,
there is often other factors involved in the overall network speed and
server ability. And since it's purchased app, we can dictate
requirements like js being available.
--- End Message ---
--- Begin Message ---
Michael A. Peters wrote:
> Phpster wrote:
>>
>>
>> On Apr 10, 2009, at 12:44, Al <[email protected]> wrote:
>>
>>>
>>> PJ wrote:
>>>> I have a script with $_POST and <form> to load data with text input.
>>>> Situation: enter name of author(s) for book. I have the script set
>>>> up to
>>>> enter first_name, last_name for Author1 and the same for Author 2.
>>>> Check if entry 1 exists then proceed accordingly
>>>> Check if entry 2 exists then proceed accordingly.
>>>> Now, If I have three or more authors to enter, is there a way to add a
>>>> radio button to add more rows for input or to skip further inputs,
>>>> if I
>>>> have to enter the inputs for each additional author?
>>>> I'm looking for a simple way to do this. Could or should Ajax be
>>>> involved in this somehow?
>>>
>>> Here's the way I do it, especially if typically the number of
>>> entries are small. e.g., 4 or so.
>>>
>>> Show the 4 and let the user Submit them.
>>>
>>> Then, if they used all 4, return the page with an additional 4. Show
>>> all 8.
>>>
>>> Then, if they've used all 8, repeat until they leave at least one
>>> unused. Process the page.
>>>
>>> Make the batch size a constant that you can easily change. And
>>> consider making the first rendering say 6 and subsequent additions
>>> 3, or whatever.
>>>
>>> If you want to get a little fancy. Make a simple log file for the
>>> total number of entries. After the application has been used for a
>>> while, you can check the log and adjust your batch size constant(s)
>>> accordingly.
>>>
>>> Al....
>>>
>>> --
>>> PHP General Mailing List (http://www.php.net/)
>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>
>>
>> Why, why make trips to the server when you don't need to?
>
> I agree.
> Write a simple javascript that creates an input and adds it as a child
> to the node that contains your inputs.extension) and replace it with a
> virgin input.
>
> var someInput = document.createElement("input");
> someInput.setAttribute("type","file");
> someInput.setAttribute("name","voucher[]");
> someInput.setAttribute("style","width: 42em;");
> myDiv.appendChild(myImage);
>
> Put something like that in a function where myDiv is the parent div of
> your inputs.
>
> Then you can add as many extra inputs as you want client side by
> calling the function and there is no need to mess with ajax or any
> other server side tech.
>
Thanks, guys, got it. JS makes sense for what I was looking for.
As to speed, yes it takes probably more time to enter 100 inputs for my
app, but then it's only for administrators and it's only to add db data;
not for users.
Thanks.
PJ
--
unheralded genius: "A clean desk is the sign of a dull mind. "
-------------------------------------------------------------
Phil Jourdan --- [email protected]
http://www.ptahhotep.com
http://www.chiccantine.com/andypantry.php
--- End Message ---
--- Begin Message ---
Hi folks. A while back I inquired about "managed VPS" hosting services.
I have since gotten a recommendation for ServInt.net, which seems to
offer an actual managed VPS or something very close to it. Does anyone
else have experience with them, good or bad? Are they decently
responsible about maintaining the server image, and responsive about
requests to change things? Decent uptime? All that usual stuff. :-)
Thanks in advance.
--Larry Garfield
--- End Message ---
--- Begin Message ---
--- On Wed, 4/8/09, Michael A. Peters <[email protected]> wrote:
> From: Michael A. Peters <[email protected]>
> Subject: Re: [PHP] How about a saveXHTML for the DOM?
>
> saveXML() already does what is needed to provide valid
> xhtml output.
From my test it sometimes generate this like at the end of the page
elements. It also generate things like <script src="file.js" /> which does not
work in most browsers.
So we have to process the out string to convert things like <script />
<textarea /> to <script></script> and <textrea></textarea>
There are other times when saveXML will remove the \n altogether from the code
which caused tags to be displayed in a single line. In addition saveXML() does
not preserve html entities. So things like © gets converted to ©.
Sometimes working with saveHTML and saveXML is like being caught between a rock
and a hard place.
I'm trying to figure out which would be easier to do:
Going from saveHTML() to XHTML
Going from saveXML() to XHTML
__
Raymond Irving
Create Rich Ajax/PHP Web apps Today!
Raxan PDI - http://raxanpdi.com
--- End Message ---
--- Begin Message ---
Raymond Irving wrote:
--- On Wed, 4/8/09, Michael A. Peters <[email protected]> wrote:
From: Michael A. Peters <[email protected]>
Subject: Re: [PHP] How about a saveXHTML for the DOM?
saveXML() already does what is needed to provide valid
xhtml output.
From my test it sometimes generate this like at the end of the page elements. It also
generate things like <script src="file.js" /> which does not work in most browsers.
<script src="foo.js />
will work on any browser that advertises it accepts the xhtml+xml mime type.
Internet exploder does not and therefore internet exploder should be
sent xhtml document. Send html documents to internet exploder.
<?php
if (! isset($usexml)) {
$usexml=1;
}
if ($usexml == 1) {
if (isset( $_SERVER['HTTP_ACCEPT'] )) {
if(! strpos( $_SERVER['HTTP_ACCEPT'], "application/xhtml+xml" ) ) {
$usexml=0;
}
} else {
$usexml=0;
}
}
?>
That will result in $usexml being set to 1 for browsers (like Firefox
and Opera) that accept xhtml+xml while setting it to 0 for browsers that
do not accept xhtml+xml.
Then when you create your DOM -
<?php
$xhtmldtd="<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"
\"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">";
$htmldtd="<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\"
\"http://www.w3.org/TR/html4/strict.dtd\">";
$myxhtml = new DOMDocument("1.0","UTF-8");
$myxhtml->preserveWhiteSpace = false;
$myxhtml->formatOutput = true;
if ($usexml == 0) {
$xmlstring = $htmldtd . "<html></html>";
} else {
$xmlstring = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" .
$xhtmldtd . "<html></html>";
}
$myxhtml->loadXML($xmlstring);
$elements = $myxhtml->getElementsByTagName("html");
$xmlHtml = $elements->item(0);
?>
You then add your children (IE head and body) to $xmlHtml.
When it comes time to serve the page -
<?php
function sendxhtmlheader($usexml) {
if ($usexml == 1) {
header("Content-Type: application/xhtml+xml; charset=utf-8");
} else {
header("Content-type: text/html; charset=utf-8");
}
}
?>
makes sure the right header describing the content is set.
Send the page like this:
<?php
if ($usexml == 0) {
print $myxhtml->saveHTML();
} else {
print $myxhtml->saveXML();
}
?>
That way you only send xhtml to browsers that advertised to your server
that they know what to do with the application/xhtml+xml mime type,
those that did not advertise they know what to do get the text/html mime
type and an html page.
It works extremely well in my test environment (my web app is not live
yet) for sending valid xhtml 1.1 to browsers that properly handle xhtml
and sending html 4.1 strict to browsers that do not properly handle
xhtml+xml (IE internet exploder).
As far as I can tell - as long as you aren't using an extension to xhtml
(like MathML) - the only problem where you can't produce both valid
xhtml 1.1 and html 4.01 strict from the same php code would be if you
were using the ruby (not programming language, the tags) elements that
are allowed in xhtml 1.1 but not defined in HTML 4.01
No browser I have tested with that broadcasts it accepts xhtml+xml has
ever had a problem with self closing script (or input or meta or ...) tags.
If you send xhtml with the text/plain mime type then the failure is on
your end for violating the specification and self closing script tags
are not legal.
--- End Message ---
--- Begin Message ---
Michael A. Peters wrote:
$myxhtml->loadXML($xmlstring);
$elements = $myxhtml->getElementsByTagName("html");
$xmlHtml = $elements->item(0);
?>
forgot this tidbit -
<?pjp
if ($usexml == 1) {
$xmlHtml->setAttribute("xmlns","http://www.w3.org/1999/xhtml");
$xmlHtml->setAttributeNS('http://www.w3.org/XML/1998/namespace','xml:lang','en');
}
*now* you can have your php code populate the dom by appending children
to $xmlHtml neutral to whether or not it eventually is going to be sent
as xml or html.
--- End Message ---
--- Begin Message ---
Thanks for the feedback Michael. I will look into your suggesstions.
Is there an option on the DOMDocument that we can set to not have saveXML()
append to the end of the tags?
This is normally the case if the html content was loaded using loadHTMLFile()
__
Raymond Irving
--- On Fri, 4/10/09, Michael A. Peters <[email protected]> wrote:
From: Michael A. Peters <[email protected]>
Subject: Re: [PHP] How about a saveXHTML for the DOM?
To: "Raymond Irving" <[email protected]>
Cc: "[email protected]" <[email protected]>
Date: Friday, April 10, 2009, 3:57 PM
Raymond Irving wrote:
>
>
>
> --- On Wed, 4/8/09, Michael A. Peters <[email protected]> wrote:
>
>> From: Michael A. Peters <[email protected]>
>> Subject: Re: [PHP] How about a saveXHTML for the DOM?
>>
>> saveXML() already does what is needed to provide valid
>> xhtml output.
>
> From my test it sometimes generate this like
at the end of the page elements. It also generate things like <script
src="file.js" /> which does not work in most browsers.
>
<script src="foo.js />
will work on any browser that advertises it accepts the xhtml+xml mime type.
Internet exploder does not and therefore internet exploder should be sent xhtml
document. Send html documents to internet exploder.
<?php
if (! isset($usexml)) {
$usexml=1;
}
if ($usexml == 1) {
if (isset( $_SERVER['HTTP_ACCEPT'] )) {
if(! strpos( $_SERVER['HTTP_ACCEPT'], "application/xhtml+xml" ) ) {
$usexml=0;
}
} else {
$usexml=0;
}
}
?>
That will result in $usexml being set to 1 for browsers (like Firefox and
Opera) that accept xhtml+xml while setting it to 0 for browsers that do not
accept xhtml+xml.
Then when you create your DOM -
<?php
$xhtmldtd="<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"
\"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">";
$htmldtd="<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\"
\"http://www.w3.org/TR/html4/strict.dtd\">";
$myxhtml = new DOMDocument("1.0","UTF-8");
$myxhtml->preserveWhiteSpace = false;
$myxhtml->formatOutput = true;
if ($usexml == 0) {
$xmlstring = $htmldtd . "<html></html>";
} else {
$xmlstring = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" . $xhtmldtd .
"<html></html>";
}
$myxhtml->loadXML($xmlstring);
$elements = $myxhtml->getElementsByTagName("html");
$xmlHtml = $elements->item(0);
?>
You then add your children (IE head and body) to $xmlHtml.
When it comes time to serve the page -
<?php
function sendxhtmlheader($usexml) {
if ($usexml == 1) {
header("Content-Type: application/xhtml+xml; charset=utf-8");
} else {
header("Content-type: text/html; charset=utf-8");
}
}
?>
makes sure the right header describing the content is set.
Send the page like this:
<?php
if ($usexml == 0) {
print $myxhtml->saveHTML();
} else {
print $myxhtml->saveXML();
}
?>
That way you only send xhtml to browsers that advertised to your server that
they know what to do with the application/xhtml+xml mime type, those that did
not advertise they know what to do get the text/html mime type and an html page.
It works extremely well in my test environment (my web app is not live yet) for
sending valid xhtml 1.1 to browsers that properly handle xhtml and sending html
4.1 strict to browsers that do not properly handle xhtml+xml (IE internet
exploder).
As far as I can tell - as long as you aren't using an extension to xhtml (like
MathML) - the only problem where you can't produce both valid xhtml 1.1 and
html 4.01 strict from the same php code would be if you were using the ruby
(not programming language, the tags) elements that are allowed in xhtml 1.1 but
not defined in HTML 4.01
No browser I have tested with that broadcasts it accepts xhtml+xml has ever had
a problem with self closing script (or input or meta or ...) tags.
If you send xhtml with the text/plain mime type then the failure is on your end
for violating the specification and self closing script tags are not legal.
--- End Message ---
--- Begin Message ---
Raymond Irving wrote:
Thanks for the feedback Michael. I will look into your suggesstions.
Is there an option on the DOMDocument that we can set to not have saveXML() append
to the end of the tags?
This is normally the case if the html content was loaded using loadHTMLFile()
I think I've seen that appear in textarea as well - I believe it has to
do with the libebreaks of the application that created the file (or in
case of textarea from a form, the line break convention of the browser).
Does it happen when you run
sed -i 's/\r//g' file.html
to remove the DOS carriage return from the line breaks?
That would be my guess.
--- End Message ---
--- Begin Message ---
Maybe this can help:
http://www.intorel.com/index.php?page=ActiveSiteCompiler-default_asp
--- On Fri, 4/10/09, Paul M Foster <[email protected]> wrote:
> From: Paul M Foster <[email protected]>
> Subject: [PHP] A Tool For Building PHP Web Apps
> To: [email protected]
> Date: Friday, April 10, 2009, 1:28 AM
> Here's a hairbrained idea I was
> kicking around. I object to the idea of
> including 15 or 30 files in a PHP application just to
> display one page
> on the internet. It makes the coding faster, but it makes
> the display
> slower and seems silly to me.
>
> So what if you had a tool or a set of tools where you could
> write code
> snippets and such, and then hit a button or issue a
> command, and
> everything you specified got written into a single file?
> You'd specify
> that this page needs to read the config, set up a database
> connection,
> validate these fields, etc. When you were done, it would
> write all this
> code to a *single* file, which the user would invoke by
> surfing to that
> page. The resulting code would be *static*, not like what
> results from
> most templating systems. So rather than specify a specific
> variable
> value in the resulting file, it would embed the PHP code to
> display the
> variable, etc.
>
> What might be the liabilities of something like that? Would
> there be
> security issues? Would there be increased difficulty in
> debugging? What
> can you think of?
>
> Paul
>
> --
> Paul M. Foster
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
At 9:12 PM -0700 4/9/09, Jim Lucas wrote:
tedd wrote:
At 5:03 PM +0200 4/9/09, Jan G.B. wrote:
You might want to use htmlspecialchars($str, ENT_QUOTES)
OUT from db to html
and
mysql_real_escape_string(stripslashes($_POST['yourself']));
The above tells me that you probably need to look at your magic
quotes setting.
The php info says:
magic_quotes_runtime Off Off
magic_quotes_sybase Off Off
I'm assuming that means OFF, right?
Cheers,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
--- End Message ---
--- Begin Message ---
This is not really a PHP question, but a mysql question.
Anyways, your query should work, as far as i can see.
If you give the structure dumps and some relevant data dumps i don't mind to
give it a try here.
-----
http://devshed.excudo.net http://devshed.excudo.net
--
View this message in context:
http://www.nabble.com/concat-and-join-stuff-tp22874340p22999438.html
Sent from the PHP - General mailing list archive at Nabble.com.
--- End Message ---