php-general Digest 8 Oct 2006 11:51:50 -0000 Issue 4389

Topics (messages 242805 through 242817):

Re: Separate PHP Code From HTML || Pros & Cons
        242805 by: Thiago Silva
        242807 by: Tony Di Croce

Re: FTP
        242806 by: Brad Chow
        242814 by: Yannick Warnier
        242816 by: Raphael Martins
        242817 by: Yannick Warnier

Re: set cookie with non-english
        242808 by: Nisse Engström

ECHO $variable
        242809 by: Ron Piggott (PHP)
        242810 by: benifactor
        242812 by: Penthexquadium

Re: Unicode Problem
        242811 by: Nisse Engström

looking for a php newsletter application ready to use
        242813 by: hicham

Re: Separate PHP Code From HTML || Pros & Cons?
        242815 by: Yannick Warnier

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 ---
On 10/7/06, sit1way <[EMAIL PROTECTED]> wrote:

Hey all.

This presents problems in that any updates I make to the CMS only affect
the
site I'm working on.  So, while working on one site I may make changes to
the CMS, changes that improve the app., but other older sites do not get
updated -- it's OK now, but things are getting sloppy ;--)

I would dearly love to have a base CMS repository that all sites would
draw
on, extending the base CMS in the event that a particular client has need
of
customization.  Some combo of Linux and Apache would do the trick; e.g.
PHP
requests for any of my sites would point to say, "/home/cms/includes/"


Are you using a version control system? Using one and, maybe, reviewing your
architeture for code re-use might help in this matter, I think....

Now, the other issue I'd like to address is separating PHP code logic from
site HTML.

(...)

I've often heard the mantra, "separate code from HTML", but it seems
ridiculous at times to include tiny HTML snippets that can easily be
echoed
out, or stored in a variable.  Smarty goes to the extreme in separating
code
from HTML, but looking at their templating system, I wonder what's the
point?  Is it the end of the world if you've got a few choice if, then,
else
statements in your HTML templates?



Is of my understading that this mantra is about intention in the code.
We have a framework written in PHP that also uses PHP as template language.

I mean, we have source files that define components, where we use PHP to
process the data normally (declaring classes, using DB, etc), but there are
also "snippet" files were we have HTML + PHP.

The special case here is that the snippet files have a couple of arrays with
data (created and offered by the components) available and their only
occupation is to process output: no DB access, no class declaration, no file
inclusion, no socket connection....all they have to do is render HTML (or
whatever) with the data they received. The most complex things we have in
snippet files are small functions where recursions help displaying  some
widgets. Everything else are loops, decision strucutres and lots of
print/echo. Simple source files, in the end.


Thiago Silva

--- End Message ---
--- Begin Message ---
I  dont think its so bad.

What I do is keep the PHP and HTML seperate, but in the same file: php on
top, html in a here document at the bottom. I COULD go one step farther and
have the HTML in a seperate file, but I just dont see the point.

  td

On 10/7/06, Thiago Silva <[EMAIL PROTECTED]> wrote:

On 10/7/06, sit1way <[EMAIL PROTECTED]> wrote:
>
> Hey all.
>
> This presents problems in that any updates I make to the CMS only affect
> the
> site I'm working on.  So, while working on one site I may make changes
to
> the CMS, changes that improve the app., but other older sites do not get
> updated -- it's OK now, but things are getting sloppy ;--)
>
> I would dearly love to have a base CMS repository that all sites would
> draw
> on, extending the base CMS in the event that a particular client has
need
> of
> customization.  Some combo of Linux and Apache would do the trick; e.g.
> PHP
> requests for any of my sites would point to say, "/home/cms/includes/"


Are you using a version control system? Using one and, maybe, reviewing
your
architeture for code re-use might help in this matter, I think....

Now, the other issue I'd like to address is separating PHP code logic from
> site HTML.
>
> (...)
>
I've often heard the mantra, "separate code from HTML", but it seems
> ridiculous at times to include tiny HTML snippets that can easily be
> echoed
> out, or stored in a variable.  Smarty goes to the extreme in separating
> code
> from HTML, but looking at their templating system, I wonder what's the
> point?  Is it the end of the world if you've got a few choice if, then,
> else
> statements in your HTML templates?



Is of my understading that this mantra is about intention in the code.
We have a framework written in PHP that also uses PHP as template
language.

I mean, we have source files that define components, where we use PHP to
process the data normally (declaring classes, using DB, etc), but there
are
also "snippet" files were we have HTML + PHP.

The special case here is that the snippet files have a couple of arrays
with
data (created and offered by the components) available and their only
occupation is to process output: no DB access, no class declaration, no
file
inclusion, no socket connection....all they have to do is render HTML (or
whatever) with the data they received. The most complex things we have in
snippet files are small functions where recursions help displaying  some
widgets. Everything else are loops, decision strucutres and lots of
print/echo. Simple source files, in the end.


