[PHP] What's wrong with this code?

2010-06-05 Thread David Mehler
Hello,
I've got a while loop outputting values from a database. Briefly it
looks like this:

while($row = mysql_fetch_array($result3))
 {
 echo tr;
 echo td . $row['name'] . /td;
 echo td . $row['type'] . /td;
 echo td . $row['startdate'] . /td;
if (!empty($row['EndDate'])) {
 echo td . $row['enddate'] . /td;
} else {
exit();
}
 echo td . $row['location'] . /td;
 echo td . $row['summary'] . /td;
 echo td . $row['description'] . /td;
 echo /tr;
}

That's not the whole code, but it is the problem code. Some output has
the ending date set, one or two records i can't remember how many i
entered with one, most do not, i want the echo to be conditional. The
output stops right before the if statement, echoes startdate and
that's it, comment out the if block and it works fine.
Thanks.
Dave.

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



Re: [PHP] What's wrong with this code?

2010-06-05 Thread Karl DeSaulniers
Could the exit() be terminating it? Do you need this exit() as the  
else for that if statement? Try deleting just the else {}.


JAT

Karl

Sent from losPhone

On Jun 5, 2010, at 6:54 PM, David Mehler dave.meh...@gmail.com wrote:


Hello,
I've got a while loop outputting values from a database. Briefly it
looks like this:

while($row = mysql_fetch_array($result3))
{
echo tr;
echo td . $row['name'] . /td;
echo td . $row['type'] . /td;
echo td . $row['startdate'] . /td;
if (!empty($row['EndDate'])) {
echo td . $row['enddate'] . /td;
} else {
exit();
}
echo td . $row['location'] . /td;
echo td . $row['summary'] . /td;
echo td . $row['description'] . /td;
echo /tr;
}

That's not the whole code, but it is the problem code. Some output has
the ending date set, one or two records i can't remember how many i
entered with one, most do not, i want the echo to be conditional. The
output stops right before the if statement, echoes startdate and
that's it, comment out the if block and it works fine.
Thanks.
Dave.

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



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



Re: [PHP] What's wrong with this code?

2010-06-05 Thread David Mehler
Hi,
Thanks. I took out the entire else section including the exit call, it
now all processes, however $row['enddate'] is not displayed on the two
records where it is set.
Thanks.
Dave.


On 6/5/10, Karl DeSaulniers k...@designdrumm.com wrote:
 Could the exit() be terminating it? Do you need this exit() as the
 else for that if statement? Try deleting just the else {}.

 JAT

 Karl

 Sent from losPhone

 On Jun 5, 2010, at 6:54 PM, David Mehler dave.meh...@gmail.com wrote:

 Hello,
 I've got a while loop outputting values from a database. Briefly it
 looks like this:

 while($row = mysql_fetch_array($result3))
 {
 echo tr;
 echo td . $row['name'] . /td;
 echo td . $row['type'] . /td;
 echo td . $row['startdate'] . /td;
 if (!empty($row['EndDate'])) {
 echo td . $row['enddate'] . /td;
 } else {
 exit();
 }
 echo td . $row['location'] . /td;
 echo td . $row['summary'] . /td;
 echo td . $row['description'] . /td;
 echo /tr;
 }

 That's not the whole code, but it is the problem code. Some output has
 the ending date set, one or two records i can't remember how many i
 entered with one, most do not, i want the echo to be conditional. The
 output stops right before the if statement, echoes startdate and
 that's it, comment out the if block and it works fine.
 Thanks.
 Dave.

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


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



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



Re: [PHP] What's wrong with this code?

2010-06-05 Thread Karl DeSaulniers

So your code looks like this?

while($row = mysql_fetch_array($result3))
{
echo tr;
echo td . $row['name'] . /td;
echo td . $row['type'] . /td;
echo td . $row['startdate'] . /td;
if (!empty($row['EndDate'])) {  //This should probably be $row 
['enddate']

echo td . $row['enddate'] . /td;
}

echo td . $row['location'] . /td;
echo td . $row['summary'] . /td;
echo td . $row['description'] . /td;
echo /tr;
}


Not to mention, you have a $row['EndDate'] and a $row['enddate'].
Probably need to choose one or the other.

HTH,

Karl



On Jun 5, 2010, at 7:43 PM, David Mehler wrote:


Hi,
Thanks. I took out the entire else section including the exit call, it
now all processes, however $row['enddate'] is not displayed on the two
records where it is set.
Thanks.
Dave.


