php-general Digest 17 Aug 2003 09:15:18 -0000 Issue 2241

Topics (messages 159805 through 159830):

Re: redhat 8: upgrade php from 4.2.2 to 4.3.2
        159805 by: Jaap van Ganswijk

Sessions
        159806 by: Peda
        159807 by: Jaap van Ganswijk
        159809 by: Curt Zirzow
        159811 by: Jaap van Ganswijk
        159812 by: Wouter van Vliet
        159815 by: Curt Zirzow
        159816 by: Jason Sheets
        159827 by: Peda
        159828 by: Peda

Re: imagecreatefromjpeg() problems
        159808 by: Jaap van Ganswijk

Re: better understanding of ereg_replace and other functions
        159810 by: Curt Zirzow
        159814 by: Jaap van Ganswijk

Have I over done this?
        159813 by: John Taylor-Johnston

[php] explode that :) !
        159817 by: John Taylor-Johnston
        159818 by: jabber.raditha.com
        159819 by: John Taylor-Johnston
        159820 by: Mike Migurski
        159821 by: Sævar Öfjörð
        159822 by: John Taylor-Johnston
        159823 by: John Taylor-Johnston
        159825 by: Curt Zirzow
        159829 by: Tom Rogers

substr ?
        159824 by: John Taylor-Johnston
        159826 by: John Taylor-Johnston

indexing a folder
        159830 by: Cadish

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 ---
At 2003-08-15 09:31 -0700, Chris W. Parker wrote:
>Hello eveyone.
>
>I want to upgrade my php install from 4.2.2 to 4.3.2. I'm pretty new to
>linux so I don't know how to install from source and I haven't been able
>to find any Redhat 8 rpm's.
>
>Can someone please give me instructions as to what I should do? (Maybe
>links to a site where I can find the correct rpm file or instructions on
>how to install a new version of php from source.. etc.)

I have just upgraded my (Mandrake) system by doing:
- Upgrading from Mandrake 9.0 to 9.1 using the CD's
  that came with the UK Linux Format magazine of
  june 2003:
  www.linuxformat.co.uk
- Then I installed the Apache Source version 2.0.45
  from the CD-ROM that came with PHP Magazine 4.2003
  www.php-mag.net
  and I compiled it, which went very smoothly
- Then I installed the PHP Source version 4.3.2
  from the same CD-ROM and compiled it. (Which
  takes more tinkering.)

The complete process took a while, especially because
I first tried to install from binaries, but it works
very well now, including a GD that supports true color
images etc.

I'm not saying that I think that Mandrake is currently
better than RedHat, but when I switched from Redhat
(5.2 or 6?) to Mandrake 7.2 (?) some years ago it's
installation process was even simpler than that of
RedHat (on which it is based).

In my experience it's a lot of work to upgrade all the
libraries by hand, because they are much too interdependent
and hard to locate on the WWW.

Some tips:
- Install Apache and PHP from source.
- Reboot your computer from time to time between installing
  things and changing .ini and .conf files, just restarting
  Apache is sometimes not enough it seems.
- Put a personal readme file in each directory, describing
  what you did to get things working. (This will help a lot
  next time.)

BTW. There is a separate mailing list about installing PHP.
You'd better ask there and look in it's archive etc.

Greetings,
Jaap


--- End Message ---
--- Begin Message ---
Hi!!

I have some problem on my site.

When I'm using this PHP script:

<?php
    session_start();
    session_register( "aUser", "aAccount" );
    $aUser      = "Cidnie";
    $aAccount   = "1016";
?>
<html>
<head>
 <title>Getting Started With Sessions: Page 1</title>
</head>
<body>
<?php
    print( "Current User: $aUser<br>" );
    print( "Current Account: $aAccount<br>" );
?>
    <br><br>
    <a href="listing2.phtml">Go to page 2</a>
</body>
</html>

I'm getting this warning messages:

Warning: session_start(): open(/tmp/sess_cbd07ca5b53347ca5003404053754bde,
O_RDWR) failed: Permission denied (13) in
/home2/pena/public_html/listing1.php on line 2