Thiago Silva




--
Publish technical articles @ skilledwords.com and get 100% of the
ad-revenue!
http://www.skilledwords.com

--- End Message ---
--- Begin Message ---
Hi Martins,

Of course. You can alter it you want.

I remember that file size limit devided into two type:
1) local access
2) remote access

file size limit only limit remote access because I can upload file from
local more than limit.

Good luck!!

Brad

On 10/8/06, Raphael Martins <[EMAIL PROTECTED]> wrote:

Hi,

When I send files via FTP, the file size is limited to the php.ini max
upload value?
Thank you!



--- End Message ---
--- Begin Message ---
Le samedi 07 octobre 2006 à 20:50 -0300, Raphael Martins a écrit :
> Hi,
> 
> When I send files via FTP, the file size is limited to the php.ini max
> upload value?
> Thank you!

No, unless you handle the FTP server with a PHP script. php.ini only
limits the size of files handled by PHP (generally via HTTP), so it
should not affect FTP (unless your FTP server is in PHP).

Yannick

--- End Message ---
--- Begin Message ---
I will be sending files over my php script... One client asked me for a
project where he allow clients to send some large files (like 50mb)...I
thought that FTP (via PHP)  will allow that.

Today he just give the FTP server user and password to his clients, but he
is worried about the security (of course!). Is there a better way? I was
thinking in split the files in several .RAR volumes... (actually, the client
will send his .RAR files instead of a 50mb file), and use remote scripting
to upload each file separatly.

Any Ideas?

Thank you!

2006/10/8, Yannick Warnier <[EMAIL PROTECTED]>:

Le samedi 07 octobre 2006 à 20:50 -0300, Raphael Martins a écrit :
> Hi,
>
> When I send files via FTP, the file size is limited to the php.ini max
> upload value?
> Thank you!

No, unless you handle the FTP server with a PHP script. php.ini only
limits the size of files handled by PHP (generally via HTTP), so it
should not affect FTP (unless your FTP server is in PHP).

Yannick

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--- End Message ---
--- Begin Message ---
Le dimanche 08 octobre 2006 à 08:05 -0300, Raphael Martins a écrit :
> I will be sending files over my php script... One client asked me for a
> project where he allow clients to send some large files (like 50mb)...I
> thought that FTP (via PHP)  will allow that.
> 
> Today he just give the FTP server user and password to his clients, but he
> is worried about the security (of course!). Is there a better way? I was
> thinking in split the files in several .RAR volumes... (actually, the client
> will send his .RAR files instead of a 50mb file), and use remote scripting
> to upload each file separatly.
> 
> Any Ideas?

There is a PECL SSH library which allows file transfers over SSH (using
PHP). I have received some reports that it's not completely stable
though, but I don't know more about it. You might want to contact Sara
Golemon (the packager) on the PECL-dev mailing list if you manage to get
into stability problems...
See http://pecl.php.net/package/ssh2 for more details.

Yannick

--- End Message ---
--- Begin Message ---
On Tue, 3 Oct 2006 01:15:59 +0300, "Ahmad Al-Twaijiry" wrote:

> Hi everyone
> 
> in my PHP code I use the following command to set a cookie with
> non-english word (UTF-8) :
> 
> @setcookie ("UserName",$Check[1]);
> 
> and in my html page I get this cookie using javascript :

[Snipped]

> but the result from writing the cookie using javascript is garbage, I
> don't get the right word !!

   The problem is that JavaScript uses UTF-16, so you
either have to store the cookie as UTF-16 or do your
own UTF-8 decoding in JavaScript.

   For example, consider the string "åäö", containing
the three funny characters in the Swedish language
(&aring;&auml;&ouml;). These characters are encoded
as <c3 a5 c3 a4 c3 b6> in UTF-8, and PHP stores these
in the cookie as:

  %C3%A5%C3%A4%C3%B6

Example:

------------------------------------------------------
<?php

  setcookie ('UserName', "\xc3\xa5\xc3\xa4\xc3\xb6");
//  setcookie ('UserName', "åäö");
  header ('Content-Type: text/html; charset=utf-8');

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  "http://www.w3.org/TR/html4/strict.dtd";>

<title>UTF-8 flavoured cookies</title>
<p>

<script type="text/javascript">

  document.write(document.cookie);

</script>
------------------------------------------------------

   The unescape() function in JavaScript converts
these characters to the Unicode code points
<00c3 00a5 00c3 00a4 00c3 00b6> which, of course,
is not what you want.

Example:

------------------------------------------------------
<?php

  setcookie ('UserName', "\xc3\xa5\xc3\xa4\xc3\xb6");