On 6/5/10, Karl DeSaulniers k...@designdrumm.com wrote:

Could the exit() be terminating it? Do you need this exit() as the
else for that if statement? Try deleting just the else {}.

JAT

Karl

Sent from losPhone

On Jun 5, 2010, at 6:54 PM, David Mehler dave.meh...@gmail.com  
wrote:



Hello,
I've got a while loop outputting values from a database. Briefly it
looks like this:

while($row = mysql_fetch_array($result3))
{
echo tr;
echo td . $row['name'] . /td;
echo td . $row['type'] . /td;
echo td . $row['startdate'] . /td;
if (!empty($row['EndDate'])) {
echo td . $row['enddate'] . /td;
} else {
exit();
}
echo td . $row['location'] . /td;
echo td . $row['summary'] . /td;
echo td . $row['description'] . /td;
echo /tr;
}

That's not the whole code, but it is the problem code. Some  
output has

the ending date set, one or two records i can't remember how many i
entered with one, most do not, i want the echo to be conditional.  
The

output stops right before the if statement, echoes startdate and
that's it, comment out the if block and it works fine.
Thanks.
Dave.

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



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




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



Karl DeSaulniers
Design Drumm
http://designdrumm.com


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



Re: [PHP] What's wrong with this code?

2010-06-05 Thread Mari Masuda
Could it be that you are not using the same variable name?  In the if statement 
you are using $row['EndDate'] and when attempting to print you are using 
$row['enddate'].  I think you need to be consistent about which capitalization 
you use (and make sure it matches what is in the db).

 if (!empty($row['EndDate'])) {
 echo td . $row['enddate'] . /td;
 }



On Jun 5, 2010, at 5:43 PM, David Mehler wrote:

 Hi,
 Thanks. I took out the entire else section including the exit call, it
 now all processes, however $row['enddate'] is not displayed on the two
 records where it is set.
 Thanks.
 Dave.
 
 
 On 6/5/10, Karl DeSaulniers k...@designdrumm.com wrote:
 Could the exit() be terminating it? Do you need this exit() as the
 else for that if statement? Try deleting just the else {}.
 
 JAT
 
 Karl
 
 Sent from losPhone
 
 On Jun 5, 2010, at 6:54 PM, David Mehler dave.meh...@gmail.com wrote:
 
 Hello,
 I've got a while loop outputting values from a database. Briefly it
 looks like this:
 
 while($row = mysql_fetch_array($result3))
 {
 echo tr;
 echo td . $row['name'] . /td;
 echo td . $row['type'] . /td;
 echo td . $row['startdate'] . /td;
 if (!empty($row['EndDate'])) {
 echo td . $row['enddate'] . /td;
 } else {
 exit();
 }
 echo td . $row['location'] . /td;
 echo td . $row['summary'] . /td;
 echo td . $row['description'] . /td;
 echo /tr;
 }
 
 That's not the whole code, but it is the problem code. Some output has
 the ending date set, one or two records i can't remember how many i
 entered with one, most do not, i want the echo to be conditional. The
 output stops right before the if statement, echoes startdate and
 that's it, comment out the if block and it works fine.
 Thanks.
 Dave.
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


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



Re: [PHP] What's wrong with this code?

2010-06-05 Thread David Mehler
Hello everyone,
Much thanks. Sometimes when you stare at code for so long it blurs
together, that's how it is with me at least. That was my problem, case
sensitive variable.
Thanks a lot.
Dave.


On 6/5/10, Mari Masuda mari.mas...@stanford.edu wrote:
 Could it be that you are not using the same variable name?  In the if
 statement you are using $row['EndDate'] and when attempting to print you are
 using $row['enddate'].  I think you need to be consistent about which
 capitalization you use (and make sure it matches what is in the db).

 if (!empty($row['EndDate'])) {
 echo td . $row['enddate'] . /td;
 }



 On Jun 5, 2010, at 5:43 PM, David Mehler wrote:

 Hi,
 Thanks. I took out the entire else section including the exit call, it
 now all processes, however $row['enddate'] is not displayed on the two
 records where it is set.
 Thanks.
 Dave.


 On 6/5/10, Karl DeSaulniers k...@designdrumm.com wrote:
 Could the exit() be terminating it? Do you need this exit() as the
 else for that if statement? Try deleting just the else {}.

 JAT

 Karl

 Sent from losPhone

 On Jun 5, 2010, at 6:54 PM, David Mehler dave.meh...@gmail.com wrote:

 Hello,
 I've got a while loop outputting values from a database. Briefly it
 looks like this:

 while($row = mysql_fetch_array($result3))
 {
 echo tr;
 echo td . $row['name'] . /td;
 echo td . $row['type'] . /td;
 echo td . $row['startdate'] . /td;
 if (!empty($row['EndDate'])) {
 echo td . $row['enddate'] . /td;
 } else {
 exit();
 }
 echo td . $row['location'] . /td;
 echo td . $row['summary'] . /td;
 echo td . $row['description'] . /td;
 echo /tr;
 }

 That's not the whole code, but it is the problem code. Some output has
 the ending date set, one or two records i can't remember how many i
 entered with one, most do not, i want the echo to be conditional. The
 output stops right before the if statement, echoes startdate and
 that's it, comment out the if block and it works fine.
 Thanks.
 Dave.

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


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



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




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



