php-general Digest 12 Aug 2008 18:48:06 -0000 Issue 5620

2008-08-12 Thread php-general-digest-help

php-general Digest 12 Aug 2008 18:48:06 - Issue 5620

Topics (messages 277992 through 277992):

strip_tags
277992 by: Philip Thompson

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]


--
---BeginMessage---

Hi all.

If you are sanitizing _POST input for a database by escaping (via  
mysql_*), is there a reason to use strip_tags()? If so, why and could  
you provide an example?


Thanks,
~Philip

innerHTML is a string. The DOM is not a string, it's a hierarchal  
object structure. Shoving a string into an object is impure and  
similar to wrapping a spaghetti noodle around an orange and calling it  
lunch.


---End Message---


[PHP] strip_tags

2008-08-12 Thread Philip Thompson

Hi all.

If you are sanitizing _POST input for a database by escaping (via  
mysql_*), is there a reason to use strip_tags()? If so, why and could  
you provide an example?


Thanks,
~Philip

innerHTML is a string. The DOM is not a string, it's a hierarchal  
object structure. Shoving a string into an object is impure and  
similar to wrapping a spaghetti noodle around an orange and calling it  
lunch.



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



Re: [PHP] strip_tags

2008-08-12 Thread Richard Heyes
 If you are sanitizing _POST input for a database by escaping (via mysql_*),
 is there a reason to use strip_tags()? If so, why and could you provide an
 example?

Not really, as long as you're using something like
mysql_real_escape_string(). Though if you're redisplaying it to your
users (ie something like a forum) then you might want to use
strip_tags() to get rid of any HTML.

-- 
Richard Heyes
http://www.phpguru.org

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



Re: [PHP] strip_tags

2008-08-12 Thread Philip Thompson

On Aug 12, 2008, at 2:01 PM, Richard Heyes wrote:

If you are sanitizing _POST input for a database by escaping (via  
mysql_*),
is there a reason to use strip_tags()? If so, why and could you  
provide an

example?


Not really, as long as you're using something like
mysql_real_escape_string(). Though if you're redisplaying it to your
users (ie something like a forum) then you might want to use
strip_tags() to get rid of any HTML.


Actually, yes, the data is likely to be redisplayed to the users on a  
website. However, when shoving the data to the browser, I use  
htmlentities(). Is it recommended to use strip_tags() before sending  
to htmlentities()?


~Philip


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



Re: [PHP] strip_tags

2008-08-12 Thread Andrew Ballard
On Tue, Aug 12, 2008 at 2:47 PM, Philip Thompson [EMAIL PROTECTED] wrote:
 Hi all.

 If you are sanitizing _POST input for a database by escaping (via mysql_*),
 is there a reason to use strip_tags()? If so, why and could you provide an
 example?

 Thanks,
 ~Philip


The database won't care whether the content includes HTML tags. So, in
that sense, there isn't a reason.

However, there are other reasons. For one, often the contents are
rendered in a web browser and you may not want the full array of HTML
tags to appear in the generated source code either for security
reasons or for aesthetics. Another is that a lot of times HTML code
can have tag bloat. Unnecessary tags reduce the amount of actual
content you can store in a limited character column even though they
may contribute little useful formatting.

I think it's a good idea to decide exactly what HTML tags you want to
allow. Then you have a few options with what you do with tags you
don't want, such as stripping them out using strip_tags() with the
optional parameter to allow those tags, or escaping the rest of the
text with htmlspecialchars(). If you strip the tags out, it makes
sense to do this before you save the value so they only need to be
stripped out once.


Andrew

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



Re: [PHP] strip_tags

2008-08-12 Thread Richard Heyes
 Actually, yes, the data is likely to be redisplayed to the users on a
 website.

I covered that in my answer. Likely maybe; a certainty no.

 However, when shoving the data to the browser, I use
 htmlentities(). Is it recommended to use strip_tags() before sending to
 htmlentities()?

Not unless you need to strip HTML tags. Usually htmlspecialchars() is enough.

-- 
Richard Heyes
http://www.phpguru.org

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



[PHP] More math fun

2008-08-12 Thread Jay Blanchard
abs($balanceTest) = 15.22
abs($oldLineArray[16]) = 15.22

$diff = abs($balanceTest) - abs($oldLineArray[16]);
echo abs($diff) . \n;

1.7763568394E-15

WTF? This should be a big fat 0

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



Re: [PHP] More math fun

