php-general Digest 30 Apr 2005 11:53:55 -0000 Issue 3427

Topics (messages 214251 through 214266):

Re: Splitting Vars from MySQL in PHP
        214251 by: Philip Olson

Re: Templating engines
        214252 by: Mattias Thorslund
        214254 by: Matthew Weier O'Phinney
        214255 by: Robert Cummings
        214256 by: Greg Donald
        214258 by: Rasmus Lerdorf
        214259 by: Robert Cummings

Re: Is it possible to save a file with UTF-8 encoding and noBOM using PHP?
        214253 by: Rasmus Lerdorf

About the mail().
        214257 by: Penghui Wang

sessions problems
        214260 by: Anasta
        214261 by: Deep

Re: Regular expressions problem
        214262 by: Khorosh Irani
        214263 by: Rasmus Lerdorf
        214266 by: Matthew Weier O'Phinney

Re: How to know if php CAN write files on server and WHERE  it can?
        214264 by: Giulio

Re: Can this code go faster?
        214265 by: Rory Browne

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 ---
> > I remember in Perl I used to extract vars from a single fetchrow by adding
> > each var name to the beginning (like this). Only this ain'ta workin :)...
> > Anyone know the right syntax to do this?
> > 
> > ($var1, $var2, $var3)= mysql_fetch_array($result, MYSQL_ASSOC)
> 
> 
> list($var1, $var2, $var3) = mysql_fetch_array($result, MYSQL_ASSOC);
> http://us4.php.net/manual/en/function.list.php

But remember that list() only works with numerical 
arrays so use MYSQL_NUM (or array_values()) in the 
above. For associative, extract() can be useful.

Regards,
Philip

--- End Message ---
--- Begin Message ---
Rasmus Lerdorf wrote:

Mattias Thorslund wrote:

Who says PHP itself is a template engine? I think nobody.


I do.

It comes down to whether you want the delineation between the template and the business logic enforced by the system or not. PHP is a general-purpose templating system that does not enforce this delineation.



That explanation is sensible enough.


[skipping ahead a little]

The approach I tend to point people at is something I have been calling a Template API. That is, when you build your application, you create a template api to go along with it. In essence you are creating a templating system for each application you write.


For many projects, I think the approach you describe in the example (below) is appropriate. One nice thing is that output can begin before the whole page has been nearly processed. I don't know if many other templating solutions can do that.

To me, it looks like it would be hard to keep the functions that are called by the template to a reasonable format or number, at least in a larger project. If it's a template that is to be used by many kinds of pages, there would be either a large number of functions, or there would be generic functions that need to do different things based on the situation.

Of course, the functions could become methods of a "page" object. Then, it gets easy to create specialized subclasses of page objects which can respond differently to the same generic method call. Sounds more attractive the more I think about it :-)

Then again, if I need a big object to handle the business logic (and dynamic presentation logic) because my template approach is sequential, it might be a toss-up compared to using sequential business logic and a small template object.


For example, I describe a simple such system here:

   http://talks.php.net/show/mtladv05/20

To me, this is a perfectly good template (from the slide):

  <?php
  start_poll(1);
  $os = array("FreeBSD","Linux","OSX","Windows","Other");
  ?>
  <p class="purpose">
  Please answer a couple of questions for us.
  </p>

  <p class="question">
  1. What is your name?
  </p>
  <?php text_answer('name',64)?>

  <p class="question">
  2. Which operating systems do you use on a daily basis?
  </p>
  <?php select_any_of($os)?>

  <p class="question">
  3. Which operating system do you prefer?
  </p>
  <?php select_one_of($os)?>

  <?php end_poll(); ?>

The end_poll() call could be eliminated as well to make it slightly cleaner, but otherwise this is straight-forward with no mixing of business-logic and content.


My main issue with general-purpose templating systems is that they always end up inventing a new language.


Except the class described in the article I was talking about. It uses PHP as the template language. It's a big reason why I find it attractive.

[skipping discussion on Smarty]

As far as I am concerned you shouldn't be dealing with any sort of objects from a template to begin with.


This does place some demands on the business logic.

There should be nothing but simple variables and straight function calls from a template, but this is a religious issue that people will never agree on. Hence PHP's neutral approach where the exact templating delienation is left up to the users.