[PHP] What's wrong with this code please?

2004-02-24 Thread Donpro
$emails = array([EMAIL PROTECTED],[EMAIL PROTECTED],[EMAIL PROTECTED]);
$addresses = explode(,,$emails);
for ($i=0; $i  count($addresses); $i++) {
   echo $i . ': ' . $addresses[$i] . 'br';
   if ($i == count($addresses) - 1)
  $form['recipient'] .= $addresses[$i];
   else
  $form['recipient'] .= $addresses[$i] . ',';
   }
   echo 'Recipient = ' . $form['recipient'] . 'br';

 
The output I am receiving is:
0: Array
Recipient = Array
 
Obviously, I want to see the output of each array element as well as the
final contents of $form['recipient'].
 
Thanks in advance,
Don

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



RE: [PHP] What's wrong with this code please?

2004-02-24 Thread Sam Masiello

If you want to see the contents of an array, use the print_r function:

http://www.php.net/print_r

HTH!

--Sam



Donpro wrote:
 $emails =
 array([EMAIL PROTECTED],[EMAIL PROTECTED],[EMAIL PROTECTED]);
 $addresses = explode(,,$emails); 
 for ($i=0; $i  count($addresses); $i++) {
echo $i . ': ' . $addresses[$i] . 'br';
if ($i == count($addresses) - 1)
   $form['recipient'] .= $addresses[$i];
else
   $form['recipient'] .= $addresses[$i] . ',';
}
echo 'Recipient = ' . $form['recipient'] . 'br';
 
 
 The output I am receiving is:
 0: Array
 Recipient = Array
 
 Obviously, I want to see the output of each array element as well as
 the final contents of $form['recipient']. 
 
 Thanks in advance,
 Don

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



Re: [PHP] What's wrong with this code please?

2004-02-24 Thread Adam Bregenzer
On Tue, 2004-02-24 at 12:51, Donpro wrote:
 $emails = array([EMAIL PROTECTED],[EMAIL PROTECTED],[EMAIL PROTECTED]);
 $addresses = explode(,,$emails);
 for ($i=0; $i  count($addresses); $i++) {
echo $i . ': ' . $addresses[$i] . 'br';
if ($i == count($addresses) - 1)
   $form['recipient'] .= $addresses[$i];
else
   $form['recipient'] .= $addresses[$i] . ',';
}
echo 'Recipient = ' . $form['recipient'] . 'br';
 
  
 The output I am receiving is:
 0: Array
 Recipient = Array
  
 Obviously, I want to see the output of each array element as well as the
 final contents of $form['recipient'].

You need to look up how to use explode[1], my guess is you don't want to
use it at all here.  In fact, implode[2] may be exactly what you are
looking for.

Regards,
Adam

[1] http://www.php.net/explode
[2] http://www.php.net/implode

-- 
Adam Bregenzer
[EMAIL PROTECTED]
http://adam.bregenzer.net/

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



RE: [PHP] What's wrong with this code please?

2004-02-24 Thread Chris W. Parker
Donpro mailto:[EMAIL PROTECTED]
on Tuesday, February 24, 2004 9:52 AM said:

 $emails =
 array([EMAIL PROTECTED],[EMAIL PROTECTED],[EMAIL PROTECTED]);
 $addresses = explode(,,$emails); for ($i=0; $i  count($addresses);
$i++) { echo $i . ': ' . $addresses[$i] . 'br';
if ($i == count($addresses) - 1)
   $form['recipient'] .= $addresses[$i];
else
   $form['recipient'] .= $addresses[$i] . ',';
}
echo 'Recipient = ' . $form['recipient'] . 'br';