2008-08-12 Thread Robert Cummings
On Tue, 2008-08-12 at 15:18 -0500, Jay Blanchard wrote:
 abs($balanceTest) = 15.22
 abs($oldLineArray[16]) = 15.22
 
 $diff = abs($balanceTest) - abs($oldLineArray[16]);
 echo abs($diff) . \n;
 
 1.7763568394E-15
 
 WTF? This should be a big fat 0

Please provide the list with the following output:

?php

var_dump( $balanceTest );
var_dump( $oldLineArray[16] );

?

Methinks you have different data types.

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


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



RE: [PHP] More math fun

2008-08-12 Thread Jay Blanchard
[snip]
Please provide the list with the following output:

?php

var_dump( $balanceTest );
var_dump( $oldLineArray[16] );

?

Methinks you have different data types.
[/snip]

string(5) 15.22
float(15.22)

You're right*smacks forehead*. Sometimes this whole forest and trees
thing kills me.

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



RE: [PHP] More math fun

2008-08-12 Thread Jay Blanchard
[snip]
?php

var_dump( $balanceTest );
var_dump( $oldLineArray[16] );

?

Methinks you have different data types.
[/snip]

string(5) 15.22
float(15.22)

You're right*smacks forehead*. Sometimes this whole forest and trees
thing kills me.
[/snip]

settype($balanceTest, float) had no effect

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



RE: [PHP] More math fun

2008-08-12 Thread Jay Blanchard
[snip]
string(5) 15.22
float(15.22)

You're right*smacks forehead*. Sometimes this whole forest and trees
thing kills me.
[/snip]

settype($balanceTest, float) had no effect
[/snip]

$diff = round(abs($balanceTest), 2) - round(abs($oldLineArray[16]), 2);

Works? Does round convert the string to a float?

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



[PHP] Incrementing variables based on database data

2008-08-12 Thread Vinny Gullotta
below is the output I'm seeing along with my code. There are 11425 items in 
the database, many of each of these possible values for $i[4], however 
you'll see from my Output that the $iiscount variable is the only one being 
incremented and it is getting incremented for every row in the table. Can 
anyone see anything I'm doing incorrectly? The data in this column in the 
table is formatted as TEXT. Thanks in advance for any help you can provide. 
=)


11425
0
0
0
0
0
0
0


$query = SELECT * FROM table;
$result = mysql_query($query) or die(mysql_error());
$iiscount = 0;
$cfcount = 0;
$nlbcount = 0;
$srcount = 0;
$sacount = 0;
$rebootcount = 0;
$apccount = 0;
$othercount = 0;

while($i = mysql_fetch_row($result)) {
if ($i[4] = IISRESET) {
 $iiscount = $iiscount + 1;
} elseif ($i[4] = CF Restart) {
 $cfcount = $cfcount + 1;
} elseif ($i[4] = NLB STOP IISRESET) {
 $nlbcount = $nlbcount +1;
} elseif ($i[4] = Service Restart) {
 $srcount = $srcount + 1;
} elseif ($i[4] = Restart System Attendant) {
 $sacount = $sacount + 1;
} elseif ($i[4] = Reboot) {
 $rebootcount = $rebootcount + 1;
} elseif ($i[4] = APC Reboot) {
 $apccount = $apccount + 1;
} elseif ($i[4] = Other) {
 $othercount = $othercount + 1;
}
}
echo $iiscount, br;
echo $cfcount, br;
echo $nlbcount, br;
echo $srcount, br;
echo $sacount, br;
echo $rebootcount, br;
echo $apccount, br;
echo $othercount, br;
?



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



[PHP] Re: Incrementing variables based on database data

2008-08-12 Thread Vinny Gullotta
Nevermind, I figured it out. I needed to make the if statements use == 
instead of = like this:


if ($i[4] == IISRESET) {
$iiscount = $iiscount + 1;
}

etc. =)


Vinny Gullotta [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
below is the output I'm seeing along with my code. There are 11425 items 
in the database, many of each of these possible values for $i[4], however 
you'll see from my Output that the $iiscount variable is the only one 
being incremented and it is getting incremented for every row in the 
table. Can anyone see anything I'm doing incorrectly? The data in this 
column in the table is formatted as TEXT. Thanks in advance for any help 
you can provide. =)


11425
0
0
0
0
0
0
0