No doubt, people will continue to argue over it for a long time to come. I try not to be religious about it, I simply want to know as many sides of the issue as possible.

Best,

Mattias


-- More views at http://www.thorslund.us

--- End Message ---
--- Begin Message ---
* Rasmus Lerdorf <[EMAIL PROTECTED]> :
> My main issue with general-purpose templating systems is that they 
> always end up inventing a new language.  It may start off as a subset of 
> some other language, but eventually it turns into a new language.  In 
> Smarty, for example, you now have stuff like:
>
>    {object-> method p1="arg1" p2=$arg2 assign="output"}
>    Result was {$output}
>
> I fail to see how this is in any way better/easier/superior to:
>
>    <?$output = $object-> method("arg1",$arg2)?>
>    Result was <?=$output?>
>
> As far as I am concerned you shouldn't be dealing with any sort of 
> objects from a template to begin with.  There should be nothing but 
> simple variables and straight function calls from a template, but this 
> is a religious issue that people will never agree on.  Hence PHP's 
> neutral approach where the exact templating delienation is left up to 
> the users.

I thoroughly agree with you on this point. I think in some areas of
Smarty development, they've gotten a little too complex, likely as a
result of people getting lazy in what they send to the template and
requesting new features. That said, I still use Smarty -- but I try to
send it straight scalars or arrays, as you suggest above, leaving my
heavy lifting in my application logic, and keep the presentation logic
more lightweight.

In reading "The Pragmatic Programmer," I think that templating languages
are an application of using metadata or a domain language. The principle
here is a subset of the language -- or another language entirely that
can be interpreted by the original language -- helps to contain and
solve the problem. Sometimes it's easier to use the subset to describe
the process than the full language. 

Let's face it, there's over 1000 functions in PHP; most of the time, I
only need a few of those for my display logic. Using a template engine
and its language helps me switch gears in my brain to thinking in terms
of display instead of my application logic.

-- 
Matthew Weier O'Phinney           | WEBSITES:
Webmaster and IT Specialist       | http://www.garden.org
National Gardening Association    | http://www.kidsgardening.com
802-863-5251 x156                 | http://nationalgardenmonth.org
mailto:[EMAIL PROTECTED]         | http://vermontbotanical.org

--- End Message ---
--- Begin Message ---
On Fri, 2005-04-29 at 21:09, Mattias Thorslund wrote:
> Rasmus Lerdorf wrote:
> 
> > Mattias Thorslund wrote:
> >
> >> Who says PHP itself is a template engine?  I think nobody. 
> >
> >
> > I do.
> >
> > It comes down to whether you want the delineation between the template 
> > and the business logic enforced by the system or not.  PHP is a 
> > general-purpose templating system that does not enforce this 
> > delineation.  

> That explanation is sensible enough.
> 
> 
> [skipping ahead a little]
> 
> > The approach I tend to point people at is something I have been 
> > calling a Template API.  That is, when you build your application, you 
> > create a template api to go along with it.  In essence you are 
> > creating a templating system for each application you write.

I think a problem here is when you decide to blend two projects that
started out separately. With a templating system (some anyways :) you
can just redefine the main layout for each page being merged into the
larger project in a single centralized location. The approach described
above would appear to require in depth modification of the application's
"template API".

> For many projects, I think the approach you describe in the example 
> (below) is appropriate. One nice thing is that output can begin before 
> the whole page has been nearly processed.  I don't know if many other 
> templating solutions can do that.

Personally I find having the output ALWAYS begin after all business
logic has completed to be a better choice, that way upon error (a
catchable error) you can redirect the user to an info page that might
state the page is temporarily unaccessible.

> To me, it looks like it would be hard to keep the functions that are 
> called by the template to a reasonable format or number, at least in a 
> larger project.  If it's a template that is to be used by many kinds of 
> pages, there would be either a large number of functions, or there would 
> be generic functions that need to do different things based on the 
> situation.

I don't think that templates have a dependency between the number of
pages using the template and an increase in the number of functions. In
fact depending on the template, and the template engine, you can have
500 pages using the template and not a single function call. Including
the elimination of include() and include_once() calls since if the
template engine compiles to PHP it can do the includes at compile time
rather than punting to PHP to do at run-time.