why are you exploding an array? $emails is already an array and can
already be accessed via index i.e. $emails[0..n];

and similar to what adam metioned, i don't even know what would happen
when you explode an array so your unexpected results are, well,
expected. ;)

$emails =
array([EMAIL PROTECTED],[EMAIL PROTECTED],[EMAIL PROTECTED]);
$emails_cnt = count($addresses);

for ($i = 0; $i  $emails_cnt; $i++)
{
  echo $i:{$emails[$i]}br;

  if ($i == ($emails_cnt - 1))
  {
$form['recipient'] .= $emails[$i];
  }
  else
  {
$form['recipient'] .= $emails[$i] . ',';
  }
}

echo Recipient = {$form['recipient']}br;


maybe that will work? (untested)


chris.

p.s. from now on don't use the count() function within loops (including
the loop declaration) because it slows things way down (when you count
the same variable over and over). instead do like what i did, count it
ahead of time and then just reference the answer.

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



[PHP] What's wrong with this code??

2003-05-31 Thread Beauford
Hi,

I have the following which gets the month and day:

$mo = date(m);
$dy = date(d);

Then I have the following IF statements which do something based on the
date..

if ($mo == 04 and $dy = 01 and $dy = 20) { $wd = 1; }
if ($mo == 04 and $dy = 21 and $dy = 27) { $wd = 2; }
if ($mo == 04 and $dy = 28 or $mo == 5 and $dy = 04) { $wd = 3; }
if ($mo == 05 and $dy = 05 and $dy = 11) { $wd = 4; }
if ($mo == 05 and $dy = 12 and $dy = 18) { $wd = 5; }
if ($mo == 05 and $dy = 19 and $dy = 25) { $wd = 6; }
if ($mo == 05 and $dy = 26 or $mo == 06 and $dy = 01) { $wd = 7; }

 Problem lines

if ($mo == 06 and $dy  01 and $dy  09) { $wd = 8; }
if ($mo == 06 and $dy  08) { $wd = 9; }

The first 7 IF statements work fine ($wd gets the right value if the
condition is met), but if I change my date to 06/02 then no matter what I
try, $wd always gets the value of 9 (it should be 8 on this date). It should
not get the value 9 until the 9th of June.

I have checked and $mo and $dy have the proper values.

Am I missing something?

TIA



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



RE: [PHP] What's wrong with this code??

2003-05-31 Thread Jennifer Goodie


  Problem lines

 if ($mo == 06 and $dy  01 and $dy  09) { $wd = 8; }
 if ($mo == 06 and $dy  08) { $wd = 9; }

but if I change my date to 06/02 then no matter what I
 try, $wd always gets the value of 9 (it should be 8 on this
 date). It should
 not get the value 9 until the 9th of June.

If the first if is true, so is the second, unless $dy == 8. In this case,
the number is 2, which is greater than 1 and less than both 8 and 9, making
both statements true.

Check your logic.


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



Re: [PHP] What's wrong with this code??

2003-05-31 Thread Ernest E Vogelsinger
At 01:08 30.04.2003, Beauford said:
[snip]
if ($mo == 06 and $dy  01 and $dy  09) { $wd = 8; }
if ($mo == 06 and $dy  08) { $wd = 9; }
[snip] 

The problem is your notation. If you had written

if ($mo == 6 and $dy  1 and $dy  9) { $wd = 8; }
if ($mo == 6 and $dy  8) { $wd = 9; }

your logic would still look a bit clumsy but work as you intend.

Why? Prefixing a number with a zero makes the intepreter believe you're
using octal numbers. Oczal numbers range from 00 to 07, the decimal number
8 would be 010 in octal notation. Your code, translated in decimal for
better understanding, is seen by the compiler as

if ($mo == 6 and $dy  1 and $dy  2) { $wd = 8; }
if ($mo == 6 and $dy  0) { $wd = 9; }

(08 = decimal 0, 09 = decimal 1). In this case your last statement will
trigger for _any_ day in June.


-- 
   O Ernest E. Vogelsinger
   (\)ICQ #13394035
^ http://www.vogelsinger.at/



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



Re: [PHP] What's wrong with this code??

2003-05-31 Thread Beauford
I figured that out after I sent the email. The reason I used the 0 in the
first place was that I was having all sorts of problems with it - and it
seemed to work fine for 01 to 05 so I just continued on with it - not even
thinking about it.