$query = SELECT * FROM table;
$result = mysql_query($query) or die(mysql_error());
$iiscount = 0;
$cfcount = 0;
$nlbcount = 0;
$srcount = 0;
$sacount = 0;
$rebootcount = 0;
$apccount = 0;
$othercount = 0;

while($i = mysql_fetch_row($result)) {
if ($i[4] = IISRESET) {
 $iiscount = $iiscount + 1;
} elseif ($i[4] = CF Restart) {
 $cfcount = $cfcount + 1;
} elseif ($i[4] = NLB STOP IISRESET) {
 $nlbcount = $nlbcount +1;
} elseif ($i[4] = Service Restart) {
 $srcount = $srcount + 1;
} elseif ($i[4] = Restart System Attendant) {
 $sacount = $sacount + 1;
} elseif ($i[4] = Reboot) {
 $rebootcount = $rebootcount + 1;
} elseif ($i[4] = APC Reboot) {
 $apccount = $apccount + 1;
} elseif ($i[4] = Other) {
 $othercount = $othercount + 1;
}
}
echo $iiscount, br;
echo $cfcount, br;
echo $nlbcount, br;
echo $srcount, br;
echo $sacount, br;
echo $rebootcount, br;
echo $apccount, br;
echo $othercount, br;
?




--

Vinny Gullotta
Intermedia System Administrator
E [EMAIL PROTECTED]
T (650) 641-4034
F (650) 424-9936
According to Einstein's Theory of Relativity, Chuck Norris can actually 
roundhouse kick you in the face yesterday!



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



Re: [PHP] Re: Incrementing variables based on database data

2008-08-12 Thread Micah Gersten
Why not let the DB do this for you?  You can group by whatever column
that is and select count(*), column_your_looking_for.

Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com



Vinny Gullotta wrote:
 Nevermind, I figured it out. I needed to make the if statements use ==
 instead of = like this:

 if ($i[4] == IISRESET) {
 $iiscount = $iiscount + 1;
 }

 etc. =)


 Vinny Gullotta [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
 below is the output I'm seeing along with my code. There are 11425
 items in the database, many of each of these possible values for
 $i[4], however you'll see from my Output that the $iiscount variable
 is the only one being incremented and it is getting incremented for
 every row in the table. Can anyone see anything I'm doing
 incorrectly? The data in this column in the table is formatted as
 TEXT. Thanks in advance for any help you can provide. =)

 11425
 0
 0
 0
 0
 0
 0
 0

 
 $query = SELECT * FROM table;
 $result = mysql_query($query) or die(mysql_error());
 $iiscount = 0;
 $cfcount = 0;
 $nlbcount = 0;
 $srcount = 0;
 $sacount = 0;
 $rebootcount = 0;
 $apccount = 0;
 $othercount = 0;

 while($i = mysql_fetch_row($result)) {
 if ($i[4] = IISRESET) {
  $iiscount = $iiscount + 1;
 } elseif ($i[4] = CF Restart) {
  $cfcount = $cfcount + 1;
 } elseif ($i[4] = NLB STOP IISRESET) {
  $nlbcount = $nlbcount +1;
 } elseif ($i[4] = Service Restart) {
  $srcount = $srcount + 1;
 } elseif ($i[4] = Restart System Attendant) {
  $sacount = $sacount + 1;
 } elseif ($i[4] = Reboot) {
  $rebootcount = $rebootcount + 1;
 } elseif ($i[4] = APC Reboot) {
  $apccount = $apccount + 1;
 } elseif ($i[4] = Other) {
  $othercount = $othercount + 1;
 }
 }
 echo $iiscount, br;
 echo $cfcount, br;
 echo $nlbcount, br;
 echo $srcount, br;
 echo $sacount, br;
 echo $rebootcount, br;
 echo $apccount, br;
 echo $othercount, br;
 ?




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



Re: [PHP] strip_tags

2008-08-12 Thread Philip Thompson

On Aug 12, 2008, at 2:10 PM, Andrew Ballard wrote:

On Tue, Aug 12, 2008 at 2:47 PM, Philip Thompson [EMAIL PROTECTED] 
 wrote:

Hi all.

If you are sanitizing _POST input for a database by escaping (via  
mysql_*),
is there a reason to use strip_tags()? If so, why and could you  
provide an

example?

Thanks,
~Philip



The database won't care whether the content includes HTML tags. So, in
that sense, there isn't a reason.