> Of course, the functions could become methods of a "page" object. Then, 
> it gets easy to create specialized subclasses of page objects which can 
> respond differently to the same generic method call.  Sounds more 
> attractive the more I think about it :-)

So every time you want a small difference you subclass the main page
object. Seems a lot of work and overhead for something small. What
happens when you want to share functionality from one project in another
without recoding or copying it?

I personally prefer the modularization of custom functionality into
loadable compiler modules. I find this especially convenient when an XML
or XML-like template system is used that allows namespaces. Then you can
just include already created functionality via module includes at
compile time, and incur no overhead at run-time. Not to mention you get
to skip past the whole sub-classing nightmare, although there's nothing
to stop you from sub-classing a compiler module :) But at least it's
more portable and re-usable. Overhead is still incurred for
transformation on dynamic content, but even still if you are
transforming dynamic content via the template engine you at least
minimize the amount of work needing to be done at run-time.

> Then again, if I need a big object to handle the business logic (and 
> dynamic presentation logic) because my template approach is sequential, 
> it might be a toss-up compared to using sequential business logic and a 
> small template object.
> 
> 
> > For example, I describe a simple such system here:
> >
> >    http://talks.php.net/show/mtladv05/20
> >
> > To me, this is a perfectly good template (from the slide):
> >
> >   <?php
> >   start_poll(1);
> >   $os = array("FreeBSD","Linux","OSX","Windows","Other");
> >   ?>
> >   <p class="purpose">
> >   Please answer a couple of questions for us.
> >   </p>
> >
> >   <p class="question">
> >   1. What is your name?
> >   </p>
> >   <?php text_answer('name',64)?>
> >
> >   <p class="question">
> >   2. Which operating systems do you use on a daily basis?
> >   </p>
> >   <?php select_any_of($os)?>
> >
> >   <p class="question">
> >   3. Which operating system do you prefer?
> >   </p>
> >   <?php select_one_of($os)?>
> >
> >   <?php end_poll(); ?>
> >
> > The end_poll() call could be eliminated as well to make it slightly 
> > cleaner, but otherwise this is straight-forward with no mixing of 
> > business-logic and content.

This works, but now what happens when your client/boss requests that the
operating system choice not be a multi-select list but rather checkboxes
and those check boxes should be 3 columns wide. The convenient
select_any_of() function is no longer usable and while I know you can
still use PHP as the template language, it surely doesn't look as neat
as the above. Now add validation error messages, javascript events, and
other stuff that is usually required in a real life situation. The
source starts to get difficult to read and maintain as you switch in and
out of PHP, HTML, and Javascript :)

> > My main issue with general-purpose templating systems is that they 
> > always end up inventing a new language.  

Not always. An XML style templating language is making use of an
existing language which is much closer to the format used by content
developers than PHP. And even if you are a coder, using XML tags in HTML
content rather than switching in and out of PHP tags makes the source
much easier to grok while providing an advantage that PHP still doesn't
have, and from what I've read recently, won't be adding anytime soon...
named and optional parameters.

Contrast:

<?php displayNews( 'Latest News', 'cbc', null, '#eeeeff' ); ?>

Versus:

<?php displayNews( array( 'title'=>'Latest News', 'source'=>'cbc',
'bgcolour'=>'#eeeeff' ) ); ?>

Versus:

<aProject:news title="Latest News" source="cbc" bgcolour="#eeeeff"/>

At a glance the first PHP version requires intimate knowledge of the
function parameters (what each is and the order). Additionally because I
wanted to override the background colour but not the number of paging
entries, I had to include the extra "null" parameter to inform the
function to skip past it.

The second PHP version is functionaly as good as the XML version, but
let's admit it, it's not nearly as clean and coherent.

> Except the class described in the article I was talking about.  It uses 
> PHP as the template language.  It's a big reason why I find it attractive.
> 
> [skipping discussion on Smarty]
> 
> > As far as I am concerned you shouldn't be dealing with any sort of 
> > objects from a template to begin with. 
> 
> 
> This does place some demands on the business logic. 
> 
> > There should be nothing but simple variables and straight function 
> > calls from a template, but this is a religious issue that people will 
> > never agree on.  Hence PHP's neutral approach where the exact 
> > templating delienation is left up to the users.