Your right though, the code is awkward - but I couldn't think of any other
way of doing it.

Any suggestions?

Thanks

- Original Message - 
From: Ernest E Vogelsinger [EMAIL PROTECTED]
To: Beauford [EMAIL PROTECTED]
Cc: PHP General [EMAIL PROTECTED]
Sent: Friday, May 30, 2003 7:39 PM
Subject: Re: [PHP] What's wrong with this code??


 At 01:08 30.04.2003, Beauford said:
 [snip]
 if ($mo == 06 and $dy  01 and $dy  09) { $wd = 8; }
 if ($mo == 06 and $dy  08) { $wd = 9; }
 [snip] 

 The problem is your notation. If you had written

 if ($mo == 6 and $dy  1 and $dy  9) { $wd = 8; }
 if ($mo == 6 and $dy  8) { $wd = 9; }

 your logic would still look a bit clumsy but work as you intend.

 Why? Prefixing a number with a zero makes the intepreter believe you're
 using octal numbers. Oczal numbers range from 00 to 07, the decimal number
 8 would be 010 in octal notation. Your code, translated in decimal for
 better understanding, is seen by the compiler as

 if ($mo == 6 and $dy  1 and $dy  2) { $wd = 8; }
 if ($mo == 6 and $dy  0) { $wd = 9; }

 (08 = decimal 0, 09 = decimal 1). In this case your last statement will
 trigger for _any_ day in June.


 -- 
O Ernest E. Vogelsinger
(\)ICQ #13394035
 ^ http://www.vogelsinger.at/



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





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



Re: [PHP] What's wrong with this code??

2003-05-31 Thread Brian V Bonini
On Fri, 2003-05-30 at 20:02, Beauford wrote:
 Your right though, the code is awkward - but I couldn't think of any other
 way of doing it.
 
 Any suggestions?
 
 
switch

http://us4.php.net/manual/en/control-structures.switch.php


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



Re: [PHP] What's wrong with this code??

2003-05-31 Thread Beauford
I find  the switch statement does not always give the desired results and
it's really not any different than using the if statement - the calculations
would still have to be the same - it's just laid out differently.

- Original Message - 
From: Brian V Bonini [EMAIL PROTECTED]
To: Beauford [EMAIL PROTECTED]
Cc: PHP General [EMAIL PROTECTED]
Sent: Friday, May 30, 2003 9:18 PM
Subject: Re: [PHP] What's wrong with this code??


 On Fri, 2003-05-30 at 20:02, Beauford wrote:
  Your right though, the code is awkward - but I couldn't think of any
other
  way of doing it.
 
  Any suggestions?
 

 switch

 http://us4.php.net/manual/en/control-structures.switch.php


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





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



Re: [PHP] What's wrong with this code?

2001-05-22 Thread Plutarck

Ahh, so you can use \\n within the regex itself...I was thinking that what
was capture in the regex itself wasn't available until the replace part.
Obviously that's not true ;)


Thanks alot, everyone! One problem down, all the other one's to go :)


Plutarck

Christian Reiniger [EMAIL PROTECTED] wrote in message
01052206314400.00595@chrisbig">news:01052206314400.00595@chrisbig...
On Tuesday 22 May 2001 05:06, Plutarck wrote:

 And now one more bit. For instance to kill an onclick event I use:

  $file = preg_replace(#(.*)onclick=\.*\(.*)#isU, \\1\\2,
 $file);

 Which works, kinda. Problem is, consider this:

 onclick='somecode()'

 It's not caught, because it only catches double quotes. How best can I
 say I want code which is between single quotes, or between double
 quotes, without it choking on something like:
 onclick='somecode(thisiswhereitwouldstop)'?

#(.*)onclick=(\|').*\\2(.*)#

A simple or combined with a backreference. And don't forget to adjust
your replacement string..

--
Christian Reiniger
LGDC Webmaster (http://sunsite.dk/lgdc/)

Software is like sex: the best is for free -- Linus Torvalds

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] What's wrong with this code?

2001-05-21 Thread Plutarck

I'm creating a filter to re-write webpages, and everything is going fine.
I'm trying to strip out anything using the SCRIPT tag, and here's what I
know works:

$file = eregi_replace(script.*.*/script, !-- RWW: Scripting
killed --, $file);

But I use PCRE functions, so I don't want to use ereg in one place and PCRE
in another, so I tried:

$file = preg_replace(#script.*.*/script#i, !-- RWW: Scripting
killed --, $file);

