php-general Digest 22 Jun 2010 14:22:54 -0000 Issue 6810

2010-06-22 Thread php-general-digest-help

php-general Digest 22 Jun 2010 14:22:54 - Issue 6810

Topics (messages 306302 through 306303):

Re: Website content question
306302 by: Ernie Kemp

Warning messages on web page.
306303 by: Mike Davies

Administrivia:

To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
php-gene...@lists.php.net


--
---BeginMessage---
I did put the PHP code. It kind of working.

 

From: ahlin.h...@gmail.com [mailto:ahlin.h...@gmail.com] On Behalf Of Hans Åhlin
Sent: June-21-10 9:43 PM
To: Ernie Kemp
Cc: PHP General List
Subject: Re: [PHP] Website content question

 

Did you include the necessary php code?


**
Hans Åhlin
  Tel: +46761488019
  icq: 275232967
  http://www.kronan-net.com/
  irc://irc.freenode.net:6667 - TheCoin
**



2010/6/21 Ernie Kemp ernie.k...@sympatico.ca

Error! Filename not specified.

This is not a direct PHP question but I will be using PHP in the website.

 

I go to the php list because the wordpress forum does not respond to my 
questions and I know some of you have a lot of expertise in other areas than 
PHP.

 

I wish to a my own pages to a theme.

I created pages on my PC and added the code at the top of the page for 
wordpress to use the page for a template page.

I than FTP’d the file over to web hosting server template location.

Through  wordpress “administrator” I added my file called homepage.php.

 

I FTP’d my CSS, images, js and flash folders over to the template location.

Went to load the website 
http://localhost/Michael-8701/site_flash/wordpress/wp-content/homepage.php and 
all I got was the html code displayed.

 

I tried moving the folder around but same results.

Read some docs on this but it’s not clear to me why this will not work.

 

Please help this is new to me and I need to get over this wall.

Thanks,

/Ernie

 

 

 

 

 

 

 

No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 9.0.829 / Virus Database: 271.1.1/2952 - Release Date: 06/21/10 
14:36:00

---End Message---
---BeginMessage---
Hello,

This is my first post to this list and I am a novice at php coding. I
can generally follow the code but not good at writing from scratch.


I have recently been trying to add to a website which was originally
developed by someone else and is written in php and mysql. I am trying
to add a 'news' section to the site. This would be similar to an
existing 'projects' section so, rather than write it completely from
scratch I copied the php and the database tables from the 'project'
section and renamed 'project' to 'news'.


This is working well except for one thing – I get the following error
messages when looking at the detailed news item. This code does not
produce this warning in the project section which is using the same php
code


Warning: reset() [function.reset]: Passed variable is not an array or
object in /home/b23aadf/public_html/news/details.php on line 72

Warning: Variable passed to each() is not an array or object
in /home/b23aadf/public_html/news/details.php on line 73


The relevant lines are :


72 reset($thumbsarray);