Warning: session_start(): Cannot send session cookie - headers already sent
by (output started at /home2/pena/public_html/listing1.php:2) in
/home2/pena/public_html/listing1.php on line 2

Warning: session_start(): Cannot send session cache limiter - headers
already sent (output started at /home2/pena/public_html/listing1.php:2) in
/home2/pena/public_html/listing1.php on line 2

Warning: Unknown(): open(/tmp/sess_cbd07ca5b53347ca5003404053754bde, O_RDWR)
failed: Permission denied (13) in Unknown on line 0

Warning: Unknown(): Failed to write session data (files). Please verify that
the current setting of session.save_path is correct (/tmp) in Unknown on
line 0


It looks like I don't have permission to write in /tmp/ directory.
Can I change that permission?

Greetings, Peda!!!



--- End Message ---
--- Begin Message ---
At 2003-08-16 23:28 +0200, Peda wrote:
>I have some problem on my site.
>
>When I'm using this PHP script:
>
><?php
>    session_start();
>    session_register( "aUser", "aAccount" );
>    $aUser      = "Cidnie";
>    $aAccount   = "1016";
>?>
><?php print( "Current User: $aUser
>" ); print( "Current Account: $aAccount
>" ); ?> 
>
><listing2.htm>Go to page 2 
>I'm getting this warning messages:
>
>Warning: session_start(): open(/tmp/sess_cbd07ca5b53347ca5003404053754bde,
>O_RDWR) failed: Permission denied (13) in
>/home2/pena/public_html/listing1.php on line 2
>
>Warning: session_start(): Cannot send session cookie - headers already sent
>by (output started at /home2/pena/public_html/listing1.php:2) in
>/home2/pena/public_html/listing1.php on line 2
>
>It looks like I don't have permission to write in /tmp/ directory.
>Can I change that permission?

Normally you can only change this when you're the
system manager ('root'), but I'm looking now on
the system that hosts one of my sites and there
I seem to own the /tmp directory that I and my
applications see. It's a kind of virtual private
Unix server.

When you have a shell login, try this:
- cd /tmp
- chown . <your_user_name>

This probably gives an error warning.

- chmod u+rw .

This probably also gives an error warning.

There are also permission commands under FTP I think.

Otherwise contact your system manager.

There are a lot of applications like 'vi' that
don't work or don't work properly without
read and write access to the /tmp directory.

By the way, your second problem about not being
able to send the cookies can be solved by putting
ob_start(); as the first command in your PHP-file.
Make sure you really insert this as the first command.
You can't even output an empty line first for example
in the HTML part (so outside of the <?php and ?>),
also not in an include file.

You can read much more about this in the manual
under output buffering and the header() function
etc.

Greetings,
Jaap


--- End Message ---
--- Begin Message ---
* Thus wrote Jaap van Ganswijk ([EMAIL PROTECTED]):
> At 2003-08-16 23:28 +0200, Peda wrote:
> 
> When you have a shell login, try this:
> - cd /tmp
> - chown . <your_user_name>
> 
> This probably gives an error warning.
> 
> - chmod u+rw .

Don't set your /tmp directoy to those settings. /tmp is a system
directory and should not be owned by any paticular user nor have rw
permissions for a paticular user.

Refer to your OS manual or contact your system administrator and
have him set the proper permissions on /tmp
 

Curt
-- 
"I used to think I was indecisive, but now I'm not so sure."

--- End Message ---
--- Begin Message ---
At 2003-08-16 22:45 +0000, Curt Zirzow wrote:
>* Thus wrote Jaap van Ganswijk ([EMAIL PROTECTED]):
>> At 2003-08-16 23:28 +0200, Peda wrote:
>> 
>> When you have a shell login, try this:
>> - cd /tmp
>> - chown . <your_user_name>
>> 
>> This probably gives an error warning.
>> 
>> - chmod u+rw .
>
>Don't set your /tmp directoy to those settings. /tmp is a system
>directory and should not be owned by any paticular user nor have rw
>permissions for a paticular user.

You're missing some points here:
- When everything is organized okay, he can't make
  himself the owner of /tmp, so trying it doesn't
  hurt.
- But it isn't organized okay and he is asking how
  he can check/change it.
- It doesn't hurt when the /tmp directory is from a
  particular user as long as every one has read and
  write permission. Root and programs running with
  root-permissions can do what they want anyway.
- If he would manage to own the /tmp directory,
  changing his own 'u'=user permissions don't
  affect the permissions of others, but it would
  help him to solve his problem (and isolate the
  problem in case he would want a more fundamental
  solution).

>Refer to your OS manual

He wrote that he had problems with his site (and
not his server) so I assumed he was using the
server of a hoster and not his own system.

>or contact your system administrator and
>have him set the proper permissions on /tmp

Yes, as I also suggested he should contact his
system administrator when he can't solve the
problem using the described experiment.

But when he is on a virtual private server like me
(with no other users) he might also want to solve
the problem himself in the manner that I described.

On a virtual server each user has kind-of a complete
Unix file-system for his personal use, fully
separated from that of the other users. So each
user has his own /tmp directory. It doesn't matter
much who owns it then. In my case, my hoster already
made me the owner of the /tmp directory for example.

BTW. The disadvantage of this system is that whatever
is in the /tmp directory is part of one's quotum and
normally it isn't and one can use the /tmp directory
to use much more harddisk space than the quotum
allows, for example for expanding compressed archives
etc.

Greetings,
Jaap


--- End Message ---
--- Begin Message ---
As others have pointed out already, your problem indeed is about not being
able to write in the tmp directory. Also, as others have pointed out, if
it's not your server you would not be able to change file permissions of the
/tmp directory. Your solution is probably found in changing the path where
php saves session data.

        ini_set('session.save_path', '/full/path/to/your/own/tmp/directory');

Of course you change the path to your own path. That would solve it for the
scripts you have that command in. If the settings of the webserver you're
running on allow it, you'd probably better use a ".htaccess" file in the
folder your php scripts run from (or just the htdocs folder, to have it
applied to all dirs). This file would then contain at least:

        php_value       session.save_path       "/full/path/to/your/own/tmp/directory"

That would also solve your problem.

The other error is also indeed about output being sent before setting a
cookie. You can use ob_start() to get rid if it. But I won't do that. It
just creates overhead, makes your scripts heavier.. As you probably would
have guessed, this time the Warning rose because your script outputted some
other error message, which makes your script also output it's headers. When
you get rid of that first warning, the others will be gone too.

Let me know if it helped you !

Wouter

-----Oorspronkelijk bericht-----
Van: Peda [mailto:[EMAIL PROTECTED]
Verzonden: zaterdag 16 augustus 2003 23:29
Aan: [EMAIL PROTECTED]
Onderwerp: [PHP] Sessions


Hi!!

I have some problem on my site.

When I'm using this PHP script:

<?php
    session_start();
    session_register( "aUser", "aAccount" );
    $aUser      = "Cidnie";
    $aAccount   = "1016";
?>
<html>
<head>
 <title>Getting Started With Sessions: Page 1</title>
</head>
<body>
<?php
    print( "Current User: $aUser<br>" );
    print( "Current Account: $aAccount<br>" );
?>
    <br><br>
    <a href="listing2.phtml">Go to page 2</a>
</body>
</html>

I'm getting this warning messages:

Warning: session_start(): open(/tmp/sess_cbd07ca5b53347ca5003404053754bde,
O_RDWR) failed: Permission denied (13) in
/home2/pena/public_html/listing1.php on line 2

Warning: session_start(): Cannot send session cookie - headers already sent
by (output started at /home2/pena/public_html/listing1.php:2) in
/home2/pena/public_html/listing1.php on line 2

Warning: session_start(): Cannot send session cache limiter - headers
already sent (output started at /home2/pena/public_html/listing1.php:2) in
/home2/pena/public_html/listing1.php on line 2

Warning: Unknown(): open(/tmp/sess_cbd07ca5b53347ca5003404053754bde, O_RDWR)
failed: Permission denied (13) in Unknown on line 0

Warning: Unknown(): Failed to write session data (files). Please verify that
the current setting of session.save_path is correct (/tmp) in Unknown on
line 0


It looks like I don't have permission to write in /tmp/ directory.
Can I change that permission?

Greetings, Peda!!!



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



--- End Message ---
--- Begin Message ---
* Thus wrote Jaap van Ganswijk ([EMAIL PROTECTED]):
> At 2003-08-16 22:45 +0000, Curt Zirzow wrote:
> >* Thus wrote Jaap van Ganswijk ([EMAIL PROTECTED]):
> >> At 2003-08-16 23:28 +0200, Peda wrote:
> >> 
> >> When you have a shell login, try this:
> >> - cd /tmp
> >> - chown . <your_user_name>
> >> 
> >> This probably gives an error warning.
> >> 
> >> - chmod u+rw .
> >
> >Don't set your /tmp directoy to those settings. /tmp is a system
> >directory and should not be owned by any paticular user nor have rw
> >permissions for a paticular user.
> 
> You're missing some points here:
> - When everything is organized okay, he can't make
>   himself the owner of /tmp, so trying it doesn't
>   hurt.

True, it wont hurt, but why suggest to incorrectly do something
that is most likely going to fail anyway.

> - But it isn't organized okay and he is asking how
>   he can check/change it.

again, fixing it incorrectly isn't the solution.

> - It doesn't hurt when the /tmp directory is from a
>   particular user as long as every one has read and
>   write permission. Root and programs running with
>   root-permissions can do what they want anyway.

Yes it does hurt, /tmp should only be set up to whoever created the
file can read write to it, no one else can touch the file.

> - If he would manage to own the /tmp directory,
>   changing his own 'u'=user permissions don't
>   affect the permissions of others, but it would
>   help him to solve his problem (and isolate the
>   problem in case he would want a more fundamental
>   solution).

The problem is already isolated. the /tmp directory needs to have
the correct permissions.


Curt
-- 
"I used to think I was indecisive, but now I'm not so sure."

--- End Message ---
--- Begin Message --- Just a note, in most cases where you have your own private /tmp it is not the same /tmp PHP uses. You are in a chrooted or jailed environment with a virtual /tmp where usually Apache runs outside this restricted environment , the biggest reason being running a seperate set of Apache processes would be very expensive on the resources. If you are using Ensim this is the way it is setup and a few other environments I know of do the same thing.

In this case changing your virtual /tmp ownership would not help Apache/PHP not being able to write to /tmp.

Jason

Curt Zirzow wrote:

The problem is already isolated. the /tmp directory needs to have
the correct permissions.


Curt




--- End Message ---
--- Begin Message ---
Thank you all for your help.

I solved the problem using
session_save_path("/some/dir/") in php script.

But now I have another question.

Every time when I'm using .htaccess file and try to connect to my site I get
this message:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable
to complete your request.
Please contact the server administrator, and inform them of the time the
error occurred, and anything you might have done that may have caused the
error.

More information about this error may be available in the server error log.


Additionally, a 500 Internal Server Error error was encountered while trying
to use an ErrorDocument to handle the request.

When I put in .htaccess file:

php_value session.save_path "/full/path/to/your/own/tmp/directory"

as you told me, I get the same message and in my error_log I get this
message:
[Sun Aug 17 12:31:42 2003] [alert] [client 213.240.5.14]
/home2/pena/public_html/.htaccess: Invalid command 'php_value', perhaps
mis-spelled or defined by a module not included in the server configuration

Thank you again!





--- End Message ---
--- Begin Message ---
Thank you all for your help.

I solved the problem using
session_save_path("/some/dir/") in php script.

But now I have another question.

Every time when I'm using .htaccess file and try to connect to my site I get
this message:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable
to complete your request.
Please contact the server administrator, and inform them of the time the
error occurred, and anything you might have done that may have caused the
error.

More information about this error may be available in the server error log.


Additionally, a 500 Internal Server Error error was encountered while trying
to use an ErrorDocument to handle the request.

When I put in .htaccess file:

php_value session.save_path "/full/path/to/your/own/tmp/directory"

as you told me, I get the same message and in my error_log I get this
message:
[Sun Aug 17 12:31:42 2003] [alert] [client 213.240.5.14]
/home2/pena/public_html/.htaccess: Invalid command 'php_value', perhaps
mis-spelled or defined by a module not included in the server configuration

Thank you again!







--- End Message ---
--- Begin Message ---
At 2003-08-16 14:35 +0200, J-K wrote:
>I've made a little script to make thumbnails which worked before the
>summer, but now I get this errormessage:
>
><b>Fatal error</b>:  Call to undefined function:
>imagecreatefromjpeg() in
><b>/usr/local/others/www.stud.users/mark/gfx/create_tn.php</b> on line
><b>15</b>
>
>First I thought they had done something with the servers, because I
>haven't touched the code. But I checked the GD-version and got this:
>      GD Version: bundled (2.0.12 compatible)
>
>      Shouldn't version 2.0.12 support imagecreatefromjpeg()?

Only when jpeg support has been compiled into
the PHP version that is running on your system.
It doesn't seem to be.

>Is there any way I can get around this?

Try if png support is enabled. But you'd have
to convert your jpeg's I guess and png's are
probably much bigger because they are
non-lossy (?). But it depends on your images
being photo-like and not drawing-like.

Otherwise you'll have to ask your system
manager to fix the problem.

BTW. you shouldn't indent paragraphs in emails,
because it makes quoting them very messy, or
the person answering your mail has to edit out
the indentations (as I have done above).

Greetings,
Jaap


--- End Message ---
--- Begin Message ---
* Thus wrote Binay Agarwal ([EMAIL PROTECTED]):
> Hi everybody,
> 
> Lot of places in manual i came across using "ereg_replace" or "ereg" is very 
> resource intensive and hence its better to use "preg_replace" or "str_replace" or 
> "strpos" if they do the jobs.
> 

I believe the use of ereg_replace in the samples you see is mainly
due to the fact that not until recently has preg_* function been
enabled by default. So it would make sense for the manual to use
examples with ereg_* functions so the example would be garuenteed
to work.

I would even suggest someone to use str_replace over preg_replace.
The fact being that anytime you call a regular expression function
it has to compile the expression and then apply that compiled
expression to the string.  Where the str_replace is directly
manipulating the  string which is quicker than preg_replace's
method. The only time the overhead is acceptable would be when
you're string is not entirely known, so:

  preg_replace('foo-bar-', '', $str);

Can simply be changed to:
  
  str_replace('foo-bar-', '', $str);

The expression, however:
  preg_replace('foo-\w+-', '', $str);

Can't be done with str_replace.

As for the resouce usage vs. ereg and preg, I believe it is
entirely the nature of the libraries that they use.  I don't think
the source of the functions will reveal too much. 

just a few of my thoughts on this subject.

Thanks for your time.

Curt
-- 
"I used to think I was indecisive, but now I'm not so sure."

--- End Message ---
--- Begin Message ---
At 2003-08-16 23:05 +0000, Curt Zirzow wrote:
>* Thus wrote Binay Agarwal ([EMAIL PROTECTED]):
>> Hi everybody,
>> 
>> Lot of places in manual i came across using "ereg_replace" or "ereg" is very 
>> resource intensive and hence its better to use "preg_replace" or "str_replace" or 
>> "strpos" if they do the jobs.
>> 
>
>I believe the use of ereg_replace in the samples you see is mainly
>due to the fact that not until recently has preg_* function been
>enabled by default. So it would make sense for the manual to use
>examples with ereg_* functions so the example would be garuenteed
>to work.

Plus that the ereg functions implement the old-fashioned
Unix regular expressions and preg the Perl variation.
Of course the Unix version (dating from around 1975 or
even earlier) is much more standard than the Perl version
of around 1990 (?).

>I would even suggest someone to use str_replace over preg_replace.

Yes.

>The fact being that anytime you call a regular expression function
>it has to compile the expression and then apply that compiled
>expression to the string.  Where the str_replace is directly
>manipulating the  string which is quicker than preg_replace's
>method.

Compiling the expression is a (time) linear
process so it doesn't matter.

>The only time the overhead is acceptable would be when
>you're string is not entirely known, so:
>
>  preg_replace('foo-bar-', '', $str);
>
>Can simply be changed to:
>  
>  str_replace('foo-bar-', '', $str);
>
>The expression, however:
>  preg_replace('foo-\w+-', '', $str);
>
>Can't be done with str_replace.
>
>As for the resouce usage vs. ereg and preg, I believe it is
>entirely the nature of the libraries that they use.  I don't think
>the source of the functions will reveal too much. 

The real problem is that ereg functions probably
allow more recursion to take place than preg
(which was designed long after the disadvantages
of ereg where known).

In computer science it is never considered a
problem as long as a process is (time) linear,
so that when the input is of size n, the time
taken is n times a constant factor. Just wait
18 months and the average CPU is twice as fast.

What can be a problem however is when a proces
is not (time) linear but for example quadratical
in the time needed for input of size n. So the
time to handle an input of size n is n^2 (times
a constant). This is also no problem when n is
small, but when n gets to be 100 or 1000, the
time consumption gets to be 10,000 or 1000,000
which can become problematical.

The normal str functions are generally (time)
linear in order. The ereg functions can be
recursive and therefore quadratical (or worse)
in nature and the preg functions seem to limit
this because of how they are defined.

But I'm sure that when one would compare the time
taken by the normal str functions to that of ereg
functions given the same simple regular expression
(just a string) that the ereg functions are not
more than twice as slow (and therefore of the
same order) and won't become of quadratical order.

Anyone care to try this out? Just use quite a long
string to search in and execute the search a 1000 or
1000,000 times to make it measurable. Could be a nice
school project...

Greetings,
Jaap


--- End Message ---
--- Begin Message ---
Have I over done this? Can I clean up this code any?
I have two states

1) Admin mode
2) Normal mode