However, there are other reasons. For one, often the contents are
rendered in a web browser and you may not want the full array of HTML
tags to appear in the generated source code either for security
reasons or for aesthetics. Another is that a lot of times HTML code
can have tag bloat. Unnecessary tags reduce the amount of actual
content you can store in a limited character column even though they
may contribute little useful formatting.

I think it's a good idea to decide exactly what HTML tags you want to
allow. Then you have a few options with what you do with tags you
don't want, such as stripping them out using strip_tags() with the
optional parameter to allow those tags, or escaping the rest of the
text with htmlspecialchars(). If you strip the tags out, it makes
sense to do this before you save the value so they only need to be
stripped out once.


Andrew


Thanks Andrew and Richard. I have another question which I can't seem  
to find in the manual.


Will strip_tags() only strip known HTML tags or will it just strip  
anything within  and ? I have some encrypted data that may contain   
and , and I don't want strip_tags() to remove the characters in this  
encrypted string.


DÔý€û¥63ôà ×¼7

So, from this, I don't want DÔý€ removed. Obviously,  
this isn't a standard HTML tag. Thoughts?


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



Re: [PHP] Re: Incrementing variables based on database data

2008-08-12 Thread Vinny Gullotta
Well, what I need to be able to do is then take the numbers of each count 
and figure out which is used the most. We use this database to log actions 
taken on servers in our network. What my boss wants me to come up with is a 
list of which commands are issued the most, which servers get the most 
attention, and for each server, which command is issued the most, and so I 
was going to kind of do it messy-like as I'm not really 100% sure of the 
best way to do it, but my goal was to create the count variables and then 
compare them using if statements to see which one is used the most. If you 
have a way of doing this more efficiently, I'd love to hear it. I'm not the 
best programmer in the world and I'm kind of just getting back into this 
stuff, so I'm all ears for any suggestions you may have =)





Micah Gersten [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]

Why not let the DB do this for you?  You can group by whatever column
that is and select count(*), column_your_looking_for.

Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com



Vinny Gullotta wrote:

Nevermind, I figured it out. I needed to make the if statements use ==
instead of = like this:

if ($i[4] == IISRESET) {
$iiscount = $iiscount + 1;
}

etc. =)


Vinny Gullotta [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]

below is the output I'm seeing along with my code. There are 11425
items in the database, many of each of these possible values for
$i[4], however you'll see from my Output that the $iiscount variable
is the only one being incremented and it is getting incremented for
every row in the table. Can anyone see anything I'm doing
incorrectly? The data in this column in the table is formatted as
TEXT. Thanks in advance for any help you can provide. =)

11425
0
0
0
0
0
0
0


$query = SELECT * FROM table;
$result = mysql_query($query) or die(mysql_error());
$iiscount = 0;
$cfcount = 0;
$nlbcount = 0;
$srcount = 0;
$sacount = 0;
$rebootcount = 0;
$apccount = 0;
$othercount = 0;

while($i = mysql_fetch_row($result)) {
if ($i[4] = IISRESET) {
 $iiscount = $iiscount + 1;
} elseif ($i[4] = CF Restart) {
 $cfcount = $cfcount + 1;
} elseif ($i[4] = NLB STOP IISRESET) {
 $nlbcount = $nlbcount +1;
} elseif ($i[4] = Service Restart) {
 $srcount = $srcount + 1;
} elseif ($i[4] = Restart System Attendant) {
 $sacount = $sacount + 1;
} elseif ($i[4] = Reboot) {
 $rebootcount = $rebootcount + 1;
} elseif ($i[4] = APC Reboot) {
 $apccount = $apccount + 1;
} elseif ($i[4] = Other) {
 $othercount = $othercount + 1;
}
}
echo $iiscount, br;
echo $cfcount, br;
echo $nlbcount, br;
echo $srcount, br;
echo $sacount, br;
echo $rebootcount, br;
echo $apccount, br;
echo $othercount, br;
?






--

Vinny Gullotta
Intermedia System Administrator
E [EMAIL PROTECTED]
T (650) 641-4034
F (650) 424-9936
According to Einstein's Theory of Relativity, Chuck Norris can actually 
roundhouse kick you in the face yesterday!



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



Re: [PHP] strip_tags