73 while (list($key, $value) = each($thumbsarray)) {

The site is at www.aadf.co.uk and select 'News'.

Is anyone able to help resolve this? If you let me know what further
information you require I can provide it.


Mike Davies

-- 
Mike Davies
Integra Web Design, Rhynie, By Huntly, AB54 4LS
01464 861535www.integrawebdesign.co.uk

---End Message---


php-general Digest 23 Jun 2010 03:59:06 -0000 Issue 6811

2010-06-22 Thread php-general-digest-help

php-general Digest 23 Jun 2010 03:59:06 - Issue 6811

Topics (messages 306304 through 306325):

Re: Warning messages on web page.
306304 by: Jim Lucas
306305 by: Shreyas Agasthya
306306 by: Daniel P. Brown
306307 by: Paul M Foster

Stripping Characters
306308 by: Rick Dwyer
306309 by: David Èesal
306310 by: Ashley Sheridan
306311 by: Shreyas Agasthya
306312 by: Richard Quadling
306313 by: Nathan Nobbe
306314 by: Richard Quadling
306315 by: Shreyas Agasthya
306316 by: Rick Dwyer
306317 by: Ashley Sheridan
306318 by: Jim Lucas
306319 by: Rick Dwyer
306322 by: Rick Dwyer
306323 by: Ashley Sheridan
306324 by: Rick Dwyer

Question about logins and locking
306320 by: James Colannino
306321 by: Tommy Pham

In what scenario an extension of a class is useful?
306325 by: Camilo Sperberg

Administrivia:

To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
php-gene...@lists.php.net


--
---BeginMessage---
Mike Davies wrote:
 Hello,
 
 This is my first post to this list and I am a novice at php coding. I
 can generally follow the code but not good at writing from scratch.
 
 
 I have recently been trying to add to a website which was originally
 developed by someone else and is written in php and mysql. I am trying
 to add a 'news' section to the site. This would be similar to an
 existing 'projects' section so, rather than write it completely from
 scratch I copied the php and the database tables from the 'project'
 section and renamed 'project' to 'news'.
 
 
 This is working well except for one thing – I get the following error
 messages when looking at the detailed news item. This code does not
 produce this warning in the project section which is using the same php
 code
 
 
 Warning: reset() [function.reset]: Passed variable is not an array or
 object in /home/b23aadf/public_html/news/details.php on line 72
 
 Warning: Variable passed to each() is not an array or object
 in /home/b23aadf/public_html/news/details.php on line 73
 
 
 The relevant lines are :
 

put a var_dump($thumbarray); right here and see what $thumbarray is

 
 72 reset($thumbsarray);
 
 73 while (list($key, $value) = each($thumbsarray)) {
 
 The site is at www.aadf.co.uk and select 'News'.
 
 Is anyone able to help resolve this? If you let me know what further
 information you require I can provide it.
 
 
 Mike Davies
 


-- 
Jim Lucas

A: Maybe because some people are too annoyed by top-posting.
Q: Why do I not get an answer to my question(s)?
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
---End Message---
---BeginMessage---
Mike,

A couple of things that I could understand reading carefully at the error.

1. reset takes an array as the input and perhaps your $thumbsarray is *not *an
array? Reset will set the internal pointer to the start of the array.

2. Warning # 2 is very closely related to #1 since you can iterate on an
array and not on a variable.

3. Just FYI - You can control the behavior should or not these
warnings/notices/errors in your php.ini file. Do a quick google and you
should be happy to see the result.

Regards,
Shreyas

On Tue, Jun 22, 2010 at 7:47 PM, Mike Davies m...@integrawebdesign.co.ukwrote:

 Hello,

 This is my first post to this list and I am a novice at php coding. I
 can generally follow the code but not good at writing from scratch.


 I have recently been trying to add to a website which was originally
 developed by someone else and is written in php and mysql. I am trying
 to add a 'news' section to the site. This would be similar to an
 existing 'projects' section so, rather than write it completely from
 scratch I copied the php and the database tables from the 'project'
 section and renamed 'project' to 'news'.


 This is working well except for one thing – I get the following error
 messages when looking at the detailed news item. This code does not
 produce this warning in the project section which is using the same php
 code


 Warning: reset() [function.reset]: Passed variable is not an array or
 object in /home/b23aadf/public_html/news/details.php on line 72

 Warning: Variable passed to each() is not an array or object
 in /home/b23aadf/public_html/news/details.php on line 73


 The relevant lines are :


 72 reset($thumbsarray);

 73 while (list($key, $value) = each($thumbsarray)) {

 The site is at www.aadf.co.uk and select 'News'.

 Is anyone able to help resolve this? If you let me know what further
 information you require I can provide it.


 Mike Davies

 --
 Mike Davies
 Integra Web Design, Rhynie, By Huntly, AB54 4LS
 

[PHP] Warning messages on web page.

2010-06-22 Thread Mike Davies
Hello,

This is my first post to this list and I am a novice at php coding. I
can generally follow the code but not good at writing from scratch.


I have recently been trying to add to a website which was originally
developed by someone else and is written in php and mysql. I am trying
to add a 'news' section to the site. This would be similar to an
existing 'projects' section so, rather than write it completely from
scratch I copied the php and the database tables from the 'project'
section and renamed 'project' to 'news'.


This is working well except for one thing – I get the following error
messages when looking at the detailed news item. This code does not
produce this warning in the project section which is using the same php
code


Warning: reset() [function.reset]: Passed variable is not an array or
object in /home/b23aadf/public_html/news/details.php on line 72

Warning: Variable passed to each() is not an array or object
in /home/b23aadf/public_html/news/details.php on line 73


The relevant lines are :


72 reset($thumbsarray);

73 while (list($key, $value) = each($thumbsarray)) {

The site is at www.aadf.co.uk and select 'News'.

Is anyone able to help resolve this? If you let me know what further
information you require I can provide it.


Mike Davies

-- 
Mike Davies
Integra Web Design, Rhynie, By Huntly, AB54 4LS
01464 861535www.integrawebdesign.co.uk


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



Re: [PHP] Warning messages on web page.

2010-06-22 Thread Jim Lucas
Mike Davies wrote:
 Hello,
 
 This is my first post to this list and I am a novice at php coding. I
 can generally follow the code but not good at writing from scratch.
 
 
 I have recently been trying to add to a website which was originally
 developed by someone else and is written in php and mysql. I am trying
 to add a 'news' section to the site. This would be similar to an
 existing 'projects' section so, rather than write it completely from
 scratch I copied the php and the database tables from the 'project'
 section and renamed 'project' to 'news'.
 
 
 This is working well except for one thing – I get the following error
 messages when looking at the detailed news item. This code does not
 produce this warning in the project section which is using the same php
 code
 
 
 Warning: reset() [function.reset]: Passed variable is not an array or
 object in /home/b23aadf/public_html/news/details.php on line 72
 
 Warning: Variable passed to each() is not an array or object
 in /home/b23aadf/public_html/news/details.php on line 73
 
 
 The relevant lines are :
 

put a var_dump($thumbarray); right here and see what $thumbarray is

 
 72 reset($thumbsarray);
 
 73 while (list($key, $value) = each($thumbsarray)) {
 
 The site is at www.aadf.co.uk and select 'News'.
 
 Is anyone able to help resolve this? If you let me know what further
 information you require I can provide it.
 
 
 Mike Davies
 


-- 
Jim Lucas

A: Maybe because some people are too annoyed by top-posting.
Q: Why do I not get an answer to my question(s)?
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?

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



Re: [PHP] Warning messages on web page.

2010-06-22 Thread Shreyas Agasthya
Mike,

A couple of things that I could understand reading carefully at the error.

1. reset takes an array as the input and perhaps your $thumbsarray is *not *an
array? Reset will set the internal pointer to the start of the array.

2. Warning # 2 is very closely related to #1 since you can iterate on an
array and not on a variable.

3. Just FYI - You can control the behavior should or not these
warnings/notices/errors in your php.ini file. Do a quick google and you
should be happy to see the result.

Regards,
Shreyas

On Tue, Jun 22, 2010 at 7:47 PM, Mike Davies m...@integrawebdesign.co.ukwrote:

 Hello,

 This is my first post to this list and I am a novice at php coding. I
 can generally follow the code but not good at writing from scratch.


 I have recently been trying to add to a website which was originally
 developed by someone else and is written in php and mysql. I am trying
 to add a 'news' section to the site. This would be similar to an
 existing 'projects' section so, rather than write it completely from
 scratch I copied the php and the database tables from the 'project'
 section and renamed 'project' to 'news'.


 This is working well except for one thing – I get the following error
 messages when looking at the detailed news item. This code does not
 produce this warning in the project section which is using the same php
 code


 Warning: reset() [function.reset]: Passed variable is not an array or
 object in /home/b23aadf/public_html/news/details.php on line 72

 Warning: Variable passed to each() is not an array or object
 in /home/b23aadf/public_html/news/details.php on line 73


 The relevant lines are :


 72 reset($thumbsarray);

 73 while (list($key, $value) = each($thumbsarray)) {

 The site is at www.aadf.co.uk and select 'News'.

 Is anyone able to help resolve this? If you let me know what further
 information you require I can provide it.


 Mike Davies

 --
 Mike Davies
 Integra Web Design, Rhynie, By Huntly, AB54 4LS
 01464 861535www.integrawebdesign.co.uk


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




-- 
Regards,
Shreyas Agasthya


Re: [PHP] Warning messages on web page.

2010-06-22 Thread Daniel P. Brown
On Tue, Jun 22, 2010 at 10:17, Mike Davies m...@integrawebdesign.co.uk wrote:
[snip!]

 Warning: reset() [function.reset]: Passed variable is not an array or
 object in /home/b23aadf/public_html/news/details.php on line 72
[snip!]

 Is anyone able to help resolve this? If you let me know what further
 information you require I can provide it.

Note the first error (quoted herein).  That tells you that the
variable ($thumbsarray) is not actually an array.  How is it being
instantiated and defined?

-- 
/Daniel P. Brown
UNADVERTISED DEDICATED SERVER SPECIALS
SAME-DAY SETUP
Just ask me what we're offering today!
daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/

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



Re: [PHP] Warning messages on web page.

2010-06-22 Thread Paul M Foster
On Tue, Jun 22, 2010 at 03:17:53PM +0100, Mike Davies wrote:

 Hello,
 
 This is my first post to this list and I am a novice at php coding. I
 can generally follow the code but not good at writing from scratch.
 
 
 I have recently been trying to add to a website which was originally
 developed by someone else and is written in php and mysql. I am trying
 to add a 'news' section to the site. This would be similar to an
 existing 'projects' section so, rather than write it completely from
 scratch I copied the php and the database tables from the 'project'
 section and renamed 'project' to 'news'.
 
 
 This is working well except for one thing – I get the following error
 messages when looking at the detailed news item. This code does not
 produce this warning in the project section which is using the same php
 code
 
 
 Warning: reset() [function.reset]: Passed variable is not an array or
 object in /home/b23aadf/public_html/news/details.php on line 72
 
 Warning: Variable passed to each() is not an array or object
 in /home/b23aadf/public_html/news/details.php on line 73
 
 
 The relevant lines are :
 
 
 72 reset($thumbsarray);
 
 73 while (list($key, $value) = each($thumbsarray)) {
 
 The site is at www.aadf.co.uk and select 'News'.
 
 Is anyone able to help resolve this? If you let me know what further
 information you require I can provide it.

Well formed question. Thanks for that. I see too many which aren't.

I can't say why it's happening, but the $thumbsarray variable isn't
getting built the way it should. You can insert a line just before your
errors pop up like:

?php echo '$thumbsarray: '; print_r($thumbsarray); ?

or

?php echo '$thumbsarray: '; echo var_dump($thumbsarray); ?

or something similar. This will tell you if the variable is set and what
type it has. I'm guessing it's not set. You'll have to look earlier to
see where it should be built and isn't.

Paul

-- 
Paul M. Foster

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



[PHP] Stripping Characters

2010-06-22 Thread Rick Dwyer

Hello List.

I need to remove characters from a string and replace them with and  
underscore.


So instead of having something like:

$moditem = str_replace(--,_,$mystring);
$moditem = str_replace(?,_,$mystring);
$moditem = str_replace(!,_,$mystring);
etc.

For every possible character I can think of, is there a way to simply  
omit any character that is not an alpha character and not a number  
value from 0 to 9?



 --Rick



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



RE: [PHP] Stripping Characters

2010-06-22 Thread David Česal
Hello,
can this resolve your problem?

$trans = array(
from = to,
another = to);

$moditem = StrTr($moditem, $trans);

-- http://cz.php.net/manual/en/function.strtr.php

David

-Original Message-
From: Rick Dwyer [mailto:rpdw...@earthlink.net] 
Sent: Tuesday, June 22, 2010 5:41 PM
To: php-general@lists.php.net
Subject: [PHP] Stripping Characters

Hello List.

I need to remove characters from a string and replace them with and
underscore.

So instead of having something like:

$moditem = str_replace(--,_,$mystring);
$moditem = str_replace(?,_,$mystring); $moditem =
str_replace(!,_,$mystring); etc.

For every possible character I can think of, is there a way to simply omit
any character that is not an alpha character and not a number value from 0
to 9?


  --Rick



--
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] Stripping Characters

2010-06-22 Thread Ashley Sheridan
On Tue, 2010-06-22 at 11:40 -0400, Rick Dwyer wrote:

 Hello List.
 
 I need to remove characters from a string and replace them with and  
 underscore.
 
 So instead of having something like:
 
 $moditem = str_replace(--,_,$mystring);
 $moditem = str_replace(?,_,$mystring);
 $moditem = str_replace(!,_,$mystring);
 etc.
 
 For every possible character I can think of, is there a way to simply  
 omit any character that is not an alpha character and not a number  
 value from 0 to 9?
 
 
   --Rick
 
 
 


Use preg_replace(), which allows you to use a regex to specify what you
want to match:

$find = '/[^a-z0-9]/i';
$replace = '_';
$new_string = preg_replace($find, $replace, $old_string);

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] Stripping Characters

2010-06-22 Thread Shreyas Agasthya
Perhaps, ereg_replace(your regex, replacement_string, String
$variable).

Regards,
Shreyas

On Tue, Jun 22, 2010 at 9:10 PM, Rick Dwyer rpdw...@earthlink.net wrote:

 Hello List.

 I need to remove characters from a string and replace them with and
 underscore.

 So instead of having something like:

 $moditem = str_replace(--,_,$mystring);
 $moditem = str_replace(?,_,$mystring);
 $moditem = str_replace(!,_,$mystring);
 etc.

 For every possible character I can think of, is there a way to simply omit
 any character that is not an alpha character and not a number value from 0
 to 9?


  --Rick



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




-- 
Regards,
Shreyas Agasthya


Re: [PHP] Stripping Characters

2010-06-22 Thread Richard Quadling
On 22 June 2010 16:44, Ashley Sheridan a...@ashleysheridan.co.uk wrote:
 On Tue, 2010-06-22 at 11:40 -0400, Rick Dwyer wrote:

 Hello List.

 I need to remove characters from a string and replace them with and
 underscore.

 So instead of having something like:

 $moditem = str_replace(--,_,$mystring);
 $moditem = str_replace(?,_,$mystring);
 $moditem = str_replace(!,_,$mystring);
 etc.

 For every possible character I can think of, is there a way to simply
 omit any character that is not an alpha character and not a number
 value from 0 to 9?


   --Rick





 Use preg_replace(), which allows you to use a regex to specify what you
 want to match:

 $find = '/[^a-z0-9]/i';
 $replace = '_';
 $new_string = preg_replace($find, $replace, $old_string);

 Thanks,
 Ash
 http://www.ashleysheridan.co.uk




Watch out for white space in there. Tabs, spaces, new lines, etc. will
also be converted to underscore.

$find = '/[^\w\s]/i';

[^\w\s]

Match a single character NOT present in the list below «[^\w\s]»
   A word character (letters, digits, and underscores) «\w»
   A whitespace character (spaces, tabs, and line breaks) «\s»


A word character is any letter or digit or the underscore
character, that is, any character which can be part of a Perl word.
The definition of letters and digits is controlled by PCRE's character
tables, and may vary if locale-specific matching is taking place. For
example, in the fr (French) locale, some character codes greater
than 128 are used for accented letters, and these are matched by \w.

-- 
-
Richard Quadling
Standing on the shoulders of some very clever giants!
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

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



Re: [PHP] Stripping Characters

2010-06-22 Thread Nathan Nobbe
On Tue, Jun 22, 2010 at 9:40 AM, Rick Dwyer rpdw...@earthlink.net wrote:

 Hello List.

 I need to remove characters from a string and replace them with and
 underscore.

 So instead of having something like:

 $moditem = str_replace(--,_,$mystring);
 $moditem = str_replace(?,_,$mystring);
 $moditem = str_replace(!,_,$mystring);
 etc.

 For every possible character I can think of, is there a way to simply omit
 any character that is not an alpha character and not a number value from 0
 to 9?


check the docs, the first parameter may be an array of multiple needles,
e.g.

$moditem = str_replace(array('-', '?', '!'), '_', $mystring);

you could likely do something more elegant w/ preg_replace() tho.

-nathan


Re: [PHP] Stripping Characters

2010-06-22 Thread Shreyas Agasthya
Then, when does one use ereg_replace as against preg_replace? I read from
one the forums that preg_* is faster and ereg_* is if not faster but
simpler.

Is that it?

Regards,
Shreyas



On Tue, Jun 22, 2010 at 9:58 PM, Richard Quadling rquadl...@gmail.comwrote:

 A word character is any letter or digit or the underscore
 character, that is, any character which can be part of a Perl word.
 The definition of letters and digits is controlled by PCRE's character
 tables, and may vary if locale-specific matching is taking place. For
 example, in the fr (French) locale, some character codes greater
 than 128 are used for accented letters, and these are matched by \w.

 The above becomes ...

 _A _word_ character is any letter or digit or the underscore
 character_ that is_ any character which can be part of a Perl _word__
 The definition of letters and digits is controlled by PCRE_s character
 tables_ and may vary if locale_specific matching is taking place_ For
 example_ in the _fr_ _French_ locale_ some character codes greater
 than 128 are used for accented letters_ and these are matched by _w__

 --
 -
 Richard Quadling
 Standing on the shoulders of some very clever giants!
 EE : http://www.experts-exchange.com/M_248814.html
 EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
 Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731
 ZOPA : http://uk.zopa.com/member/RQuadling

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




-- 
Regards,
Shreyas Agasthya


Re: [PHP] Stripping Characters

2010-06-22 Thread Rick Dwyer

Thanks to everyone who responded.

Regarding the myriad of choices, isn't Ashley's, listed below, the one  
most like to guarantee the cleanest output of just letters and numbers?



 --Rick


On Jun 22, 2010, at 11:44 AM, Ashley Sheridan wrote:


On Tue, 2010-06-22 at 11:40 -0400, Rick Dwyer wrote:
Use preg_replace(), which allows you to use a regex to specify what  
you want to match:


$find = '/[^a-z0-9]/i';
$replace = '_';
$new_string = preg_replace($find, $replace, $old_string);

Thanks,
Ash
http://www.ashleysheridan.co.uk






Re: [PHP] Stripping Characters

2010-06-22 Thread Ashley Sheridan
On Tue, 2010-06-22 at 13:35 -0400, Rick Dwyer wrote:

 Thanks to everyone who responded.
 
 Regarding the myriad of choices, isn't Ashley's, listed below, the one  
 most like to guarantee the cleanest output of just letters and numbers?
 
 
   --Rick
 
 
 On Jun 22, 2010, at 11:44 AM, Ashley Sheridan wrote:
 
  On Tue, 2010-06-22 at 11:40 -0400, Rick Dwyer wrote:
  Use preg_replace(), which allows you to use a regex to specify what  
  you want to match:
 
  $find = '/[^a-z0-9]/i';
  $replace = '_';
  $new_string = preg_replace($find, $replace, $old_string);
 
  Thanks,
  Ash
  http://www.ashleysheridan.co.uk
 
 
 


It is clean, but as Richard mentioned, it won't handle strings outside
of the traditional 128 ASCII range, so accented characters and the like
will be converted to an underscore. Also, spaces might become an issue.

However, if you are happy that your input won't go beyond the a-z0-9
range, then it should do what you need.

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] Stripping Characters

2010-06-22 Thread Jim Lucas
Shreyas Agasthya wrote:
 Then, when does one use ereg_replace as against preg_replace? I read from
 one the forums that preg_* is faster and ereg_* is if not faster but
 simpler.

BUT, all the ereg_* has been depricated.  DO NOT USE THEM if you want your code
to work in the future.  :)

 
 Is that it?
 
 Regards,
 Shreyas
 
 
 
 On Tue, Jun 22, 2010 at 9:58 PM, Richard Quadling rquadl...@gmail.comwrote:
 
 A word character is any letter or digit or the underscore
 character, that is, any character which can be part of a Perl word.
 The definition of letters and digits is controlled by PCRE's character
 tables, and may vary if locale-specific matching is taking place. For
 example, in the fr (French) locale, some character codes greater
 than 128 are used for accented letters, and these are matched by \w.

 The above becomes ...

 _A _word_ character is any letter or digit or the underscore
 character_ that is_ any character which can be part of a Perl _word__
 The definition of letters and digits is controlled by PCRE_s character
 tables_ and may vary if locale_specific matching is taking place_ For
 example_ in the _fr_ _French_ locale_ some character codes greater
 than 128 are used for accented letters_ and these are matched by _w__

 --
 -
 Richard Quadling
 Standing on the shoulders of some very clever giants!
 EE : http://www.experts-exchange.com/M_248814.html
 EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
 Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731
 ZOPA : http://uk.zopa.com/member/RQuadling

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


 
 


-- 
Jim Lucas

A: Maybe because some people are too annoyed by top-posting.
Q: Why do I not get an answer to my question(s)?
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?

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



[PHP] Question about logins and locking

2010-06-22 Thread James Colannino
Hey everyone,

I have a question about logins.  Let's say that I want to allow each
user account to login only once at a time.  I would then need some kind
of locking mechanism to make sure that the same user can't login again
somewhere else until first logging off.  What's a good way to achieve
this?  I want to be able to handle situations in which the user closes
their browser without first logging off, where I would want to count
that as a logout.

Perhaps I could do some kind of periodic polling in Javascript, combined
with a query to the database that sets a value when the user logs in and
when the user logs out?  I'm just looking for some conceptual ideas. 
Thanks everyone!

James

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



RE: [PHP] Question about logins and locking

2010-06-22 Thread Tommy Pham
 -Original Message-
 From: James Colannino [mailto:ja...@colannino.org]
 Sent: Tuesday, June 22, 2010 2:29 PM
 To: php-general@lists.php.net
 Subject: [PHP] Question about logins and locking
 
 Hey everyone,
 
 I have a question about logins.  Let's say that I want to allow each user
 account to login only once at a time.  I would then need some kind of
locking
 mechanism to make sure that the same user can't login again somewhere
 else until first logging off.  What's a good way to achieve this?  I want
to be
 able to handle situations in which the user closes their browser without
first
 logging off, where I would want to count that as a logout.
 
 Perhaps I could do some kind of periodic polling in Javascript, combined
with
 a query to the database that sets a value when the user logs in and when
the
 user logs out?  I'm just looking for some conceptual ideas.
 Thanks everyone!
 
 James
 

James,

1) Set an encrypted (to prevent hijacking and eavesdropping) cookie to
expire when browser closes
2) Have a table in the DB backend to keep track if the user is logged in or
not and when was the last time the validated user access your site (this
gets updated when the user visit a link on your site by checking the cookie
and the DB entry of the session ID)
3) Set your session timeout accordingly to you security requirement
4) Have a javascript on a timeout to self-logoff should the user is AFK
longer than your session timeout.