in Normal mode, I have two states:

a) student is not in the database
a) student is in the database and has likely reloaded the browser. I'm trying to avoid 
multiple entries with the same $StudentId

 ###############################################
 ### if $_POST["StudentId" is 99999995, we are in Administrative mode
 ### StudentId=99999995 had already been created as id=1
 ### MySQL can only update id=1
 ###############################################
 if($StudentId == "99999995")
 {
 OpenServer();
 $sql = "UPDATE $db.$table SET
  FamilyName      = '$FamilyName',
  FirstName       = '$FirstName',
  HomeFac         = '$HomeFac',
  SessionSelected = '$SessionSelected'
  WHERE StudentId = '99999995'";
 mysql_query($sql) or die(print mysql_error());
 CloseServer();
 }else{
 ###############################################
 ### We are in normal mode
 ###############################################
 OpenServer();
 $sql = "select StudentId from $table where StudentId = ".$StudentId;
 $news = mysql_query($sql) or die(print mysql_error());
  if (mysql_num_rows($news) == 0)
  {
  ###############################################
  ### $_POST["StudentId" has never registered
  ###############################################
  OpenServer();
  $sql = "INSERT INTO $db.$table
  (StudentId,FamilyName,FirstName,HomeFac,SessionSelected)
  values ('$StudentId','$FamilyName','$FirstName','$HomeFac','$SessionSelected')";
  mysql_query($sql) or die(print mysql_error());
  CloseServer();
  }else{
  ###############################################
  ### $StudentId has registered and has likely
  ### reloaded the browser.
  ### This should prevent multiple entries with
  ### the same $StudentId
  ###############################################
  OpenServer();
  $sql = "UPDATE $db.$table SET
   FamilyName      = '$FamilyName',
   FirstName       = '$FirstName',
   HomeFac         = '$HomeFac',
   SessionSelected = '$SessionSelected'
   WHERE StudentId = '$StudentId'";
  mysql_query($sql) or die(print mysql_error());
  CloseServer();
  }
 CloseServer();
 }