//  setcookie ('UserName', "åäö");
  header ('Content-Type: text/html; charset=utf-8');

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  "http://www.w3.org/TR/html4/strict.dtd";>

<title>UTF-8 flavoured cookies</title>
<p>

<script type="text/javascript">

  var s = unescape(document.cookie);
  var t = "";
  for (var i = 0; i < s.length; i++) {
    var c = s.charCodeAt(i);
    t += c < 128 ? String.fromCharCode(c) : c.toString(16) + " ";
  }
  document.write(t);

</script>
------------------------------------------------------

   While there are no doubt better ways to solve this,
you /could/ use the unescape() function to convert the
percent-encoded characters to unicode code point, and
then write your own UTF-8 decoder to do the rest.

Example:

(This is an old C function hammered into JavaScript
 shape. It is likely to be a horrible implementation
 in JavaScript. The error checking adds a bit of bloat.
 Note that the utf_8_decode function supports the full
 Unicode range, while JavaScript doesn't. )
------------------------------------------------------
<?php

  setcookie ('UserName', "\xc3\xa5\xc3\xa4\xc3\xb6");
  header ('Content-Type: text/html; charset=utf-8');

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  "http://www.w3.org/TR/html4/strict.dtd";>

<title>UTF-8 flavoured cookies</title>
<p>

<script type="text/javascript">

function utf_8_decode (sin)
{
  function octet_count (c)
  {
    var octet_counts = [
    /* c0 */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
    /* d0 */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
    /* e0 */ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
    /* f0 */ 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 0, 0
    ];

    return c < 128 ? 1 :
           c < 192 ? 0 : octet_counts [(c&255)-192];
  }

  var octet0_masks = [ 0x00,0x7f,0x1f,0x0f,0x07,0x03,0x01 ];
  var sout = "";
  var add;
  for (var si = 0; si < sin.length; si += add) {
    var c = sin.charCodeAt(si);
    add = octet_count(c);
    if (si+add <= sin.length) {
      var u = c & octet0_masks[add];
      var ci;
      for (ci = 1; (ci < add) && ((sin.charCodeAt(si+ci)&0xc0) == 0x80);
ci++)
        u = (u<<6) | (sin.charCodeAt(si+ci) & 0x3f);
      if (ci == add) {
        sout += String.fromCharCode (u);
      } else {
        // Invalid UTF-8 sequence. Should probably throw() instead.
        sout += "\ufffd"; // Replacement character.
        add = 1;
      }
    } else {
      // Invalid UTF-8 sequence. Should probably throw() instead.
      sout += "\ufffd"; // Replacement character.
      add = 1;
    }
  }

  return sout;
}

document.write (utf_8_decode(unescape(document.cookie)));

</script>
------------------------------------------------------

> BTW:
> * I also tried the php function setrawcookie and I get the same problem
> * I use <META http-equiv=Content-Type  content="text/html;
> charset=utf-8"> in my page

   The <META> thing might be good for storing pages
on disk, but on the web you should use real HTTP
headers.


  --nfe

--- End Message ---
--- Begin Message ---
In one of my scripts I have

<input type=text name="message_title" size=40 maxlength=80 value="<?echo
$saved_message_title;?>">

where

$saved_message_title is 1 Peter 5:7 "Cast all your cares on Him for He
cares about you"
--- note the " 

When this is displayed on the screen $saved_message_title reads

1 Peter 5:7 

I am assuming the " closes the value=

How may I echo this to the screen and have the full text be displayed,
not just 1 Peter 5:7 ?

Ron

--- End Message ---
--- Begin Message ---
you should try this...

$saved_message_title = '1 Peter 5:7 "Cast all your cares on Him for He
cares about you"';
----- Original Message ----- 
From: "Ron Piggott (PHP)" <[EMAIL PROTECTED]>
To: "PHP General" <[email protected]>
Sent: Saturday, October 07, 2006 11:39 PM
Subject: [PHP] ECHO $variable


> In one of my scripts I have
> 
> <input type=text name="message_title" size=40 maxlength=80 value="<?echo
> $saved_message_title;?>">
> 
> where
> 
> $saved_message_title is 1 Peter 5:7 "Cast all your cares on Him for He
> cares about you"
> --- note the " 
> 
> When this is displayed on the screen $saved_message_title reads
> 
> 1 Peter 5:7 
> 
> I am assuming the " closes the value=
> 
> How may I echo this to the screen and have the full text be displayed,
> not just 1 Peter 5:7 ?
> 
> Ron
> 

--- End Message ---
--- Begin Message ---
On Mon, 9 Oct 2006 00:23:00 -0700, "benifactor" <[EMAIL PROTECTED]> wrote:
> you should try this...
> 
> $saved_message_title = '1 Peter 5:7 "Cast all your cares on Him for He
> cares about you"';
> ----- Original Message ----- 
> From: "Ron Piggott (PHP)" <[EMAIL PROTECTED]>
> To: "PHP General" <[email protected]>
> Sent: Saturday, October 07, 2006 11:39 PM
> Subject: [PHP] ECHO $variable
> 
> 
> > In one of my scripts I have
> > 
> > <input type=text name="message_title" size=40 maxlength=80 value="<?echo
> > $saved_message_title;?>">
> > 
> > where
> > 
> > $saved_message_title is 1 Peter 5:7 "Cast all your cares on Him for He
> > cares about you"
> > --- note the " 
> > 
> > When this is displayed on the screen $saved_message_title reads
> > 
> > 1 Peter 5:7 
> > 
> > I am assuming the " closes the value=
> > 
> > How may I echo this to the screen and have the full text be displayed,
> > not just 1 Peter 5:7 ?
> > 
> > Ron
> > 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

His problem is in HTML, not PHP.

Uses htmlspecialchars() or htmlentities() to convert special characters
to HTML entities. The double quote will becomes "&quot;" so that it can
be display correctly.

--
Sorry for my poor English.

--- End Message ---
--- Begin Message ---
On Fri, 6 Oct 2006 10:44:55 -0500 (CDT), "Richard Lynch" wrote:

> I don't think MS Word quotes are Unicode, really...
> 
> I think they're just made-up character sets that Microsoft felt like
> using to be incompatible with everybody else...
> 
> Though the %u#### is almost-for-sure and ATTEMPT to apply Unicode
> conversion, that doesn't mean that the original content was really
> Unicode to start with.
> 
> So after you "undo" the Unicode conversion, you've still potentially
> got data on your hands from a proprietary non-standards-based made-up
> software application.
> 
> Apologies in advance if MS Word actually *is* using a standard Unicode
> charset... But I sure doubt it.

   I think you're missing the point. MS Word DOES use
proprietary encodings, but when text is copied from
MS Word and pasted into the browser, it involves a
conversion process. E.g., the bullet (0x95 in cp1250)
will be converted to whatever encoding the web page is
in (0x2022 in a Unicode encoding).

   Whether the conversion is performed by the browser,
some OS glue or some other trickery, witchery or devilry,
is at the moment beyond my scant knowledge.

   How to solve the original posters problem is also
beyond me, as I haven't used AJAX. I tend to prefer the
ol' form submission for my bits and bobs. That way I can
use UTF-8 all way around, and everything just magically
works. It even works fine for JavaScript-challenged
browsers, would you believe.


  --nfe

--- End Message ---
--- Begin Message ---
Hello everybody
I'm looking for a newsletter soft. written in php4  to add to a
website done in php4
found a lot of them on the net,
can anyone advise me a good easy one ?
that can administer and send newsletter from the web , if possible in french

Thanks a lot

hicham

--- End Message ---
--- Begin Message ---
Le samedi 07 octobre 2006 à 17:24 -0400, sit1way a écrit :
> Hey all.

Hi Noah,

> I've built a simple, yet effective PHP based CMS, one that I use in all 
> sites I develop.

[...]

> I've often heard the mantra, "separate code from HTML", but it seems 
> ridiculous at times to include tiny HTML snippets that can easily be echoed 
> out, or stored in a variable.  

That mantra generally helps not getting your code and your graphics
messed up. It is only a good suggestion, so you do whatever you want
with it. It's like object oriented programming... it's a good suggestion
and it proves very useful most of the time, but it's for you to judge if
it is useful in your case, and most of the time you cannot judge
perfectly without trying it.

> Smarty goes to the extreme in separating code 
> from HTML, but looking at their templating system, I wonder what's the 
> point?  Is it the end of the world if you've got a few choice if, then, else 
> statements in your HTML templates?

Smarty goes to the extreme because it is *just* a templating engine. You
can still use PHP code in Smarty templates by using specific tags, but
for trying it I think it makes sense to prepare everything *outside* the
display script. The display script can then be given to work on to a web
designer without him messing everything up.
It also helps not getting into one display script that will handle 5
different types of display depending on the conditions. One display
script should really display one kind of data in a specific format. If
you want to change the format, it makes sense to change the display
script.

> I'm thinking of creating a bunch of include files based on request type in 
> my CMS Admin Center; e.g. include "classes/admin/news/add.php", where add, 
> update, or delete is the request type.  This cleans up my PHP processing 
> pages quite a bit (don't have all the if add, do X, elseif update, do Y, 
> etc. logic to comb through).

You can also use the same code base (by playing with Apache
VirtualHost's) and only change the config file and templates location,
rather than the opposite. Up to you again.

Yannick

--- End Message ---

Reply via email to