2008-08-12 Thread Andrew Ballard
On Tue, Aug 12, 2008 at 4:53 PM, Philip Thompson [EMAIL PROTECTED] wrote:
 On Aug 12, 2008, at 2:10 PM, Andrew Ballard wrote:

 On Tue, Aug 12, 2008 at 2:47 PM, Philip Thompson [EMAIL PROTECTED]
 wrote:

 Hi all.

 If you are sanitizing _POST input for a database by escaping (via
 mysql_*),
 is there a reason to use strip_tags()? If so, why and could you provide
 an
 example?

 Thanks,
 ~Philip


 The database won't care whether the content includes HTML tags. So, in
 that sense, there isn't a reason.

 However, there are other reasons. For one, often the contents are
 rendered in a web browser and you may not want the full array of HTML
 tags to appear in the generated source code either for security
 reasons or for aesthetics. Another is that a lot of times HTML code
 can have tag bloat. Unnecessary tags reduce the amount of actual
 content you can store in a limited character column even though they
 may contribute little useful formatting.

 I think it's a good idea to decide exactly what HTML tags you want to
 allow. Then you have a few options with what you do with tags you
 don't want, such as stripping them out using strip_tags() with the
 optional parameter to allow those tags, or escaping the rest of the
 text with htmlspecialchars(). If you strip the tags out, it makes
 sense to do this before you save the value so they only need to be
 stripped out once.


 Andrew

 Thanks Andrew and Richard. I have another question which I can't seem to
 find in the manual.

 Will strip_tags() only strip known HTML tags or will it just strip anything
 within  and ? I have some encrypted data that may contain  and , and I
 don't want strip_tags() to remove the characters in this encrypted string.

 DÃý€û¥63 ôà ×¼7

 So, from this, I don't want DÃý€ removed. Obviously, this isn't a
 standard HTML tag. Thoughts?

 Thanks,
 ~Philip

Try it and see, but it looks like the answer is it depends.  I ran
your message text through strip_tags and it seems to remove the
greater-than signs when followed by non-whitespace characters, but
left them when they were surrounded by whitespace. Compare below to
your original message:

[---snip---]
Thanks Andrew and Richard. I have another question which I can't seem
to find in the manual.

Will strip_tags() only strip known HTML tags or will it just strip
anything within  and ? I have some encrypted data that may contain 
and , and I don't want strip_tags() to remove the characters in this
encrypted string.

û¥63 ôà ×¼7

So, from this, I don't want  removed. Obviously, this isn't a
standard HTML tag. Thoughts?
[---snip---]

Andrew


Re: [PHP] Re: Incrementing variables based on database data

2008-08-12 Thread Micah Gersten
Well, MySQL can aggregate the data for you so you don't have to pass it
to PHP.  It can just give you the results.  I suggest reading up on the
SELECT COUNT syntax and the GROUP BY syntax in MySQL.

Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com



Vinny Gullotta wrote:
 Well, what I need to be able to do is then take the numbers of each
 count and figure out which is used the most. We use this database to
 log actions taken on servers in our network. What my boss wants me to
 come up with is a list of which commands are issued the most, which
 servers get the most attention, and for each server, which command is
 issued the most, and so I was going to kind of do it messy-like as I'm
 not really 100% sure of the best way to do it, but my goal was to
 create the count variables and then compare them using if statements
 to see which one is used the most. If you have a way of doing this
 more efficiently, I'd love to hear it. I'm not the best programmer in
 the world and I'm kind of just getting back into this stuff, so I'm
 all ears for any suggestions you may have =)




 Micah Gersten [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
 Why not let the DB do this for you?  You can group by whatever column
 that is and select count(*), column_your_looking_for.

 Thank you,
 Micah Gersten
 onShore Networks
 Internal Developer
 http://www.onshore.com



 Vinny Gullotta wrote:
 Nevermind, I figured it out. I needed to make the if statements use ==
 instead of = like this:

 if ($i[4] == IISRESET) {
 $iiscount = $iiscount + 1;
 }

 etc. =)


 Vinny Gullotta [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
 below is the output I'm seeing along with my code. There are 11425
 items in the database, many of each of these possible values for
 $i[4], however you'll see from my Output that the $iiscount variable
 is the only one being incremented and it is getting incremented for
 every row in the table. Can anyone see anything I'm doing
 incorrectly? The data in this column in the table is formatted as
 TEXT. Thanks in advance for any help you can provide. =)

 11425
 0
 0
 0
 0
 0
 0
 0

 
 $query = SELECT * FROM table;
 $result = mysql_query($query) or die(mysql_error());
 $iiscount = 0;
 $cfcount = 0;
 $nlbcount = 0;
 $srcount = 0;
 $sacount = 0;
 $rebootcount = 0;
 $apccount = 0;
 $othercount = 0;

 while($i = mysql_fetch_row($result)) {
 if ($i[4] = IISRESET) {
  $iiscount = $iiscount + 1;
 } elseif ($i[4] = CF Restart) {
  $cfcount = $cfcount + 1;
 } elseif ($i[4] = NLB STOP IISRESET) {
  $nlbcount = $nlbcount +1;
 } elseif ($i[4] = Service Restart) {
  $srcount = $srcount + 1;
 } elseif ($i[4] = Restart System Attendant) {
  $sacount = $sacount + 1;
 } elseif ($i[4] = Reboot) {
  $rebootcount = $rebootcount + 1;
 } elseif ($i[4] = APC Reboot) {
  $apccount = $apccount + 1;
 } elseif ($i[4] = Other) {
  $othercount = $othercount + 1;
 }
 }
 echo $iiscount, br;
 echo $cfcount, br;
 echo $nlbcount, br;
 echo $srcount, br;
 echo $sacount, br;
 echo $rebootcount, br;
 echo $apccount, br;
 echo $othercount, br;
 ?





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