I think there should be nothing but simple variables and function calls
(or at least the equivalents for any given template system) but
additionally I believe foreach and if constructs to also be appropriate
to act upon the simple variables and function calls to avoid the need to
move display logic back into the business logic.

> No doubt, people will continue to argue over it for a long time to 
> come.  I try not to be religious about it, I simply want to know as many 
> sides of the issue as possible.

IMHO the advocacy of a templating system depends on the project. I
wouldn't generally use one for a small 2 to 5 page project, but once I
start getting into projects with more than 10 pages, and especially
projects with 100s of pages, I'd be hard pressed to accept a straight
PHP implementation.

Ultimately I think this debate is similar to the braces style debate.
Some people just prefer one style over the other and there's not really
a right or wrong position, just a general warm fuzzy feeling that you're
doing things the way you best see fit :)

Cheers,
Rob.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

--- End Message ---
--- Begin Message ---
On 4/29/05, Robert Cummings <[EMAIL PROTECTED]> wrote:
> Personally I find having the output ALWAYS begin after all business
> logic has completed to be a better choice

I agree totally.  Most PHP coders I've worked around put PHP in their
HTML.  I am the exact opposite.  I use PHP to build up my HTML and
then output it at the very end of the script.  I use heredoc syntax
almost exclusively.  Seems very clean.

Drives me insane to see HTML with stuff like <?=$var?> all through it.


-- 
Greg Donald
Zend Certified Engineer
http://destiney.com/

--- End Message ---
--- Begin Message --- Robert Cummings wrote:
I think a problem here is when you decide to blend two projects that
started out separately. With a templating system (some anyways :) you
can just redefine the main layout for each page being merged into the
larger project in a single centralized location. The approach described
above would appear to require in depth modification of the application's
"template API".

The template api is a functional description of the backend capabilities you are exposing to the templates. They shouldn't have to change unless you are making changes to those backend capabilities. The templates themselves provide the markup and location of these various components of the application. The stack looks like this:


  http://talks.php.net/show/lca05/58

So if you are blending things together you will at most need to change the top two layers.

I don't think that templates have a dependency between the number of
pages using the template and an increase in the number of functions. In
fact depending on the template, and the template engine, you can have
500 pages using the template and not a single function call. Including
the elimination of include() and include_once() calls since if the
template engine compiles to PHP it can do the includes at compile time
rather than punting to PHP to do at run-time.

While compiling to PHP is by far superior to the various terrible eval() and regex-based templating layers out there, it is still dog-slow compared to tight specialized PHP code. Just instantiating the base Smarty class, for example, takes a very long time. I optimized a Smarty site a while back where I got a 50% speedup by migrating the base Smarty class to C in an extension.


So while how you want to separate your business logic from your layout and content, which to me are actually 3 levels of separation, is a religious thing, performance is not. Even though most sites don't get anywhere near the traffic of the stuff I deal with at Yahoo!, it still makes a difference whether your pages get served up in 80ns vs. 500ns. The 80ns page starts rendering right away with no latency and the whole thing has a perceptible crispness to it.

This works, but now what happens when your client/boss requests that the
operating system choice not be a multi-select list but rather checkboxes
and those check boxes should be 3 columns wide. The convenient
select_any_of() function is no longer usable and while I know you can
still use PHP as the template language, it surely doesn't look as neat
as the above. Now add validation error messages, javascript events, and
other stuff that is usually required in a real life situation. The
source starts to get difficult to read and maintain as you switch in and
out of PHP, HTML, and Javascript :)

You simply change the select_any_of() API function, or make another one. There are 3 levels of separation here. For large projects you have people who provide content. In this example, these are the people writing the actual polls. They are not web designers, they don't know any Javascript and next to no HTML. They simply provide the content for the application. Much like a journalist would provide content to a news site. The next layer down is the HTML/Javascript and whatever presentation layer magic you need. And finally, the 3rd layer is the business logic which is where your database calls and real meat of your application resides. In this 3rd layer there is absolutely no HTML nor Javascript.