If another user or if the same user tries to login with a different browser,
you can check the status of the user.  If the user is logged in, you can
deny it after the authentication.  Should the user closes the browser
without having to logoff, you can check when was the last time the user
accessed your site and see if it's been longer than your session timeout.
For security purposes, you can optionally send a courtesy email notifying
that the user didn't logout properly since last accessed.  This way, you can
track whether if the user's system is compromised in some way or not.  It
all depends on what kind of application, service, user level access, and the
strict security you require.

Regards,
Tommy


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



Re: [PHP] Stripping Characters

2010-06-22 Thread Rick Dwyer

Hello again list.

My code for stripping characters is below.  I'm hoping to get feedback  
as to how rock solid it will provide the desired output under any  
circumstance:


My output must look like this (no quotes):

This-is-my-string-with-lots-of-junk-characters-in-it

The code with string looks like this:

$old_string = 'This is my   $string -- with ƒ  
lots˙˙˙of junk characters in it¡™£¢∞§¶•ªºœ∑´®† 
¥¨ˆøπ“‘ååß∂ƒ©˙∆˚¬…æ`__';


$find = '/[^a-z0-9]/i';
$replace = ' ';

$new_string = preg_replace($find, $replace, $old_string);
$new_string = preg_replace(/ {2,}/, -, $new_string);
$new_string = preg_replace(/ {1,}/, -, $new_string);

$new_string = rtrim($new_string, -);
$new_string = ltrim($new_string, -);


echo $new_string;

Will the logic above capture and remove every non alpha numeric  
character and place a SINGLE hyphen between the non contiguous alpha  
numeric characters?


Thanks for the help on this.


 --Rick


On Jun 22, 2010, at 4:52 PM, Rick Dwyer wrote:




On Jun 22, 2010, at 1:41 PM, Ashley Sheridan wrote:


It is clean, but as Richard mentioned, it won't handle strings  
outside of the traditional 128 ASCII range, so accented characters  
and the like will be converted to an underscore. Also, spaces might  
become an issue.


However, if you are happy that your input won't go beyond the a- 
z0-9 range, then it should do what you need.


No, actually I'm fairly confident characters outside the 128 range  
are what are causing me problems now.


So I will try Richard's method.

Thanks to all.

--Rick




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



Re: [PHP] Stripping Characters

2010-06-22 Thread Ashley Sheridan
On Tue, 2010-06-22 at 20:03 -0400, Rick Dwyer wrote:

 Hello again list.
 
 My code for stripping characters is below.  I'm hoping to get feedback  
 as to how rock solid it will provide the desired output under any  
 circumstance:
 
 My output must look like this (no quotes):
 
 This-is-my-string-with-lots-of-junk-characters-in-it
 
 The code with string looks like this:
 
 $old_string = 'This is my   $string -- with ƒ  
 lots˙˙˙of junk characters in it¡™£¢∞§¶•ªºœ∑´®† 
 ¥¨ˆøπ“‘ååß∂ƒ©˙∆˚¬…æ`__';
 
 $find = '/[^a-z0-9]/i';
 $replace = ' ';
 
 $new_string = preg_replace($find, $replace, $old_string);
 $new_string = preg_replace(/ {2,}/, -, $new_string);
 $new_string = preg_replace(/ {1,}/, -, $new_string);
 
 $new_string = rtrim($new_string, -);
 $new_string = ltrim($new_string, -);
 
 
 echo $new_string;
 
 Will the logic above capture and remove every non alpha numeric  
 character and place a SINGLE hyphen between the non contiguous alpha  
 numeric characters?
 
 Thanks for the help on this.
 
 
   --Rick
 
 
 On Jun 22, 2010, at 4:52 PM, Rick Dwyer wrote:
 
 
 
  On Jun 22, 2010, at 1:41 PM, Ashley Sheridan wrote:
 
  It is clean, but as Richard mentioned, it won't handle strings  
  outside of the traditional 128 ASCII range, so accented characters  
  and the like will be converted to an underscore. Also, spaces might  
  become an issue.
 
  However, if you are happy that your input won't go beyond the a- 
  z0-9 range, then it should do what you need.
 
  No, actually I'm fairly confident characters outside the 128 range  
  are what are causing me problems now.
 
  So I will try Richard's method.
 
  Thanks to all.
 
  --Rick
 
 
 