function OpenServer()
{
global $server,$user,$pass,$db;
$myconnection = mysql_connect($server,$user,$pass);
mysql_select_db($db,$myconnection);
}

function CloseServer()
{
global $server,$user,$pass;
$myconnection = mysql_connect($server,$user,$pass);
mysql_close($myconnection);
}



--- End Message ---
--- Begin Message ---
$P1OC1Q1 = "1¶some text or some comment";

echo "<tr><td>Your score is: </td><td>"; $score=split($P1OC1Q1,"¶"); echo 
$score[0]."</td></tr>\n";

Do I have to go through all that to get score[0] ?

John


--- End Message ---
--- Begin Message --- Looks like a really simple piece of code except for the cryptic variable names.

John Taylor-Johnston wrote:

$P1OC1Q1 = "1¶some text or some comment";

echo "<tr><td>Your score is: </td><td>"; $score=split($P1OC1Q1,"¶"); echo $score[0]."</td></tr>\n";

Do I have to go through all that to get score[0] ?

John






--

Raditha Dissanayake
-------------------------------------------------------------
http://www.radinks.com/sftp/
Lean and mean Secure FTP applet with Graphical User Inteface.
just 150 Kilo Bytes



--- End Message ---
--- Begin Message ---
Kind of hoping to do shorten it like this:

echo "<tr><td>Your score is: </td><td>".$score[0]=split($P1OC1Q1,"¶")."</td></tr>\n";

No such hopes?

> Looks like a really simple piece of code except for the cryptic variable names.
>
> >$P1OC1Q1 = "1¶some text or some comment";
> >echo "<tr><td>Your score is: </td><td>"; $score=split($P1OC1Q1,"¶"); echo 
> >$score[0]."</td></tr>\n";
> >
> >Do I have to go through all that to get score[0] ?


--- End Message ---
--- Begin Message ---
>echo "<tr><td>Your score is: </td><td>"; $score=split($P1OC1Q1,"¶"); echo
>$score[0]."</td></tr>\n";
>
>Do I have to go through all that to get score[0] ?

I think reset(split()) should work for getting the first element.

---------------------------------------------------------------------
michal migurski- contact info and pgp key:
sf/ca            http://mike.teczno.com/contact.html


--- End Message ---
--- Begin Message ---
Why not:

echo "<tr><td>Your score is:
</td><td>".split($P1OC1Q1,"")."</td></tr>\n";

-----Original Message-----
From: John Taylor-Johnston [mailto:[EMAIL PROTECTED] 
Sent: 17. ágúst 2003 03:48
To: [EMAIL PROTECTED]
Subject: Re: [PHP] [php] explode that :) !