-Rasmus
--- End Message ---
--- Begin Message ---
On Fri, 2005-04-29 at 23:55, Rasmus Lerdorf wrote:
> Robert Cummings wrote:
> > I don't think that templates have a dependency between the number of
> > pages using the template and an increase in the number of functions. In
> > fact depending on the template, and the template engine, you can have
> > 500 pages using the template and not a single function call. Including
> > the elimination of include() and include_once() calls since if the
> > template engine compiles to PHP it can do the includes at compile time
> > rather than punting to PHP to do at run-time.
> 
> While compiling to PHP is by far superior to the various terrible eval() 
> and regex-based templating layers out there, it is still dog-slow 
> compared to tight specialized PHP code.  Just instantiating the base 
> Smarty class, for example, takes a very long time.  I optimized a Smarty 
> site a while back where I got a 50% speedup by migrating the base Smarty 
> class to C in an extension.

This isn't a problem for engines that compile to PHP source that has
direct hooks into the necessary data structures that will contain the
data at run time.

Smarty isn't one of them though :)

Cheers,
Rob.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'


--- End Message ---
--- Begin Message --- Jon M. wrote:
No matter what I do to the strings to encode them in whatever format before using "fwrite", it ALWAYS seems to end up writing the actual file in "iso-8859-1".

Isn't the encoding of the characters in PHP's strings, and the encoding of the actual binary file on your hard drive, two totally different things? Or am I just misinformed?

A file is completely defined by its contents. If you fwrite UTF-8 data to the file, then it is a UTF-8 file. Whether your editor, or whatever it is you are using to determine the file is being written as iso-8859-1 is smart enough to pick this up is a completely different question.


Why don't you try creating the same contents with PHP and with your preferred text editor and then compare the contents. Perhaps your editor is dropping a hint somewhere in it that you are not writing to the file from PHP.

-Rasmus
--- End Message ---
--- Begin Message ---
Hi lists:

I am new here. And i know little about php. Sorry ask so stupid
question.
I want to use my local /usr/sbin/sendmail to send mail to a certain
address. I have checked the function_list in http://www,php.net.
And i found the mail(). It enough to my requirement.

And i have written a php file like below:

<?php
if($_POST['send']) {
  $message = $_POST['message'];
  $body = "ååï" . $message['username'] . "\n" .
      "éäååï" . $message['usermail'] . "\n" .
      "åååçï" . $message['compname'] . "\n" .
      "çèåçï" . $message['telephone'] . "\n\n" .
      "ééäéï" . $message['subject'] . "\n" .
      "ééååï" . $message['content'] . "\n";

  $headers .= "Content-Transfer-Encoding: UTF-8\n";
  $headers .= "Content-Type: text/plain; charset=utf-8\n";
  $headers .= "MIME-Version: 1.0\n";
  $headers .= "From: [EMAIL PROTECTED]";
  $headers .= "X-Mailer: Online Help!(http://www.example.com)\n";

  mail('[EMAIL PROTECTED]', 'æéèåå! ', $body, $headers);
  header("Location: http://www.example.com";);
}