You can remove the second line of code, as the third one is replacing
what line 2 does anyway.

Also, instead of a rtrim and ltrim, you can merge the two with a single
call to trim, which will work on both ends of the string at once.

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] Stripping Characters

2010-06-22 Thread Rick Dwyer

Very good.
Thank you.

 --Rick


On Jun 22, 2010, at 8:14 PM, Ashley Sheridan wrote:


On Tue, 2010-06-22 at 20:03 -0400, Rick Dwyer wrote:


Hello again list.

My code for stripping characters is below.  I'm hoping to get  
feedback

as to how rock solid it will provide the desired output under any
circumstance:

My output must look like this (no quotes):

This-is-my-string-with-lots-of-junk-characters-in-it

The code with string looks like this:

$old_string = 'This is my   $string -- with ƒ
lots˙˙˙of junk characters in it¡™£¢∞§¶•ªºœ∑´®†
¥¨ˆøπ“‘ååß∂ƒ©˙∆˚¬… 
æ`__';


$find = '/[^a-z0-9]/i';
$replace = ' ';

$new_string = preg_replace($find, $replace, $old_string);
$new_string = preg_replace(/ {2,}/, -, $new_string);
$new_string = preg_replace(/ {1,}/, -, $new_string);

$new_string = rtrim($new_string, -);
$new_string = ltrim($new_string, -);


echo $new_string;

Will the logic above capture and remove every non alpha numeric
character and place a SINGLE hyphen between the non contiguous alpha
numeric characters?

Thanks for the help on this.


  --Rick


On Jun 22, 2010, at 4:52 PM, Rick Dwyer wrote:



 On Jun 22, 2010, at 1:41 PM, Ashley Sheridan wrote:

 It is clean, but as Richard mentioned, it won't handle strings
 outside of the traditional 128 ASCII range, so accented characters
 and the like will be converted to an underscore. Also, spaces  
might

 become an issue.

 However, if you are happy that your input won't go beyond the a-
 z0-9 range, then it should do what you need.

 No, actually I'm fairly confident characters outside the 128 range
 are what are causing me problems now.

 So I will try Richard's method.

 Thanks to all.

 --Rick





You can remove the second line of code, as the third one is  
replacing what line 2 does anyway.


Also, instead of a rtrim and ltrim, you can merge the two with a  
single call to trim, which will work on both ends of the string at  
once.


Thanks,
Ash
http://www.ashleysheridan.co.uk






[PHP] In what scenario an extension of a class is useful?

2010-06-22 Thread Camilo Sperberg
Hello everybody :)

I'm really intrigued on something... In what real-world applications could
an extension of a class be really useful?

Let's say I have this code:

class foo {
  function hello_world($a) {
echo 'foo hello world';
  }

  function bye_world() {
echo 'foo bye world';
  }
}

class bar extends foo {
  function hello_world($a,$b) {
echo 'bar hello world';
  }
}

Point 1: Why not just overwrite the hello_world method in the foo class in
the first place? Wouldn't that save code and possible incompatibility or
consistency issues between the code you've already written and between the
two classes ? (Assuming that you do some things based on the $a and $b
values).

Point 2: On the other hand, maybe I could apply different operations to both
(e.g.: return 1 in foo and 2 in bar), without breaking the basic
functionality already achieved in the foo class. (Maybe considering that I
want to apply an update or patch to an already existing application,
however, is this is the scenario, I should always fix the old code wherever
I invoke the foo class which returns us to point 1).

Point 3: Ok, maybe I don't want a specific class to be so huge and I
separate it into pieces of classes. But then again, wouldn't it be simpler
to just save some code and keeping only one file with the entire class?

Is it just that or do I miss something else? I'm not saying it is useless,
it sounds indeed fantastic to work with... but I just can't imagine in what
real-world cases this would be useful.

Greetings !

-- 
Mailed by:
UnReAl4U - unreal4u
ICQ #: 54472056
www1: http://www.chw.net/
www2: http://unreal4u.com/


Re: [PHP] Question about logins and locking

2010-06-22 Thread James Colannino
Tommy Pham wrote:

 1) Set an encrypted (to prevent hijacking and eavesdropping) cookie to
 expire when browser closes
 2) Have a table in the DB backend to keep track if the user is logged in or
 not and when was the last time the validated user access your site (this
 gets updated when the user visit a link on your site by checking the cookie
 and the DB entry of the session ID)
 3) Set your session timeout accordingly to you security requirement
 4) Have a javascript on a timeout to self-logoff should the user is AFK
 longer than your session timeout.
 
 If another user or if the same user tries to login with a different browser,
 you can check the status of the user.  If the user is logged in, you can
 deny it after the authentication.  Should the user closes the browser
 without having to logoff, you can check when was the last time the user
 accessed your site and see if it's been longer than your session timeout.
 For security purposes, you can optionally send a courtesy email notifying
 that the user didn't logout properly since last accessed.  This way, you can
 track whether if the user's system is compromised in some way or not.  It
 all depends on what kind of application, service, user level access, and the
 strict security you require.

Thanks Tommy.  That was very helpful, and some of it is similar to how I
was thinking of doing it.

James

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