[PHP] If Column Exists

2008-08-12 Thread VamVan
Hello,

I am working on data migration for one mysql db to another using PHP. How do
I check if a particular table has a particular column. If not alter...

Thanks


Re: [PHP] strip_tags

2008-08-12 Thread Philip Thompson

On Aug 12, 2008, at 4:11 PM, Andrew Ballard wrote:

On Tue, Aug 12, 2008 at 4:53 PM, Philip Thompson [EMAIL PROTECTED] 
 wrote:

On Aug 12, 2008, at 2:10 PM, Andrew Ballard wrote:

On Tue, Aug 12, 2008 at 2:47 PM, Philip Thompson [EMAIL PROTECTED] 


wrote:


Hi all.

If you are sanitizing _POST input for a database by escaping (via
mysql_*),
is there a reason to use strip_tags()? If so, why and could you  
provide

an
example?

Thanks,
~Philip



The database won't care whether the content includes HTML tags.  
So, in

that sense, there isn't a reason.

However, there are other reasons. For one, often the contents are
rendered in a web browser and you may not want the full array of  
HTML

tags to appear in the generated source code either for security
reasons or for aesthetics. Another is that a lot of times HTML code
can have tag bloat. Unnecessary tags reduce the amount of actual
content you can store in a limited character column even though they
may contribute little useful formatting.

I think it's a good idea to decide exactly what HTML tags you want  
to

allow. Then you have a few options with what you do with tags you
don't want, such as stripping them out using strip_tags() with the
optional parameter to allow those tags, or escaping the rest of the
text with htmlspecialchars(). If you strip the tags out, it makes
sense to do this before you save the value so they only need to be
stripped out once.


Andrew


Thanks Andrew and Richard. I have another question which I can't  
seem to

find in the manual.

Will strip_tags() only strip known HTML tags or will it just strip  
anything
within  and ? I have some encrypted data that may contain  and  
, and I
don't want strip_tags() to remove the characters in this encrypted  
string.


DÃý€û¥63 ôà ×¼7

So, from this, I don't want DÃý€ removed. Obviously, this  
isn't a

standard HTML tag. Thoughts?

Thanks,
~Philip


Try it and see, but it looks like the answer is it depends.  I ran
your message text through strip_tags and it seems to remove the
greater-than signs when followed by non-whitespace characters, but
left them when they were surrounded by whitespace. Compare below to
your original message:

[---snip---]
Thanks Andrew and Richard. I have another question which I can't seem
to find in the manual.

Will strip_tags() only strip known HTML tags or will it just strip
anything within  and ? I have some encrypted data that may contain 
and , and I don't want strip_tags() to remove the characters in this
encrypted string.

û¥63 ôà ×¼7

So, from this, I don't want  removed. Obviously, this isn't a
standard HTML tag. Thoughts?
[---snip---]

Andrew


I did a similar test:

?php
$strs = array(
DÃý€û¥63 ôà ×¼7,
DÃý€û¥63 ôà ×¼7,
 DÃý€ û¥63 ôà ×¼7,
pHow are you doing?/p,
);

echo pre\nstr:\n;
foreach ($strs as $i = $str) {
echo $i = . htmlentities ($str) . \n;
}
echo \nstripped:\n;
foreach ($strs as $i = $str) {
echo $i = . htmlentities (strip_tags($str)) . \n;
}
echo /pre\n;
?