if($_POST['cancel']) {
  header("Location: http://www.example.com";);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd";>
<html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="zh" >
<head>
<title>åçæé</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<h1 style="text-align:center;color: red">åçåå</h1>
<div style="margin: auto; width: 65%;">
<p>èéæåçååæåïåæææääééæçéïæåäåååååäéïèææäååäåçäæéååæçééïååçæäåå.</p>
<form method="post">
<fieldset>
<legend>æçèçäæ</legend>
æçååï<input type="text" name="message[username]" >
éäååï<input type="text" name="message[usermail]" ><br>
åååçï<input type="text" name="message[compname]" >
çèåçï<input type="text" name="message[telephone]" >
</fieldset>
<fieldset>
<legend>ææéçéé</legend>
äéï<input name="message[subject]" type="text" size="30" value=""
maxLength="100"><br>
ååï<textarea name="message[content]"rows="10" cols="70"></textarea>
<div style="text-align:center">
<input type="submit" name="send" value="åé">
<input type="submit" name="cancel" value="åæ">
</div>
</fieldset>
</form>
</div>
</body>
</html>

But all the chinese words could change to "????". The charset of this
file is UTF-8.
I wonder know how to deal with it. And i am blind with it now. Because
the lack of experience with php.


Best regards

Wang Penghui



--- End Message ---
--- Begin Message ---
Anyone know how to update a record on logout, heres what i am using for
login, however there iare no variables for the logout page.

?
session_start();  // Start Session

include("connect.php");

$username = $_POST['username'];
$password = $_POST['password'];

   // Register some session variables
   session_register('username');
   $_SESSION['username'] = $username;
 //sets user online to yes
$sql = mysql_query("UPDATE users SET online='1' WHERE username='$username'
AND password='$password'");

   if (($username == "admin") And ($password == "admin")) {
    header("location: login_admin.php");
   } else {
    header("location: login_success.php");
   }

?>

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

   When someone hit the logout page say "logout.php".
You can write the code in that page itself to update
the record. Since the username of that particular user
is stored as a session as long as the user closes the
browser window.

So in the logout page you can add like this.....

session_start();
include("connect.php");
$uname=$_SESSION['username'];
$sql = mysql_query("UPDATE users SET online='0'
 WHERE username='$uname'");

//alternatively u can also delete that particular user
from the database instead of updating the online
status to '0'.

I hope this might help you.

Regards
..Deeps..

--- Anasta <[EMAIL PROTECTED]> wrote:
> Anyone know how to update a record on logout, heres
> what i am using for
> login, however there iare no variables for the
> logout page.
> 
> ?
> session_start();  // Start Session
> 
> include("connect.php");
> 
> $username = $_POST['username'];
> $password = $_POST['password'];
> 
>    // Register some session variables
>    session_register('username');
>    $_SESSION['username'] = $username;
>  //sets user online to yes
> $sql = mysql_query("UPDATE users SET online='1'
> WHERE username='$username'
> AND password='$password'");
> 
>    if (($username == "admin") And ($password ==
> "admin")) {
>     header("location: login_admin.php");
>    } else {
>     header("location: login_success.php");
>    }
> 
> ?>
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 

________________________________________________________________________
Yahoo! India Matrimony: Find your life partner online
Go to: http://yahoo.shaadi.com/india-matrimony

--- End Message ---
--- Begin Message ---
For example I want to math this stream:
123 mm  334
What is the pattern that math with this stream?
Thanks

On 4/29/05, Malcolm Mill <[EMAIL PROTECTED]> wrote:
> What is it you want to do?
> 
> On 4/29/05, Khorosh Irani <[EMAIL PROTECTED]> wrote:
> > Hello
> > I have a question:
> > What is in the role of space in the regular expressions (POSIX)?
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>

--- End Message ---
--- Begin Message --- Khorosh Irani wrote:
For example I want to math this stream:
123 mm  334
What is the pattern that math with this stream?
Thanks

123[[:space:]]+mm[[:space:]]+334

-Rasmus
--- End Message ---
--- Begin Message ---
* Khorosh Irani <[EMAIL PROTECTED]>:
> For example I want to math this stream:
> 123 mm  334
> What is the pattern that math with this stream?

Depends on what regexp function you use, what exactly you want to match,
and whether or not you want to know, after you match, any of the
segments. Rasmus has given you one possible pattern that works with the
ereg functions. If you wanted to use a preg function and wanted to match
3 digits, a space, two m', one or more spaces, and 3 digits, you would
use:

    preg_match('/^\d{3} mm\s+\d{3}$/', $string);

But, what it all comes down to is: you need to determine what PATTERN
you need to be able to match. Once you know that, you can write the
regexp.

> On 4/29/05, Malcolm Mill <[EMAIL PROTECTED]> wrote:
> > What is it you want to do?
> > 
> > On 4/29/05, Khorosh Irani <[EMAIL PROTECTED]> wrote:
> > > Hello
> > > I have a question:
> > > What is in the role of space in the regular expressions (POSIX)?

-- 
Matthew Weier O'Phinney           | WEBSITES:
Webmaster and IT Specialist       | http://www.garden.org
National Gardening Association    | http://www.kidsgardening.com
802-863-5251 x156                 | http://nationalgardenmonth.org
mailto:[EMAIL PROTECTED]         | http://vermontbotanical.org

--- End Message ---
--- Begin Message ---
Thanks Richard for your answer

Il giorno 29/apr/05, alle 10:07 PM, Richard Lynch ha scritto:


If you're just going to delete the files after your script is done, why
copy them somewhere else at all?

Your best bet is to try and use the /tmp dir, or, more properly, what PHP
thinks is a "good" place for tmp files.

I developed an application that uploads files on the server calling a php page, using post just as a form would be.


to avoid the max_file_size and max_post_size problems, the application splits large files on smasller chunks, and calls repeatedly the php sending one file chunk at a time, every time waiting for a response from the php page and then reposting to it subsequent chunk of data.

So the php script is called more times, one for every chunk, and at the last call It's up to the php script to re-construct the entire file when all the uploads are finished, and then copy it on a known location using ftp.

That's why I would like to move every temp file on another directory, since I'm not assured that php temp files will keep existing during all the upload process transactions ( or worst, could be php engine itself deleting them immediatly when php script execution ends? )

Hope was clear what I'm attempting to do...

regards,

      Giulio


For that matter, using http://php.net/tmpfile may take care of all your worries on this one.


Cantoberon Multimedia srl http://www.cantoberon.it Tel. 06 39737052

--- End Message ---
--- Begin Message ---
I sent this about a week ago, but I forgot to 'reply to all', and send
it to the list.
Thanks Rolf for pointing that out to me.

I'm not totally sure, but this might work. I'm too tired to understand
rolf's masks, but:

<?php

function bin2int($bin){
  $a = bindec($bin);
  return ($a < 128) ? ($a) : ($a - 256);
} Not sure if that's faster or not.

You could also try using string indices, instead of substr.

function bin2int($bin){
  if(  $bin{0} ){
    return bindec($bin) - 256;
  } else {
    return bindec($bin);
}

or using ? :

function bin2int($bin){
  return ($bin{0}) ? (bindec($bin) - 256) : bindec($bin);
}

It's not something I'd worry about too much, although I would advocate
getting rid of your substr()'s
On 26 Apr 2005 19:40:10 -0000, Rolf �stvik <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] (Ren� Fournier) wrote in
> news:[EMAIL PROTECTED]:
>
> > I need to convert a binary number of arbitrary length to a signed
> > integer.
> > This is how I'm doing it now:
> > CODE
> > --------
> > function bin2int ($bin) {
> >      if (substr($bin,0,1) == 1) {
> >           $val = 0 - bindec(substr($bin,1));     // NEGATIVE
> >           } else {
> >           $val = bindec(substr($bin,1));     // POSITIVE
> >           }
> >      }
> >
> > echo bin2int("00001101").'<br />';
> > echo bin2int("10001101");
> >
> > OUTPUT
> > --------
> > 13
> > -13
> >
> > As you can see, if the most-significant bit is 1, then the rest of the
> > value is negative. If the first bit is 0, then the rest is positive.
>
> If this is what you want then your numeric representation of negative
> numbers is not standard. In that case your function is as good as you can
> get.
>
> This is the standard two's complement representation:
> "00001101"      is 13
> "11110010"      is -13
> "10001101"      is -115
>
> You specify the most-significant bit as sign bit, and that you can have a
> arbitrary lenght string representing a binary number.
> Then "010" will be different than "10", is that correct?
>
> If you on the other hand know that the string should represent an 8 bit in
> two's complement then this could work:
>
> function bin2int ($bin) {
>     $a =  bindec($bin);
>
>     $val = ($a | 0x80) ? (0xffffff00 | $a) : $a;
>
>     return $val;
> }
>
> //  or by using if instead of ? and :
> //function bin2int ($bin) {
> //    $a =  bindec($bin);
> //  if ( $a | 0x80) {
> //      $val = (0xffffff00 | $a);
> //  } else {
> //      $val =$a;
> //  }
> //
> //    return $val;
> //}
>
> If the string represent a 16 bit number use
> $val = ($ | 0x8000) ? (0xffff0000 | $a) : $a;
>
> If the string represent a 32 bit number use only bindec
>
> If you still want
>  - a leading 1 to represent a negative number,
>  - and that the string can have arbitrary lenght,
>  - but you want correct two's complement representation
> then we need something different, e.g:
>
> function bin2int ($bin) {
>     if (substr($bin,0,1) == 1) {
>         // NEGATIVE
>         $val = bindec(substr("11111111111111111111111111111111".$bin,-32));
>     } else {
>            // POSITIVE
>         $val = bindec($bin);
>     }
>     return $val;
> }
>
> --
> Rolf
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---

Reply via email to