Thing is, that doesn't work. And I don't know why.

I assume that the brackets are what is causing the trouble, but what do
those brackets do in PCRE that requires they be escaped? But escaping them
doesn't seem to work either...

So, what's wrong with the second piece of code that isn't wrong in the
first?


Thanks in advance.

Plutarck



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] What's wrong with this code?

2001-05-21 Thread CC Zona

In article 9eb4nf$pdf$[EMAIL PROTECTED],
 [EMAIL PROTECTED] (Plutarck) wrote:

 $file = eregi_replace(script.*.*/script, !-- RWW: Scripting
 killed --, $file);
 
 But I use PCRE functions, so I don't want to use ereg in one place and PCRE
 in another, so I tried:
 
 $file = preg_replace(#script.*.*/script#i, !-- RWW: Scripting
 killed --, $file);
 
 Thing is, that doesn't work. And I don't know why.

pregs are greedy by default, while eregs are ungreedy by default.  If you 
make your preg ungreedy (using the U modifier), do you get a result more 
consisent with the ereg's?

-- 
CC

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] What's wrong with this code?

2001-05-21 Thread Rasmus Lerdorf

 But I use PCRE functions, so I don't want to use ereg in one place and PCRE
 in another, so I tried:

 $file = preg_replace(#script.*.*/script#i, !-- RWW: Scripting
 killed --, $file);

   '/script.*.*?\/script/i'

-Rasmus


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] What's wrong with this code?

2001-05-21 Thread Plutarck

Since there is a / in the code itself, I use # as a delimiter instead so
I don't have to escape it, making it harder to read.

So here's the code:

$file = preg_replace(#script.*.*/script#Ui, !-- RWW: Scripting
killed --, $file);

Which works...kinda. But here's the weird thing. This is a piece of code in
the HTML which will be replaced:

SCRIPT Language='JavaScript'
!--
function changeimage(imgNam,status) {
 if (document.images) {
  document[imgNam].src=eval(imgNam + '_' + status + '.src');
 }
}
// --
/SCRIPT
SCRIPT LANGUAGE='JavaScript'
!--
if (document.images)
{
// Preload images for onclick image change function
major1_on   = new Image();
major1_on.src   = '/nav/1-on.gif';
major1_off  = new Image();
major1_off.src  = '/nav/1-off.gif';
major1_over = new Image();
major1_over.src = '/nav/1-over.gif';
}
// --
/SCRIPT


And here's the weird part. When I run my preg code on just that piece of
code, it does absolutely nothing to it. This is the whole code I'm using to
test:

?php

$file = SCRIPT Language='JavaScript'
!--
function changeimage(imgNam,status) {
 if (document.images) {
  document[imgNam].src=eval(imgNam + '_' + status + '.src');
 }
}
// --
/SCRIPT
SCRIPT LANGUAGE='JavaScript'
!--
if (document.images)
{
// Preload images for onclick image change function
major1_on   = new Image();
major1_on.src   = '/nav/1-on.gif';
major1_off  = new Image();
major1_off.src  = '/nav/1-off.gif';
major1_over = new Image();
major1_over.src = '/nav/1-over.gif';
major2_on   = new Image();
major2_on.src   = '/nav/2-on.gif';
major2_off  = new Image();
major2_off.src  = '/nav/2-off.gif';
major2_over = new Image();
major2_over.src = '/nav/2-over.gif';
major3_on   = new Image();
major3_on.src   = '/nav/3-on.gif';
major3_off  = new Image();
major3_off.src  = '/nav/3-off.gif';
major3_over = new Image();
major3_over.src = '/nav/3-over.gif';
major4_on   = new Image();
major4_on.src   = '/nav/4-on.gif';
major4_off  = new Image();
major4_off.src  = '/nav/4-off.gif';
major4_over = new Image();
major4_over.src = '/nav/4-over.gif';
major5_on   = new Image();
major5_on.src   = '/nav/5-on.gif';
major5_off  = new Image();
major5_off.src  = '/nav/5-off.gif';
major5_over = new Image();
major5_over.src = '/nav/5-over.gif';
major6_on   = new Image();
major6_on.src   = '/nav/6-on.gif';
major6_off  = new Image();
major6_off.src  = '/nav/6-off.gif';
major6_over = new Image();
major6_over.src = '/nav/6-over.gif';
major7_on   = new Image();
major7_on.src   = '/nav/7-on.gif';
major7_off  = new Image();
major7_off.src  = '/nav/7-off.gif';
major7_over = new Image();
major7_over.src = '/nav/7-over.gif';
major8_on   = new Image();
major8_on.src   = '/nav/8-on.gif';
major8_off  = new Image();
major8_off.src  = '/nav/8-off.gif';
major8_over = new Image();
major8_over.src = '/nav/8-over.gif';
major28_on   = new Image();
major28_on.src   = '/nav/28-on.gif';
major28_off  = new Image();
major28_off.src  = '/nav/28-off.gif';
major28_over = new Image();
major28_over.src = '/nav/28-over.gif';
major29_on   = new Image();
major29_on.src   = '/nav/29-on.gif';
major29_off  = new Image();
major29_off.src  = '/nav/29-off.gif';
major29_over = new Image();
major29_over.src = '/nav/29-over.gif';
}
// --
/SCRIPT;