The output from this was:

str:
0 = DÃý€û¥63 ôà ×¼7
1 = DÃý€û¥63 ôà ×¼7
2 =  DÃý€ û¥63 ôà ×¼7
3 = pHow are you doing?/p

stripped:
0 = û¥63 ôà ×¼7
1 =
2 =  DÃý€ û¥63 ôà ×¼7
3 = How are you doing?



Notice how stripped[1] is empty. This occurred when I removed the  
closing . I find this to be a bit odd. Oh well. Maybe a bug or feature?


Nonetheless, I test if it is an encrypted string, then don't call  
strip_tags() on it. Otherwise, do. This seems like it will work well.


Thanks for the input!

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



RE: [PHP] If Column Exists

2008-08-12 Thread Jay Blanchard
[snip]
I am working on data migration for one mysql db to another using PHP.
How do
I check if a particular table has a particular column. If not alter...
[/snip]

Use DESCRIBE TABLE;

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



Re: [PHP] More math fun

2008-08-12 Thread Jim Lucas

Jay Blanchard wrote:

abs($balanceTest) = 15.22
abs($oldLineArray[16]) = 15.22

$diff = abs($balanceTest) - abs($oldLineArray[16]);
echo abs($diff) . \n;

1.7763568394E-15

WTF? This should be a big fat 0



I do not see how it makes any difference if $balanceTest and $oldLineArray[16] 
are strings in the beginning.  In line that does the subtraction, they would 
have been converted to floats automagically by abs().  If you look at the 
manual for this function, you will see that the returned value is either a 
float or integer bases on the input type.  Float would return a float. 
Anything else would return a integer.


BTW - if I setup the following:

?php

$balanceTest = '15.22';  # A string
$oldLineArray[16] = 15.22; # A float

$diff = abs($balanceTest) - abs($oldLineArray[16]);
echo abs($diff) . \n;
echo gettype(abs($diff)) . \n;

# 1.7763568394E-15

?

I get 0 and 'double'

--
Jim Lucas

   Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them.

Twelfth Night, Act II, Scene V
by William Shakespeare


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



[PHP] Re: Incrementing variables based on database data

2008-08-12 Thread Jon Drukman

Vinny Gullotta wrote:
Well, what I need to be able to do is then take the numbers of each 
count and figure out which is used the most. We use this database to log 
actions taken on servers in our network. What my boss wants me to come 
up with is a list of which commands are issued the most, which servers 
get the most attention, and for each server, which command is issued the 
most, and so I was going to kind of do it messy-like as I'm not really 
100% sure of the best way to do it, but my goal was to create the count 
variables and then compare them using if statements to see which one is 
used the most. If you have a way of doing this more efficiently, I'd 
love to hear it. I'm not the best programmer in the world and I'm kind 
of just getting back into this stuff, so I'm all ears for any 
suggestions you may have =)


you can do it with one sql query.  i don't know the real names of your 
columns so i'm just going to make some up.


select message_type, count(1) x from table group by message_type order 
by x desc


you can do the same thing for machines - just change message_type to 
machine_name.


-jsd-


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



[PHP] A dumb question regarding sending email

2008-08-12 Thread tedd

Hi gang:

I wish I had another identify for asking dumb questions, but it's 
late and I'm tried -- so here goes.


I have a herdoc that I send out as an email -- no problems there.

However, how do I include a link within it?

If I use http://example.com, it's just a string but not an actual link.

So, how do you format a link in a heredoc?

Thanks,

tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



[PHP] Re: A dumb question regarding sending email

2008-08-12 Thread Ross McKay
On Tue, 12 Aug 2008 22:07:41 -0400, tedd sperling wrote:

I have a herdoc that I send out as an email -- no problems there.

However, how do I include a link within it?

If I use http://example.com, it's just a string but not an actual link.

So, how do you format a link in a heredoc?

a) most email programs will detect that plain-text URL and turn it into
a link when displaying the email, so... maybe you don't want to bother!

b) send the email with an HTML body (either instead of or in addition to
the plain-text body), and use the standard 
a href='http://example.com/'http://example.com//a
in the HTML body. You'll need to catch the heredoc as a string, and
replace any URLs with the anchored URL as above.
-- 
Ross McKay, Toronto, NSW Australia
Before enlightenment: chop wood, carry water;
 After enlightenment: chop wood, carry water - Wu Li

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



Re: [PHP] A dumb question regarding sending email