Kind of hoping to do shorten it like this:

echo "<tr><td>Your score is:
</td><td>".$score[0]=split($P1OC1Q1,"¶")."</td></tr>\n";

No such hopes?

> Looks like a really simple piece of code except for the cryptic
variable names.
>
> >$P1OC1Q1 = "1¶some text or some comment";
> >echo "<tr><td>Your score is: </td><td>"; $score=split($P1OC1Q1,"¶");
echo $score[0]."</td></tr>\n";
> >
> >Do I have to go through all that to get score[0] ?


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



--- End Message ---
--- Begin Message ---
> Why not:
> echo "<tr><td>Your score is:
> </td><td>".split($P1OC1Q1,"¶")."</td></tr>\n";

Ok, but what happens when $P1OC1Q1 = "". It errors out.

$P1OC1Q1 = "";#left blank
$P1OC1Q2 = "1¶bunch of text";
$P1OC1Q3 = "1¶bunch of text";
$P1OC1Q4 = "1¶bunch of text";
$P1OC1Q5 = "1¶bunch of text";
$P1OC1Q6 = "1¶bunch of text";




--- End Message ---
--- Begin Message ---
Actually this does not work:

echo split($P1OC1Q1,"¶");

There are two variables in $P1OC1Q1 = "1¶a bucnh of text"
I want to split $P1OC1Q1 and get "1" as a numeral for a calculation. I was looking for 
a cleaner way to do it.