$file = preg_replace(#script.*.*?/script#i, !-- RWW: Scripting
killed --, $file);

echo $file;

?


Does nothin. Haven't the foggiest clue as to why, but here's what's really
making me sick. By running it on http://www.theregister.co.uk which is where
I got the code I'm trying to strip down, this is what I do in my code:

?php

$target = 'http://www.theregister.co.uk';
$fp = fopen($target, r);
$file = fread($fp, 1000);

// kill scripting
$file = preg_replace(#script.*.*?/script#i, !-- RWW: Scripting
killed --, $file);

echo $file;

?

When run it misses the first use of SCRIPT that I posted above, but it
catches the second one! And I don't know why! ;(



Plutarck

Rasmus Lerdorf [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
  But I use PCRE functions, so I don't want to use ereg in one place and
PCRE
  in another, so I tried:
 
  $file = preg_replace(#script.*.*/script#i, !-- RWW: Scripting
  killed --, $file);

'/script.*.*?\/script/i'

 -Rasmus


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] What's wrong with this code?

2001-05-21 Thread Christian Reiniger

On Monday 21 May 2001 16:23, Plutarck wrote:

 Since there is a / in the code itself, I use # as a delimiter
 instead so I don't have to escape it, making it harder to read.

 So here's the code:

 $file = preg_replace(#script.*.*/script#Ui, !-- RWW: Scripting
 killed --, $file);

Stupid error (noticed this after trying for ~10 minutes...):
Add the s modifier. Otherwise . doesn't match newlines.

-- 
Christian Reiniger
LGDC Webmaster (http://sunsite.dk/lgdc/)

Error 032: Recursion error - see error 032

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] What's wrong with this code?

2001-05-21 Thread Plutarck

Doh!

I read the part about what . does and it didn't even register that it
won't match newlines.

Well now that part works ;)

And now one more bit. For instance to kill an onclick event I use:

 $file = preg_replace(#(.*)onclick=\.*\(.*)#isU, \\1\\2, $file);

Which works, kinda. Problem is, consider this:

onclick='somecode()'

It's not caught, because it only catches double quotes. How best can I say I
want code which is between single quotes, or between double quotes, without
it choking on something like: onclick='somecode(thisiswhereitwouldstop)'?

Should I just copy the regex to another line and replace single quotes with
double quotes, thus doing two searches rather than trying to do it all at
one time?


Plutarck
Christian Reiniger [EMAIL PROTECTED] wrote in message
01052120275102.00644@chrisbig">news:01052120275102.00644@chrisbig...
On Monday 21 May 2001 16:23, Plutarck wrote:

 Since there is a / in the code itself, I use # as a delimiter
 instead so I don't have to escape it, making it harder to read.

 So here's the code:

 $file = preg_replace(#script.*.*/script#Ui, !-- RWW: Scripting
 killed --, $file);

Stupid error (noticed this after trying for ~10 minutes...):
Add the s modifier. Otherwise . doesn't match newlines.

--
Christian Reiniger
LGDC Webmaster (http://sunsite.dk/lgdc/)

Error 032: Recursion error - see error 032

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] What's wrong with this code?

2001-05-21 Thread Christian Reiniger

On Tuesday 22 May 2001 05:06, Plutarck wrote:

 And now one more bit. For instance to kill an onclick event I use:

  $file = preg_replace(#(.*)onclick=\.*\(.*)#isU, \\1\\2,
 $file);

 Which works, kinda. Problem is, consider this:

 onclick='somecode()'

 It's not caught, because it only catches double quotes. How best can I
 say I want code which is between single quotes, or between double
 quotes, without it choking on something like:
 onclick='somecode(thisiswhereitwouldstop)'?

#(.*)onclick=(\|').*\\2(.*)#

A simple or combined with a backreference. And don't forget to adjust 
your replacement string..

-- 
Christian Reiniger
LGDC Webmaster (http://sunsite.dk/lgdc/)

Software is like sex: the best is for free -- Linus Torvalds

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] What's wrong with this code?

2001-04-23 Thread Alexander Wagner

Tyler Longren wrote:
 $file = fopen(includes/about.inc, r);
 $data = fread($file, 2400);
[..]
 Any ideas why that doesn't work on one server but it will work on
 another server?  The server it works on is Win2k, IIS5, php4.0.4pl1. 
 The server it doesn't work on is Linux, Apache, php4.0.4pl1.  Any
 ideas why this won't work?  Just to be sure, I did a chmod 777
 about.inc, so file permissions isn't it.

I don't know why this wouldn't work on LAMP, but if you want to read a 
whole file you should do this:
$data = implode('',file(includes/about.inc));

regards
Wagner

-- 
In place of infinity we usually put some really big number, like 15.
 - Anonymous Computer Science professor


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] What's wrong with this code?