2008-08-12 Thread Chris

tedd wrote:

Hi gang:

I wish I had another identify for asking dumb questions, but it's late 
and I'm tried -- so here goes.


I have a herdoc that I send out as an email -- no problems there.

However, how do I include a link within it?

If I use http://example.com, it's just a string but not an actual link.


Your mail client determines that.

You sent that email as text-only and thunderbird turned it into a link 
for me.


If you're trying to send an a href.. link, you need to send it as a 
full html email (which means setting proper email headers etc).. for 
that I'd suggest using one of the libraries to do it all for you 
(phpmailer, swiftmail or whatever it is, zend_mailer)...


--
Postgresql  php tutorials
http://www.designmagick.com/


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



Re: [PHP] More math fun

2008-08-12 Thread Robert Cummings
On Tue, 2008-08-12 at 14:59 -0700, Jim Lucas wrote:
 Jay Blanchard wrote:
  abs($balanceTest) = 15.22
  abs($oldLineArray[16]) = 15.22
  
  $diff = abs($balanceTest) - abs($oldLineArray[16]);
  echo abs($diff) . \n;
  
  1.7763568394E-15
  
  WTF? This should be a big fat 0
  
 
 I do not see how it makes any difference if $balanceTest and 
 $oldLineArray[16] 
 are strings in the beginning.  In line that does the subtraction, they would 
 have been converted to floats automagically by abs().  If you look at the 
 manual for this function, you will see that the returned value is either a 
 float or integer bases on the input type.  Float would return a float. 
 Anything else would return a integer.
 
 BTW - if I setup the following:
 
 ?php
 
 $balanceTest = '15.22';  # A string
 $oldLineArray[16] = 15.22; # A float
 
 $diff = abs($balanceTest) - abs($oldLineArray[16]);
 echo abs($diff) . \n;
 echo gettype(abs($diff)) . \n;
 
 # 1.7763568394E-15
 
 ?
 
 I get 0 and 'double'

Yeah, I was probably thinking abs( $balanceTest - $oldLineArray[16] )
versus what was actually present. But either way, I get 0 doing the
above also when I set up the values... so I have no idea how it's not
working for Jay.

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


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



Re: [PHP] More math fun

2008-08-12 Thread Micah Gersten
Robert, when you do yours, it's performing the same function on two
different variable types and has to do a conversion before the function
works.  He was doing a numeric function on a string which might be
giving the funky results.

Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com



Robert Cummings wrote:
 On Tue, 2008-08-12 at 14:59 -0700, Jim Lucas wrote:
   
 Jay Blanchard wrote:
 
 abs($balanceTest) = 15.22
 abs($oldLineArray[16]) = 15.22

 $diff = abs($balanceTest) - abs($oldLineArray[16]);
 echo abs($diff) . \n;

 1.7763568394E-15

 WTF? This should be a big fat 0

   
 I do not see how it makes any difference if $balanceTest and 
 $oldLineArray[16] 
 are strings in the beginning.  In line that does the subtraction, they would 
 have been converted to floats automagically by abs().  If you look at the 
 manual for this function, you will see that the returned value is either a 
 float or integer bases on the input type.  Float would return a float. 
 Anything else would return a integer.

 BTW - if I setup the following:

 ?php

 $balanceTest = '15.22';  # A string
 $oldLineArray[16] = 15.22; # A float

 $diff = abs($balanceTest) - abs($oldLineArray[16]);
 echo abs($diff) . \n;
 echo gettype(abs($diff)) . \n;

 # 1.7763568394E-15

 ?

 I get 0 and 'double'
 

 Yeah, I was probably thinking abs( $balanceTest - $oldLineArray[16] )
 versus what was actually present. But either way, I get 0 doing the
 above also when I set up the values... so I have no idea how it's not
 working for Jay.

 Cheers,
 Rob.
   

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



Re: [PHP] More math fun

2008-08-12 Thread Robert Cummings
On Tue, 2008-08-12 at 23:23 -0500, Micah Gersten wrote:
 Robert, when you do yours, it's performing the same function on two
 different variable types and has to do a conversion before the function
 works.  He was doing a numeric function on a string which might be
 giving the funky results.

That's what Jim tried and got 0 and double... I confirmed Jim's results
(I didn't originally test Jay's problem) and then tried the alternative
that I might have thought this morning. Either way, it seems to come up
as 0. Maybe Jay is running a buggy version of PHP.

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


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