$P1OC1Q1 = "1¶some text or some comment";
echo "<tr><td>Your score is: </td><td>"; $score=split($P1OC1Q1,"¶");
echo $score[0]."</td></tr>\n";

My problem becomes more difficult when $P1OC1Q1 = "";
Split errors out.


SævË Ölêöyp wrote:

> Why not:
>
> echo "<tr><td>Your score is:
> </td><td>".split($P1OC1Q1,"")."</td></tr>\n";
>
> -----Original Message-----
> From: John Taylor-Johnston [mailto:[EMAIL PROTECTED]
> Sent: 17. ágúst 2003 03:48
> To: [EMAIL PROTECTED]
> Subject: Re: [PHP] [php] explode that :) !
>
> Kind of hoping to do shorten it like this:
>
> echo "<tr><td>Your score is:
> </td><td>".$score[0]=split($P1OC1Q1,"¶")."</td></tr>\n";
>
> No such hopes?
>
> > Looks like a really simple piece of code except for the cryptic
> variable names.
> >
> > >$P1OC1Q1 = "1¶some text or some comment";
> > >echo "<tr><td>Your score is: </td><td>"; $score=split($P1OC1Q1,"¶");
> echo $score[0]."</td></tr>\n";
> > >
> > >Do I have to go through all that to get score[0] ?
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