2001-04-23 Thread Chris Fry

I think you need to specify the full path rather than relative when using
fopen eg:

$file = fopen(/usr/local/apache/htocs/includes/about.inc, r);

Chris

Alexander Wagner wrote:

 Tyler Longren wrote:
  $file = fopen(includes/about.inc, r);
  $data = fread($file, 2400);
 [..]
  Any ideas why that doesn't work on one server but it will work on
  another server?  The server it works on is Win2k, IIS5, php4.0.4pl1.
  The server it doesn't work on is Linux, Apache, php4.0.4pl1.  Any
  ideas why this won't work?  Just to be sure, I did a chmod 777
  about.inc, so file permissions isn't it.

 I don't know why this wouldn't work on LAMP, but if you want to read a
 whole file you should do this:
 $data = implode('',file(includes/about.inc));

 regards
 Wagner

 --
 In place of infinity we usually put some really big number, like 15.
  - Anonymous Computer Science professor

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]

--
Chris Fry
Quillsoft Pty Ltd
Specialists in Secure Internet Services and E-Commerce Solutions
10 Gray Street
Kogarah
NSW  2217
Australia

Phone: +61 2 9553 1691
Fax: +61 2 9553 1692
Mobile: 0419 414 323
eMail: [EMAIL PROTECTED]
http://www.quillsoft.com.au

You can download our Public CA Certificate from:-
https://ca.secureanywhere.com/htdocs/cacert.crt

**

This information contains confidential information intended only for
the use of the authorised recipient.  If you are not an authorised
recipient of this e-mail, please contact Quillsoft Pty Ltd by return
e-mail.
In this case, you should not read, print, re-transmit, store or act
in reliance on this e-mail or any attachments, and should destroy all
copies of them.
This e-mail and any attachments may also contain copyright material
belonging to Quillsoft Pty Ltd.
The views expressed in this e-mail or attachments are the views of
the author and not the views of Quillsoft Pty Ltd.
You should only deal with the material contained in this e-mail if
you are authorised to do so.

This notice should not be removed.



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] What's wrong with this code?

2001-04-23 Thread Geir Eivind Mork

On Monday 23 April 2001 08:59, Alexander Wagner wrote:
  Tyler Longren wrote:

   $file = fopen(includes/about.inc, r);
   $data = fread($file, 2400);

$file = includes/about.inc;
if ($fp = fopen($file,r)) {
$data = fread($fp,filesize($file));
fclose($fp);
}

ought to work.

-- 
 php developer / CoreTrek AS| Beware of a tall dark man with a spoon
 Sandnes / Rogaland / Norway| up his nose. 
 web: http://www.moijk.net/ | 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] What's wrong with this code?

2001-04-22 Thread Tyler Longren

$file = fopen("includes/about.inc", "r");
$data = fread($file, 2400);
$stripped = stripslashes($data);
$formatted_data = nl2br($stripped);
echo "$formatted_data";

Any ideas why that doesn't work on one server but it will work on another
server?  The server it works on is Win2k, IIS5, php4.0.4pl1.  The server it
doesn't work on is Linux, Apache, php4.0.4pl1.  Any ideas why this won't
work?  Just to be sure, I did a chmod 777 about.inc, so file permissions
isn't it.

Thanks everyone,
Tyler Longren


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]