--
John Taylor-Johnston
-----------------------------------------------------------------------------
"If it's not open-source, it's Murphy's Law."

  ' ' '   Collège de Sherbrooke:
 ô¿ô   http://www.collegesherbrooke.qc.ca/languesmodernes/
   -     Université de Sherbrooke:
          http://compcanlit.ca/
          819-569-2064



--- End Message ---
--- Begin Message ---
* Thus wrote John Taylor-Johnston ([EMAIL PROTECTED]):
> $P1OC1Q1 = "1¶some text or some comment";
> 
> echo "<tr><td>Your score is: </td><td>"; $score=split($P1OC1Q1,"¶"); echo 
> $score[0]."</td></tr>\n";
> 
> Do I have to go through all that to get score[0] ?

substr($P1OC1Q1, 0, strpos($P1OC1Q1, '¶')-1)

That will return every thing to the left of '¶'. and '' if nothing
is there without complaining.


Curt
-- 
"I used to think I was indecisive, but now I'm not so sure."

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

Sunday, August 17, 2003, 12:58:23 PM, you wrote:
JTJ> $P1OC1Q1 = "1¶some text or some comment";

JTJ> echo "<tr><td>Your score is: </td><td>"; $score=split($P1OC1Q1,"¶"); echo 
$score[0]."</td></tr>\n";

JTJ> Do I have to go through all that to get score[0] ?

JTJ> John


if the number is always first and an integer:

echo "<tr><td>Your score is: </td><td>".intval($P1OC1Q1)."</td></tr>\n";

-- 
regards,
Tom


--- End Message ---
--- Begin Message ---
How can I find out if $mystring includes the character "¶"?
Thought substr would do it?
J


--- End Message ---
--- Begin Message ---
Sorry, scrap that:

if (substr_count($mystring,"¶") >0)

John Taylor-Johnston wrote:

> How can I find out if $mystring includes the character "¶"?
> Thought substr would do it?
> J

--
John Taylor-Johnston
-----------------------------------------------------------------------------
"If it's not open-source, it's Murphy's Law."

  ' ' '   Collège de Sherbrooke:
 ô¿ô   http://www.collegesherbrooke.qc.ca/languesmodernes/
   -     Université de Sherbrooke:
          http://compcanlit.ca/
          819-569-2064



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

How can i index a folder that's not on my server?

With indexing, i mean getting a list of all files in that folder...

Thx a lot
Cadish



--- End Message ---

Reply via email to