Re: [PHP] Is it better to return a multi-array, or an array of objects?

2006-03-03 Thread Murray @ PlanetThoughtful

On 4/03/2006 3:10 PM, Daevid Vincent wrote:

I'm building a fairly large project. I've been trying to follow best
practices, but I'm a bit worried about performance. Using PHP 5.1 and mySQL
5.0.

I have product and company classes.

So when a user does a search of the database, is it better/faster/etc. to
return just a two dimensional associative array to populate an HTML table of
the results like: product name, product id, price, company name, company
phone, etc. (assume I'm only showing some of the total number of fields).
  

[snip]

One observation: you shouldn't return all fields in a recordset unless 
you *need* all of the fields in a recordset.


The majority of the time, you should be explicitly stating which fields 
to retrieve in your SQL statement, as in:


SELECT field1, field2, field8 FROM mytable WHERE whatever

as opposed to:

SELECT * FROM mytable WHERE whatever

Some of the time, yes, that will mean you're explicitly typing out 7 
field names from a table that only has 8 field names, but getting out of 
the habit of using *, particularly if you expect your application to 
work well under heavy loads, will save you resources, which will 
increase your app's overall performance.


It may be you're already doing this, but it wasn't clear from your post.

Much warmth,

planetthoughtful
---
Lost in thought
http://www.planetthoughtful.org

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



Re: [PHP] Mysql Rows

2006-03-03 Thread Murray @ PlanetThoughtful

On 4/03/2006 2:49 PM, benifactor wrote:

thank you. the table does have and id feild that auto increments, however if
you delete a user there will be a gap between the users between which would
not be what is not acurate enough. thank you for you help. simple fix. i
should have caught it.
- Original Message - 
From: Anthony Ettinger [EMAIL PROTECTED]

To: benifactor [EMAIL PROTECTED]
Cc: php php-general@lists.php.net
Sent: Friday, March 03, 2006 3:52 PM
Subject: Re: [PHP] Mysql Rows


define $1 = 0 outside your loop.

i'm curious why you are relying on row-order in the database?
Typically you'd have a PRIMARY KEY auto_increment for something like
this.

  


I have to agree with Anthony - why are you using row order to determine 
something relating to users? I couldn't follow your brief explanation 
above, and the fact that you're doing it sets off some soft alarm bells 
about the design of your application. Why is it important that there 
shouldn't be any 'gaps' between users? Because you want to know how many 
users there are? If so, simply do a SELECT COUNT(*) on the table 
whenever / wherever you need to know.


If you're using it for IDs for the users, it's generally a bad idea to 
reuse this type of information. If you have some other purpose, I'm 
extremely curious about what it might be.


Much warmth,

planetthoughtful
---
Lost in thought
http://www.planetthoughtful.org

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



Re: [PHP] Mysql Rows

2006-03-03 Thread Murray @ PlanetThoughtful



I have to agree with Anthony - why are you using row order to determine
something relating to users? I couldn't follow your brief explanation
above, and the fact that you're doing it sets off some soft alarm bells
about the design of your application. Why is it important that there
shouldn't be any 'gaps' between users? Because you want to know how many
users there are? If so, simply do a SELECT COUNT(*) on the table
whenever / wherever you need to know.

If you're using it for IDs for the users, it's generally a bad idea to
reuse this type of information. If you have some other purpose, I'm
extremely curious about what it might be.




What I was getting at is you get the unique id for the username (if
you allow username changes, then you want a unique key to do your
joins on from other tables).

  


Yep, that's one good reason among many for using unique ids. Thinking a 
little about the OP's question, I could understand row order being 
relevant in certain situations where you wanted to display something 
like, You were the 432nd person to register at our site!, etc.


But, too often I've seen people new to database design not liking 'gaps' 
because 'user1' will have a unique id of '1', while 'user2' will have a 
unique id of '6' because the records associated with unique ids '2' 
through '5' were deleted during testing, and so on. So, they feel that 
'user2' should have a unique id of '2', ignoring the fact that that's 
not a unique id at all, if you had id '2' associated with another record 
at some point.


I'm not suggesting this is what the OP is doing, just that that's why I 
was curious about the purpose.


Much warmth,

planetthoughtful
---
Lost in thought
http://www.planetthoughtful.org

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



Re: [PHP] Mysql Rows

2006-03-03 Thread Murray @ PlanetThoughtful

On 4/03/2006 5:36 PM, Anthony Ettinger wrote:



Yep, that's one good reason among many for using unique ids.
Thinking a
little about the OP's question, I could understand row order being
relevant in certain situations where you wanted to display something
like, You were the 432nd person to register at our site!, etc.



I'd do this with a timestamp, and then sorting by date and doing a 
count() on the results. But then again that's just me. I remember the 
days where i'd clear a database after testing to keep the 
auto_increment inline, but eventually, you will get out of sync on 
that, so it's not a reliable way of keeping a numerical sequence.


Right, or you could just as easily do the same sort and WHERE clause by 
your unique id, but even just doing a count, you're interested in the 
fact that the record is at position whatever in that recordset, so 
'row order' is relevant and, in that context, meaningful.


Much warmth,

planetthoughtful
---
Lost in thought
http://www.planetthoughtful.org

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



Re: [PHP] how to learn php

2006-02-10 Thread Murray @ PlanetThoughtful

On 11/02/2006 10:10 AM, /dev/null wrote:

hello

i have been trying to learn php.

what is the best approach to learning php for someone who has no 
programming experience?


i am very familiar with html, xhtml, and css. i'm not an idiot when it 
comes to using computers.
i have bought several books and have subscribed to a couple of the php 
mailing lists, but i feel that i could be doing more to learn php.


what approach (and steps) did you take in learning this really cool 
scripting language? should i look into taking classes or stick with an 
autodidact approach?


any advice and/or opinions would be greatly appreciated.

thanks.



I honestly believe the best way to learn any programming language, aside 
from perhaps tertiary study (and then only perhaps), is to start out 
with a project and ask the questions you need to solve as you build that 
project.


It should quickly become obvious which things you need to learn, as you 
plan and pursue the project.


Some of those questions might be:

- I need to access data in a database. How do I do that?
- I need to be able to carry data from one page to another, how do I do 
that?
- I need to be able to store 'stuff' at one point in a page (ie, maybe 
data I got from the database) so I can use it again at another point in 
the page.


And so on.

Armed with those questions, you can go through your books, go through 
helpful web sites (don't underestimate the quality of the docs and 
comments on php.net) and ask questions in forums like this one.


Another useful way of picking up knowledge that might not be relevant to 
you right now, but will probably be handy to know later, is reading 
threads in this mailing list. That way you learn about the kinds of 
problems others have encountered, and the suggestions for solving them 
they have received.


Much warmth,

Murray
---
Lost in thought
http://www.planetthoughtful.org

Urban legends, superstitions, ghost
stories and folklore
http://www.ulblog.org

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



[PHP] Redirect from /rss.xml to /rss/rss.xml

2006-02-09 Thread Murray @ PlanetThoughtful

Hi All,

This may turn out to be more of an apache question (but I'm hoping there 
are some apache experts on the list as well), but I'm wondering how I 
would go about automatically redirecting requests for /rss.xml to read 
the contents of /rss/rss.xml instead?


Any help appreciated!

Much warmth,

Murray
---
Lost in thought
http://www.planetthoughtful.org

Urban legends, superstitions, ghost
stories and folklore
http://www.ulblog.org

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



[PHP] Preparing site content for RSS XML feed

2006-02-02 Thread Murray @ PlanetThoughtful

Hi All,

I currently generate a simple rss.xml file for syndication from my site, 
containing nothing more than the subject of the post and a link to the 
article on my site.


I'd like to syndicate the the actual content of each of the posts, but 
as I understand it RSS / XML is somewhat demanding in what it expects of 
how various html entities are treated etc?


I don't suppose, by any chance, that there are any PHP tools that can be 
easily factored in to a process to take content that would include 
normal HTML (ie DIV and SPAN tags, links, TABLEs etc)?


Failing that, does anyone know of a good guide on what steps need to be 
taken to create a valid RSS feed where the content contains HTML?


Any help appreciated!

Much warmth,

Murray

--
Lost in thought :-
http://www.planetthoughtful.org

A blog devoted to urban legends,
superstitions, ghost stories, and
all things folkloric. :-

http://www.ulblog.org

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



[PHP] CR \ LFs being represented as ascii characters in output of mail()

2006-01-31 Thread Murray @ PlanetThoughtful

Hi All,

I'm having an odd problem with formatting of line feeds in an email my 
site automatically sends to me when someone comments on one of my blog 
entries.


For some reason \r\n characters are coming through exactly like that 
in the email, and yet the same value being stored in the backend MySQL 
database seems to represent the carriage-return \ line-feed characters 
as it should.


A typical example of the value when sent in the email would be:

Lol, hi Duncan.\r\n\r\nIt\'s possible that this post once had some comments. I 
lost most of PT at one point when my host had a harddrive crash, and salvaged a 
lot of entries from local copies on my computer, and notes I\'d scribbled in my 
journals and so on.\r\n\r\nStill, it\'s great to see you commenting on the post 
that made you a legend on PT!\r\n\r\nMuch warmth,\r\n\r\nMr Banderas

The odd thing is that the rest of the email is correctly interpreting 
line-feed characters, it's only the value entered on the comment form 
that represents CR \ LFs as normal characters.


I'm not sure if this is the culprit, but because my remote host for this 
site has magic_quotes_gpc on, and my local setup doesn't, I run the 
following function every time a page is requested where form processing 
is performed:


  function traverse ( $arr )
  {
  if ( !is_array ( $arr ) )
  return;

  foreach ( $arr as $key = $val )
  is_array ( $arr[$key] ) ? traverse ( $arr[$key] ) : ( 
$arr[$key] = stripslashes ( $arr[$key] ) );

  }

Can anyone give me any thoughts on how to represent these CR \ LF 
characters properly in the email?


Many thanks,

Murray

--
Lost in thought :-
http://www.planetthoughtful.org

---

A blog devoted to urban legends,
superstitions, ghost stories, and
all things folkloric. :-

http://www.ulblog.org

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



[PHP] date(H, $datevalue) always adds an hour?

2006-01-20 Thread Murray @ PlanetThoughtful

Hi All,

Wondering if anyone can help me work out why date(H) always adds an 
hour? I'm *assuming* it thinks it should be compensating for Daylight 
Saving Time (though I'd be just as willing to believe that it's caused 
by something else), however we don't observe DST in Queensland, Australia.


Making matters a little more complex, while my local machine shouldn't 
be compensating for DST (if that's what's happening), my remote machine 
(based in Florida somewhere, I think) should, when applicable.


So, just to explain a little better.

Let's say the clock on my computer reads 7:00pm. If I do echo 
date(H); it will output 20, instead of 19.


The same thing happens if I take a date value from my mysql database.

$sql = SELECT UNIX_TIMESTAMP(datecreated) AS unx_date FROM mytable;
$rs = mysql_query($sql);
$row = mysql_fetch_object($rs);
echo date(H, $row-unx_date);

If the above record contained the value '2006-01-10 19:00', the code 
would output 20 instead of 19.


Can anyone help me figure out how to accommodate for this?

Much warmth,

Murray

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



Re: [PHP] date(H, $datevalue) always adds an hour?

2006-01-20 Thread Murray @ PlanetThoughtful

On 20/01/2006 8:39 PM, David Grant wrote:

Murray,

What do you get if you print date(T)?

David
  

Hi David,

I get EST, which I assume is Eastern Savings Time? If that's the 
case, any idea where I change this value so that it only affects my 
local machine?


Much warmth,

Murray

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



Re: [PHP] date(H, $datevalue) always adds an hour?

2006-01-20 Thread Murray @ PlanetThoughtful

On 20/01/2006 8:48 PM, David Grant wrote:

Murray,

As far as I know, Queensland is in EST (Eastern Standard Time), so that
is the correct value.  Are you using the same machine or is it remote?

David
  

Hi David,

I'm currently working entirely on my local (Queensland) machine. The 
remote machine only becomes an issue when I'm finished putting the site 
together.


Thanks for giving this some thought...

Murray

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



[PHP] Template engine that doesn't rely on PEAR?

2006-01-15 Thread Murray @ PlanetThoughtful

Hi All,

Can anyone recommend a PHP 4.x compliant template engine that doesn't 
depend on PEAR?


I can't get PEAR to operate properly on my remote host, so I'm looking 
for something that can be dropped in to an existing site and is complete 
in and of itself.


Any recommendations that suit the above would be very welcome!

Much warmth,

Murray

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



Re: [PHP] What software do you use for writing PHP?

2005-12-07 Thread Murray @ PlanetThoughtful

Jim Moseby wrote:

man you guys are wimps.. gvim on windows... :)
  

Pt'Edit' in DOS.  ;)




(Pt * 2)  'edlin' in DOS.  :)


Infinitely recursive pfft A pencil and a piece of paper and 
ringing people to describe the cool web site you've just drawn,


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



Re: [PHP] No forums?

2005-11-08 Thread Murray @ PlanetThoughtful

Richard Davey wrote:


I agree 99% with you, the majority are (excuse my French) utter shite.

*but* the code quality, features and stability of the excellent FUD
Forum thankfully doesn't fall into the camp you describe. While I
don't use it myself, you only need to take a quick look at the code
and who's involved with it to recognise its quality.
 



Hmmm, thank you for mentioning this forum, I wasn't previously aware of 
it. I know phpBB has been criticized previously for behind-the-scenes 
code quality, though it seems like a fairly mature online forum package 
while using it.


Any thoughts on a comparison between the 2?

Much warmth,

Murray

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



[PHP] Line breaks in mail function?

2005-11-06 Thread Murray @ PlanetThoughtful

Hi All,

I'm building a site on a new web host and am currently working on 
feedback forms.


I'm using the mail() function to send the feedback to the destination 
mail account, and I'm having problems getting the body of the email to 
line break.


I've tried constructing the body with both \n\n and \r\n\r\n 
terminating lines where I want line breaks to appear, but both return an 
email with the body in one long string showing the actual \n\n or 
\r\n\r\n characters, as opposed to interpreting them as line breaks.


Example code:

   $body = 'From: ' . $name . '\r\n\r\n';
   $body .= 'Email:' . $email . '\r\n\r\n';
   $body .= 'IP Address: ' . $_SERVER['REMOTE_ADDR'] . '\r\n\r\n';
   $body .= 'Feedback:\r\n\r\n';
   $body .= $feedback;
   mail([EMAIL PROTECTED], Feedback, $body, From: 
$email\r\nReply-To: $email\r\nX-Mailer: PHP/ . phpversion());


As I said above, I've also tried using \n\n instead of \r\n\r\n.

Can anyone give me some advive on how to get the linebreak characters 
interpreted as linebreaks?


Many thanks and much warmth,

Murray

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



Re: [PHP] Line breaks in mail function?

2005-11-06 Thread Murray @ PlanetThoughtful

Jasper Bryant-Greene wrote:


On Mon, 2005-11-07 at 12:20 +1000, Murray @ PlanetThoughtful wrote:
 


Example code:

   $body = 'From: ' . $name . '\r\n\r\n';
   $body .= 'Email:' . $email . '\r\n\r\n';
   $body .= 'IP Address: ' . $_SERVER['REMOTE_ADDR'] . '\r\n\r\n';
   $body .= 'Feedback:\r\n\r\n';
   $body .= $feedback;
   mail([EMAIL PROTECTED], Feedback, $body, From: 
$email\r\nReply-To: $email\r\nX-Mailer: PHP/ . phpversion());


As I said above, I've also tried using \n\n instead of \r\n\r\n.

Can anyone give me some advive on how to get the linebreak characters 
interpreted as linebreaks?
   



Use double quotes around the parts that have \r and \n characters if you
want them to be interpreted.

 


Ah, damn you Jasper, I should have noticed that myself.

Don't you hate it when you've been staring at code too long to notice 
the obvious?


Thank you!

Much warmth,

Murray

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



[PHP] Unsubscribing from several PHP lists

2005-11-04 Thread Murray @ PlanetThoughtful

Hi All,

Does anyone know of a way to unsubscribe an email address from the PHP 
email lists when you can't send a reply to the confirmation email?


My host for my currently subscribed email address has an issue with its 
SSL certificate which means that I can't send replies from that account 
(which has gone on for months and I've given up on waiting for it to be 
resolved). For this reason, I'm swapping my subscriptions over to 
another email account through a different host, but of course the reason 
why I'm subscribing from another account is also the reason why I can't 
reply to confirm the unsubscription from the 'broken' account.


Any help appreciated.

Much warmth,

Murray

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



Re: [PHP] Handling competing edits in a wiki engine?

2005-10-04 Thread Murray @ PlanetThoughtful

Terence wrote:




Murray @ PlanetThoughtful wrote:


Hi All,

I've recently been working on building my own wiki engine for my blog
site. While the majority of the engine is complete, a remaining concern
I have is how to handle competing edits (ie when two or more people are
editing the same wiki page simultaneously).

I'm wondering if anyone else on the list has given this some thought?
How would / do you handle competing edits to the same entry in a wiki
application?



We use a combination of locking the record using a simple boolean 
column together with the user id who has locked the item and the 
timestamp.


The locking prevents another user from opening the form  and happily 
editing away without realising his changes will be lost when he 
presses submit. The user id is to inform the second user who has 
opened the document, and the timestemp is so that the first guy doesnt 
open the document and go out for lunch leaving it locked. We default 
it to 5 minutes after which someone else can open the document and 
edit it.


I think I'm going to go with Jasper's suggestion, re: simply 
timestamping the current edit from the preceding version and testing 
that timestamp against the existence of more recent edits and throwing 
back to the user a request to resolve their changes against the now 
'current' version.


I had been thinking about a timed locking strategy (5 minutes seems 
short, though, for content creation, and what do you currently do when 
person A comes back from lunch, person B has made an edit in the same 
entry after person A's lock timed out, and person A commits their now 
aged edit? Do you basically throw an error anyway, and ask person A to 
resolve?), and perhaps implementing a simple javascript countdown on the 
page to alert the person editing the page when time for their edit is 
running out, but in all honesty I think throwing back the error, and 
perhaps presenting a diff of the newer version of the entry, and the 
version the user has edited, might be the way to go.


Either way, gives me plenty to think about.

Out of curiosity, does anyone know if it's possible to tell whether an 
individual session is still alive from PHP? I don't mean from within 
code being run for a particular user, but in code that, for example, 
might be executed by a cron job, which would examine a table in which 
session ids have been recorded automatically for each visitor, and 
determining which of those sessions are still theoretically alive? I 
suspect this isn't possible, but I've also learned to never 
underestimate the ingenuity of those faced with things that aren't possible.


Much warmth,

Murrray @ PlanetThoughftul
---
A man, a canoe, and a dream to climb Mt Everest...
http://www.planetthoughtful.org

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



[PHP] Handling competing edits in a wiki engine?

2005-10-03 Thread Murray @ PlanetThoughtful

Hi All,

I've recently been working on building my own wiki engine for my blog
site. While the majority of the engine is complete, a remaining concern
I have is how to handle competing edits (ie when two or more people are
editing the same wiki page simultaneously).

I'm wondering if anyone else on the list has given this some thought?
How would / do you handle competing edits to the same entry in a wiki
application?

Just to add a little extra information: all 'edits' are in fact
'inserts'. Entries are stored in a mysql table. The engine simply
displays the most recent record for the entry being viewed. This is, of
course, to allow for retrieval of an historical version of the entry
should one or more entries be vandalized.

Much warmth,

Murrray @ PlanetThoughftul
---
A man, a canoe, and a dream to climb Mt Everest...
http://www.planetthoughtful.org

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



RE: [PHP] Regex Help

2005-09-28 Thread Murray @ PlanetThoughtful
 Hi, folks.   I'm having trouble with a simple regex.  I'm sure it's just
 something small that I'm missing but nothing I'm trying is working.
 
 In an HTML file I have comments like this:
 
 !-- START PRINT --
 various html crap here
 !-- END PRINT --
 
 Here's the regex I'm using:
 
 /!-- START PRINT --(.*?)!-- END PRINT --/
 
 And then the call to preg_match_all():
 
 preg_match_all($printable_reg, $str, $out);
 
 It's been quite a while since I've worked with regular expressions so
 I'm not sure what the problem is.  The regex isn't throwing errors, it's
 just not matching the content located between the start print and end
 print comments.
 
 Can anyone lend a hand or give some advice?

Hi Pablo,

At a (reasonable) guess, I'd say it's because you're not using the s
pattern modifier in your preg_match_all()? The s modifier forces your
regular expression to match new lines with the . metacharacter.

Try:

preg_match_all(/!-- START PRINT --(.*?)!-- END PRINT --/s, $str,
$out);

http://php.planetmirror.com/manual/en/reference.pcre.pattern.modifiers.php

Hope this helps.

Much warmth,

Murray
---
Lost in thought...
http://www.planetthoughtful.org

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



RE: [PHP] serialize

2005-09-26 Thread Murray @ PlanetThoughtful
 murray...
 
 it may have been helpful to the guy to also give him an idea of your tbl
 structure. i think you're talking about something like:
  tbl schema
 
 EvalTBL
-id
-UserID
-ScoreTypeID
 
 ScoreTBL
-id
-ScoreType
 
 table ScoreType could/would have as many different categorites as
 required.
 table EvalType would have a scoreTypeID (from the ScoreTBL) for each
 userID.
 each user could have multiple scoreTypes in the EvalTBL...

Hi bruce,

That would have been an even more normalized representation of the table(s),
yes.

For the purposes of demonstrating a state of normalization that still
allowed the OP to maintain a single table, my structure in that post was:

Scores
-ScoredThingID
-scoretype
-score

I would personally have implemented a structure similar to the one you
outlined, but posted with the idea of first things first. That's why I
included a link to a tutorial on normalization and suggested Googling on the
topic as well, for further reading.

Still and all, it's helpful of you to clarify.

Much warmth,

Murray
---
Lost in thought...
http://www.planetthoughtful.org

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



RE: [PHP] PCRE false match with preg_match?

2005-09-26 Thread Murray @ PlanetThoughtful
 I recently encountered a strange behaviour, could someone please
 countercheck it, to either tell me there is an error in my pattern?
 
 I have a test string: 7005-N/52
 I have two match patterns:a) /([0-9]*)\/(.*)/i
   b) /([0-9]*)\-(.*)/i
 I check the test string with the help of preg_match, and they both
 matched, but normally variant a) shouldn't have matched.
 
 Normally I test my patterns with the tool The Regex Coach, and
 according to this tool it shouldn't have matched.
 PHP version is 5.0.4, PCRE extension version is 4.5 01-December-2003

Hi Jens

Your first pattern 'matches' because it finds a hit on the /52 component
of your test string.

If you look at the pattern itself, it's because you're using the
'zero-or-more-occurrences' quantifier (ie *) in the first part of your
pattern: ([0-9]*).

It's a valid hit, because there are zero incidences of numeric characters
immediately prior to the /52 component of the test string.

Changing the * to a + (at least one or more occurrences) could 'fix'
that pattern (ie so that it doesn't match your string), depending on any
other values being tested by it.

Much warmth,

Murray
---
Lost in thought...
http://www.planetthoughtful.org

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



RE: [PHP] serialize

2005-09-26 Thread Murray @ PlanetThoughtful
 Sent this to [EMAIL PROTECTED] but forgot to copy php-general...
 heh. Here it is again.
 
 I would use a table such as
 Table
  |_UserData
 
 Then use objects per user to store the data.
 class User {
   var TestScore;
   var ScoreType;
   ...
   var Vars;
   function __construct($TestScore, $ScoreType) {
 $this-TestScore = $TestScore;
 $this-ScoreType = $ScoreType;
   }
   function __sleep() {
   $this-Vars = get_object_variables($this);
  }
  ...
  function ListVars() {
 $MyString = ;
 ForEach($this-Vars as $key = $value) {
   $MyString .= ${key}: ${value}\n;
 }
 Return $MyString;
 }
 }
 $Joe = new User(WhateverScore, WhateverType);
 $sJoe = Serialize($Joe);
 ...Store it...
 
 
 ...Recall it...
 (Variable result = recieved serialized version of $Joe)
 $Joe = unserialize($Result);
 $Results = $Joe-ListVars();

Hi Jake,

I guess this comes down to preference, but I personally simply couldn't
bring myself to store serialized objects in a table in the way you're
describing.

A well-designed database should not only be normalized, but should also be
agnostic of the technology being used to access it.

I don't know enough about whether or not serialize() is a widely implemented
language construct, but I have worked on enough projects where someone in
management has said, Hey, I know you've done all this work in PHP (or
insert language here), but we've decided we want to rework it in (insert
other language which someone read a glowing article about on some website)
to shudder at the thought of storing data in a database that perhaps only
one language can access.

It also implies more coding to perform relatively simple recordset
operations such as give me the average of 'score12' across all things being
scored, etc. Lastly, it locks your DBA (assuming you have one) out of being
able to perform granular updates should the need arise. It's for pretty much
the same reason that I hide under my desk, whimpering, when someone
inevitably suggests storing XML recordsets as XML documents in database
fields.

So, full marks for fully exploiting the potential of objects, but you'll
have to excuse me while I go make a coffee and maybe go for a brisk walk to
get over the case of heebie-jeebies this suggestion gave me. ;-)

Much warmth,

Murray
---
Lost in thought...
http://www.planetthoughtful.org

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



RE: [PHP] Optimal Regex?

2005-09-26 Thread Murray @ PlanetThoughtful
 I need to catch all instances of a coordinate in a give string. So far I
 have this, which only works if the coordinate is in a certain format.
 
 
 $string = (334,-53.44),(111,222);
 $expression = '([(][-]?[0-9]*[.0-9]*?,[-]?[0-9]*[.0-9]*?[)])';
 preg_match_all($expression, $string, $matches);
 
 This returns the correct strings (334,-53.44) and (111,222), but I'd like
 all formats to work. Like (111, 222), ( 111 , 222 ), (111, 222 ), etc,
 etc.
 How would I change my regex to accomplish this?

Hi David,

Someone else may have a more direct answer (ie a tweak of your regex that
accounts for the possibilities that you've mentioned) but looking at your
email I immediately had a concern over etc, etc.

Regular expressions rely very much on you being able to predict the
different possible cases you will be dealing with.

Looking at the examples you provided, it looks like you're (currently?)
concerned with anomalous spaces in your string.

A simple way of dealing with these would be to do:

$string = str_replace( , , $string);

...before you attempt your regex match. This will remove all spaces from the
string, making it fit a more predictable pattern (one that your current
regex matches).

If, however, there are other possible anomalous characters you need to take
into account, it would be much more helpful if you could supply examples of
them.

Much warmth,

Murray
---
Lost in thought...
http://www.planetthoughtful.org

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



RE: [PHP] Optimal Regex?

2005-09-26 Thread Murray @ PlanetThoughtful

 Wow, that definitely works. I would sort of like to know how to tweak the
regex, but maybe this is the best way of doing it. Is [0-9]*[.0-9]*? the
best way of looking for a number with decimals?

Hi David,

Just to answer this question, I would probably use something like the
following pattern to match a number with optional decimals:

-?([\d]+)?(\.[\d]+)?

In and of itself, the pattern you have above will only match numeric digits.
So, with a string of 23.99, it would match the 23 and the 99 as
separate matches. Basically this happens because you have the 'lazy'
quantifier (ie ?) after the zero-or-more-occurrences quantifier (*), and
the laziest iteration of [.0-9]*? is to match nothing.

A small improvement can be made by putting () around the [.0-9]* part of the
pattern, thus: ([.0-9]*)?

This now becomes the optional quantifier, indicating that the pattern
between () can be matched *if it exists*.

This still isn't perfect, however, since the modified [0-9]*([.0-9]*)?
will not only match a number like 29.33 in it's entirety, it will also
match 129..3..57 in its entirety. This is because you include the period
(.) within the character class, so it can be matched zero-or-more times as
well as the digits. Moving the period (.) outside the character class so
that the regex only attempts to find an optional single instance of it
between two sets of numbers (where the second set of numbers is also
optional) makes another improvement.

[0-9]*(\.[0-9]*)?

Note that I've escaped the period, because otherwise it would be interpreted
as meaning any single character.

This should now work pretty much as you expect it to.

My version adds the ability to match both positive and negative numbers with
decimals. It also uses the shorthand character class for numeric digits
(\d).

Hope this is of some help.

Much warmth,

Murray
---
Lost in thought...
http://www.planetthoughtful.org

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



RE: [PHP] serialize

2005-09-25 Thread Murray @ PlanetThoughtful
 I have an app that stores evaluation scores so I have 30+ values all
 within a certain range, currently in the db, each of these values has
 it's own column:
 
 Table test
id
user_id
motivation
caring
personal_characteristics
creativity,
...etc.
 
 If the client decides they want to trap more characteristics, it
 requires changes to the table structure and the table quickly gets
 large with 30+ columns.  I was thinking of just compacting all of
 these down to one column and then using serialize/unserialize and
 storing an array of the test scoresis this the best way??

Hi,

This has less to do with PHP (though it will impact on your code) and more
to do with database design principles.

From what you describe, you have a denormalized table. Ie, every score value
has its own field for each thing being scored:

Id, score1, score2, score3, score4..., score30

, 23, 18, 12, 36, 38
1112, 45, 12, 62, 25, 73

A more normalized representation of that table would be:

Id, scoretype, score

, 'score1', 23
, 'score2', 18
, 'score3', 12
, 'score4', 36

, 'score30', 38
1112, 'score1', 45
1112, 'score2', 12
1112, 'score3', 62
1112, 'score4', 25

1112, 'score30', 73

Adding a new score type for each id is then as simple as inserting rows for
the ids with a new 'scoretype' value, meaning that no change of the actual
table structure is required.

To retrieve the scores for any given id in your PHP code, you'd do something
like:

$sql = SELECT scoretype, score FROM scores WHERE id=;
$rs = mysql_query($sql);
while ($row = mysql_fetch_object($rs)){
$scores[$row-scoretype] = $row-score;
}
mysql_free_result($rs);
print_r($scores);

It might be helpful to you to Google on the topic of database normalization.

Here's a link from the MySQL site that gives a brief introduction to the
topic.

http://dev.mysql.com/tech-resources/articles/intro-to-normalization.html

Hope this helps.

Much warmth,

Murray
---
Lost in thought...
http://www.planetthoughtful.org

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



RE: [PHP] basic user/input form questions... more validation!

2005-09-22 Thread Murray @ PlanetThoughtful


 -Original Message-
 From: bruce [mailto:[EMAIL PROTECTED]
 Sent: Friday, 23 September 2005 10:23 AM
 To: 'Jasper Bryant-Greene'; php-general@lists.php.net
 Subject: RE: [PHP] basic user/input form questions... more validation!
 
 one more question/issue...
 
 the mysql_real_escape function escapes with a'\' which works for mysql,
 but isn't standard ansi... is there another function that does the same
 thing, but uses the ansi standard '. also, if there is another function,
 does it also work with mysql??

The important thing here is that escaping with a \ is MySQL's standard for
escaping, so should be used when using MySQL as your storage backend.

Much warmth,

Murray
---
Lost in thought...
http://www.planetthoughtful.org



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



RE: [PHP] Re: email validation (no regex)

2005-09-21 Thread Murray @ PlanetThoughtful
What you have is virtually impossible to determine if all legitimate
 possibilities are covered.
email validation using regex is a very heavily analyzed subject
Google regex email validate and you'll find loads of expressions.
 Look at the Zend article, it provides some insight.
 
 I fully understand about the almost limitless possibilities. Googling the
 subject returns results more mind boggling than the regex itself.  :o)  Do
 ANY of the regex examples you have found cover all those possibilities?
 If
 so, why are there so many different approaches?  For most applications,
 where you will only be validating a small number of emails in a given day,
 why put yourself to all the regex pain, still to not have covered all the
 possibilities?
 
 In the end, with regards to email validation, all most people need is to
 know that a given email has a proper username, just 1 '@' in the middle,
 and
 a valid domain.  If it doesn't, its a bogus email address.

As to that, why not validate the email address by sending an automated
message to the supplied account, requiring the person to click on a
validation link? Easy, simple, works better than either method currently
being discussed, purely for its simplicity, if nothing else.

Much warmth,

Murray
---
Lost in thought...
http://www.planetthoughtful.org

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



RE: [PHP] Re: email validation (no regex)

2005-09-21 Thread Murray @ PlanetThoughtful
 because you should want/need to validate that the address is correct prior
 to determining if the email server is up running...
 
 the regex function simply allows you to quickly determine if the address
 is
 valid... doens't mean that it's going to go to an actual live user...!!
 
 btw simply checking for a single '@' with a domain doesn't do it... what
 if
 the user has '[EMAIL PROTECTED]' or '[EMAIL PROTECTED]'. will your regex 
 accept/deny
 this???
 
 welcome to the world of email validation
 
 -bruce
 
 As to that, why not validate the email address by sending an automated
 message to the supplied account, requiring the person to click on a
 validation link? Easy, simple, works better than either method currently
 being discussed, purely for its simplicity, if nothing else.

I agree, so basic validation is A Good Thing. However, the most desirable
form of validation would have to be, can I send a legitimate email to that
account and receive acknowledgement that it's working by having the user
click on a validation link.

Much warmth,

Murray
---
Lost in thought...
http://www.planetthoughtful.org

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



RE: [PHP] Re: email validation (no regex)

2005-09-21 Thread Murray @ PlanetThoughtful
  because you should want/need to validate that the address is correct
 prior
  to determining if the email server is up running...
 
  the regex function simply allows you to quickly determine if the address
  is
  valid... doens't mean that it's going to go to an actual live user...!!
 
  btw simply checking for a single '@' with a domain doesn't do it... what
  if
  the user has '[EMAIL PROTECTED]' or '[EMAIL PROTECTED]'. will your regex
 accept/deny
  this???
 
  welcome to the world of email validation
 
  -bruce
 
  As to that, why not validate the email address by sending an automated
  message to the supplied account, requiring the person to click on a
  validation link? Easy, simple, works better than either method currently
  being discussed, purely for its simplicity, if nothing else.
 
 I agree, so basic validation is A Good Thing. However, the most desirable
 form of validation would have to be, can I send a legitimate email to that
 account and receive acknowledgement that it's working by having the user
 click on a validation link.

After all, for all the regex / interrogation you perform, you still can't be
certain that the user entered an account *they own*. See? Sending a
validation email is *also* A Good Thing!

Much warmth,

Murray
---
Lost in thought...
http://www.planetthoughtful.org

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



RE: [PHP] Re: Suggestions for class design

2005-09-20 Thread Murray @ PlanetThoughtful
 on 09/19/2005 02:33 PM Chris W. Parker said the following:
  Let's take for example a class called 'Customer' that (obviously)
  manipulates customers in the database. Here is a very basic Customer
  class. (Data validation and the like are left out for brevity.)
 
 This is a basic object persistence problem.
 
 
  (Unless I've already got some major design flaws I think we should be
  good to go.)
  
   Where I get tripped up is when I realize I'll need to at some point
   get more than one customer at a time and thus I want to add a method
   called 'get_customers()'.
 
 
 Yes, there is a problem. You are trying to retrieve objects into memory
 before they exist. It makes more sense that you retrieve objects using a
 factory class.
 
 That is the approach of Metastorage. You may want to take a looka at
 Metastorage before you reinvent the wheel.

Hi Manuel,

I very much understand your desire to promote your various projects, but the
original poster is asking a question that is basic to any programmer's
development in object-oriented coding.

Once he understands how to solve class abstraction problems such as the one
he is asking about, he will be better equipped to deal with a wider range of
application development tasks.

This is not to trivialize your Metastorage project (or, to be more accurate,
I know nothing about it, so it's not my place to trivialize it or
otherwise), but to point out that 'out-of-the-box' solutions to fundamental
coding development problems probably ultimately makes for a poorer
programmer. I could well be wrong, but it seems this is a case of give a
man a fish as opposed to teach a man to fish.

Also, and separate from above, I don't understand the relevance of your
comment, You are trying to retrieve objects into memory before they exist.
Unless I'm horribly mistaken [1], the original poster has developed a class
that abstracts a single customer, and is asking the list for suggestions in
how to best approach a need to be able to abstract collections of customers.
This is a normal application development issue, and for the life of me I
can't grasp how your comment relates.

Much warmth,

Murray
---
Lost in thought...
http://www.planetthoughtful.org

[1] And it wouldn't be the first time!

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



RE: [PHP] Tidying code for PHP5.0.5/PHP4.4.0

2005-09-20 Thread Murray @ PlanetThoughtful
 Jochem Maas wrote:
  Michael Sims wrote:
  So, as far as foo() knows:
 
  foo($a = 5);
  and
  foo(5);
 
  are exactly the same...
 
  I don't think they are, and you're examples don't prove it.
  Anyone care to come up with the proof.
 
 No, I was wrong, Rasmus corrected me.  That's my one allowed mistake for
 the day.  I promise to wait until tomorrow before making another one. ;)

Who was it that said, If you find that you only made one mistake today, you
weren't looking hard enough?

Oh, that's right, it was me. ;)

Off to make more mistakes...

Much warmth,

Murray
---
Lost in thought...
http://www.planetthoughtful.org

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



RE: [PHP] Re: Suggestions for class design

2005-09-20 Thread Murray @ PlanetThoughtful
[snippage]

 I do not understand why this could bother you or anybody else. If you
 have a better solution, nothing stops you to make your recommendations.

Hi Manuel,

I did make my recommendation. To you. It went something like (and I'm
paraphrasing), Your proposed solution doesn't solve the original poster's
conceptual problem with abstracting classes that deal with collections of
objects in conjunction with classes that abstract single objects.

In other words, and I realize I'm stretching out on a limb with this
metaphor, I saw in your post an attempt to treat the symptoms without
offering a cure for the disease.

Actually, that really is a terrible metaphor. I'm certain I'll think of a
better one about 3 seconds after I hit 'send'. Isn't that always the way?

And your perception of bias may or may not be accurate. I don't recall
delivering wrath-of-god denunciation of your suggestion to use a project you
developed, just acknowledged a desire to promote a project you're probably
(and perhaps justifiably) proud of. You say that wasn't a component of your
recommendation. I'm willing to accept that, not that I expect you to be
losing any sleep over whether or not I believe you.

This is a reality of expressing opinions on a public list: others are free
to disagree with you. See Michael Sims' response to the same post you're
addressing here. He makes some great points and I for one am glad he had an
opportunity to make them in response and counterpoint to a post I made. His
thoughts enrich the list, as do yours, and as, I hope, do mine.

  This is not to trivialize your Metastorage project (or, to be more
 accurate,
  I know nothing about it, so it's not my place to trivialize it or
  otherwise), but to point out that 'out-of-the-box' solutions to
 fundamental
  coding development problems probably ultimately makes for a poorer
  programmer. I could well be wrong, but it seems this is a case of give
 a
  man a fish as opposed to teach a man to fish.
 
 I think you should have learned about Metastorage first before
 commenting. It is not really a out-of-the-box solution. It is a code
 generator tool that employs well known design patterns to generate code
 to customized to the developer needs.

At some point I just may do that. It's an interesting concept, if nothing
else. My comments remain relevant, however, regardless of my knowledge of
your project. At least, and this is important, that's my opinion.

  Also, and separate from above, I don't understand the relevance of your
  comment, You are trying to retrieve objects into memory before they
 exist.
  Unless I'm horribly mistaken [1], the original poster has developed a
 class
  that abstracts a single customer, and is asking the list for suggestions
 in
  how to best approach a need to be able to abstract collections of
 customers.
  This is a normal application development issue, and for the life of me I
  can't grasp how your comment relates.
 
 I tried to explain in the part of the message that you did not quote,
 why using a factory class as entry point, which is my suggestion, it
 makes more sense.

Thank you for the extra explanation. I still don't understand the comment's
relevancy to the actual question being asked by the original poster, but I
will explain, in case it's of interest, why that comment caused me some
confusion:

- The original poster outlined that he had created a class that represented
a customer.

- He told the list he was having difficulties with the concept of
abstracting a collection of customers

- He received some helpful suggestions from the list about how to approach
that task

- None of which would have meant he was 'trying to retrieve objects into
memory before they exist.' I don't know about anyone else, but what that
comment implied to me was that the original poster was attempting to
instantiate a class as an object before including the file that contained
the class definition.

I may well have misunderstood what you meant by your comment, but it still
stands out as not being relevant to the problem the original poster was
describing.

Much warmth,

Murray
---
Lost in thought...
http://www.planetthoughtful.org

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



RE: [PHP] Re: Suggestions for class design

2005-09-20 Thread Murray @ PlanetThoughtful
  This is not to trivialize your Metastorage project (or, to be more
  accurate, I know nothing about it, so it's not my place to trivialize
  it or otherwise), but to point out that 'out-of-the-box' solutions to
  fundamental coding development problems probably ultimately makes for
  a poorer programmer. I could well be wrong, but it seems this is a
  case of give a man a fish as opposed to teach a man to fish.
 
 I see your point, but I'm not so sure I agree fully.  Manuel suggested
 Metastorage (which makes sense, it's his project and he's most
 familiar/comfortable with it), I suggested Propel because that is what
 I've
 used.  I think we both suggested existing ORM's for the same reason...
 namely that properly implementing a full featured ORM is an extremely
 difficult thing to get right.  I don't know anything about Chris's skill
 as
 a programmer, but he's bound to reinvent the wheel several times over, and
 poorly to boot.  I believe that implementing an ORM is one of those things
 that you cannot fully understand and appreciate until you've tried to do
 it
 and failed.  IMHO it's only after you've built one that you realize what
 you
 really need, and by then it needs to be rebuilt.  It's kind of like Fred
 Brook's plan to throw one away; you will, anyhow, or at least it was for
 me.

Hi Michael,

You've hit on a point that I implied in my original post, but should have
been more explicit about. If I can add some emphasis: * IMHO it's only after
you've built one that you realize what you really need *

I couldn't agree more. As I read and understand the original poster's
question, he is still in the 'building one' phase of his development as an
OO PHP coder. If this wasn't the case, I doubt he'd be asking the question
he asked.

My post was not aimed at saying 'using packaged approaches to solve coding
problems is bad', but to say 'the original poster is asking a fundamental
learning question, so a packaged approach will possibly, maybe even
probably, hamper his development as a programmer at this point.' Put another
way, working out how to implement a class to handle the question he asked
would not be incredibly challenging, particularly with the help and advice
of people on this list, and would add to his understanding of how OO works
generically and in PHP. Both very good things.

I use several package solutions in my own projects. Notably, MDB2 and
HTML_QuickForm. I use MDB2 because it means my projects can be more flexible
to any decisions made to change the backend storage technology. I use
HTML_QuickForm because it provides convenient methods to building forms, and
it minimizes the mixture of HTML and PHP code in my pages, something I
personally prefer. Having said which, before adopting either of these
packages I was satisfied that I understood how to achieve the same results
using nothing more than my own coding skills. 

In other words, as a programmer I am comfortable working directly with a
variety of data storage backends, employing classes to abstract different
collections of data objects. I am comfortable building, validating, and
processing forms. The packages I use are for convenience, rather than
placing me at arm's length to understanding the programming concepts and
needs they address.

Also, I don't disagree that there are some brilliant packages out there,
written by people who've taken time to learn more about a specific problem
or set of problems than the average programmer would have to spend,
particularly across the broad range of coding demands an application may
touch upon. Again I reiterate: using packages to address application needs
is not a bad thing, while avoiding learning the basics of programming by
using such packages almost certainly is, particularly if you're taking your
development as a programmer seriously, and consider yourself to be aiming at
becoming a 'professional' programmer.

[here there be snippage]

 My point is, I had implemented my own home grown ORM about 3-4 times, and
 while each one was much better than the one that preceded it, I still
 wasn't
 quite all the way towards a 100% general implementation.  That's when I
 found Propel.  It got so many things right that I hadn't figured out how
 to
 solve, as well as implementing things that I hadn't even considered yet.
 
 Now, you could argue that going through all those iterations and
 refactoring
 my own ORM helped me to improve my skills as a programmer, and you would
 be
 right.  That's where I agree with you, somewhat. :)  However, I was many
 many iterations away from improving my ORM to the point where it would be
 as
 useful as Propel (and that's assuming it would ever be that useful).  The
 guys who developed it (and I'm sure the same goes for Manuel and
 Metastorage) concentrated on making the best general purpose ORM they
 could
 make.  IOW their whole goal was to build an ORM, while my goal each time
 was
 to develop one for the purposes of finishing whatever real project I
 

RE: [PHP] html forms in php

2005-09-15 Thread Murray @ PlanetThoughtful
 Good day all,
 
 I have a problem for you all..
 I have a form that has has the ability to delete a lot of information from
 my MySQL database.
 
 I would like to create a bit of security, in case the user hits the button
 by accident.
 I would like to create an additionnal window that would appear that would
 ask:
 Are you sure? and then a yes and no buttons to confirm the deletion
 or
 to cancel the command.
 
 Any thougts??

Hi Phil,

You can achieve this in several ways. One would be to use a JavaScript
onClick event on the 'dangerous' button to pop up a dialog with your 'Are
you sure?' prompt and the yes/no buttons. If the user clicks on the 'no'
button, you use JavaScript to cancel the page submission. If they click on
the 'yes' button, the page submits. This approach would mean assuming that
your users have JavaScript enabled.

A second approach would be to have an intermediary page between the page
with the button, and the page that performs the actual delete. The
intermediary page would be little more than another form with the yes/no
buttons.

Much warmth,

Murray
---
Lost in thought...
http://www.planetthoughtful.org

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



RE: [PHP] Modifying data in forms with values

2005-09-13 Thread Murray @ PlanetThoughtful
 I have to create registration forms all the time for people in the office
 and
 what I keep running into is that I need a way for when they edit a field
 that
 the drop-down list of choices is automatically set for the right now.
 
 I have 100+ counties in one list, but I don't want to write 100+ if
 statements
 for checking to see if the value of $county equals the value of the field
 I am
 drop down choice.
 
 Anyone have some quick solutions?
 
 I have radio buttons as well, but going to use a drop-down list for the
 editing
 pages to make it all simple.

Hi Robert,

As a suggestion, why not put your counties in an array (are you taking them
from a recordset? If so, same idea applies) and use foreach() to iterate
through the array, building the select list. When $county equals the current
value of the array, include  SELECTED in the select HTML you are building.
One if statement should handle the situation nicely.

Much warmth,

Murray @ PlanetThoughtful
---
Lost in thought...
http://www.planetthoughtful.org

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



RE: [PHP] error message while mysqling on php

2005-09-13 Thread Murray @ PlanetThoughtful
 I have received an error: Warning: mysql_num_rows(): supplied argument is
 not a valid MySQL result resource in /home/www/mksystem.net when trying to
 execute $num = mysql_num_rows($result);
 
 Please go to http://mksystem.net/phpinfo.php and tell me whether it is due
 to the version of php I have on server and an easy workaround would be
 appreciated.

Check the syntax of your SQL statement, it's very possible you have an error
in it somewhere. If you have PHPMyAdmin, or some other interface to MySQL
such as MySQL Query Browser, etc, try executing the SQL statement in one of
them directly, to see if they return a valid resultset.

Much warmth,

Murray
---
Lost in thought...
http://www.planetthoughtful.org

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



RE: [PHP] setting 'expiry date'

2005-09-12 Thread Murray @ PlanetThoughtful
 I have a php/mysql database with articles. What I need is a php sctipt
 that
 will compare the current day with the 'expiry date' entered by the user
 and
 if the there is a difference then drop it from the database..
 
 I retrieve the date (called time and format it like this...
 
 $query= SELECT DATE_FORMAT(time, '%d.%m.%Y') AS time, article, id FROM
 news
 ORDER BY id DESC;
 
 
 The expiry date is entered through a javascript widget and is in the
 format
 dd/mm/.

Hi Ross,

Is there a real reason for deleting the articles? Why not only display
articles where the current date/time is less than the expiration date/time?

Once the current date/time is greater than the expiration date/time, stop
displaying the article.

Same effect as far as your users are concerned, and you're not faced with
the frustration of, 'I need a copy of that article from 12 months ago!'

Much warmth,

Murray
---
Lost in thought...
http://www.planetthoughtful.org

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



RE: [PHP] Opinion Request - No PHP content - Versioning Systems

2005-09-12 Thread Murray @ PlanetThoughtful
 
 Hey, I'm about to implement a versioning system here, and was going to
 go with CVS, but being that I haven't used it in almost two years I was
 wondering what y'all think?  Opinions on the best, user-friendly (Mac
 Geeks will be using it), etc?  Thanks.
 

Hi John,

I only have experience with CVS and Subversion, but of the two, I *much*
prefer Subversion. Could be a purely subjective thing, but it's worth
looking into all the same.

http://subversion.tigris.org/

Much warmth,

Murray
---
Lost in thought...
http://www.planetthoughtful.org

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



RE: [PHP] searching through a mysql db/tbl

2005-09-10 Thread Murray @ PlanetThoughtful
 hi...
 
 i'm trying to figure out how to approach/solve a few issues. looking
 through
 google hasn't made the light shine!!
 
 1) i'm trying to figure out how to allow a user to search through a
 query/tbl for a given string. ie, if i have the following as the result of
 a
 query:
 
   name   email   foo...
   aa [EMAIL PROTECTED] 
   b1 [EMAIL PROTECTED]123
   bb [EMAIL PROTECTED]qwe
 
 
 if i allow a user to search on say 'aa', i'd like the user to be able to
 get:
 
   name   email   foo...
   aa [EMAIL PROTECTED] 
   b1 [EMAIL PROTECTED]123
 
 any ideas as to how i could go about and create the query, or what would i
 need to do to have this result...

Hi,

Basically what you need to do is dynamically create the WHERE clause of your
query string.

In the example above, the WHERE clause might look something like:

$qry = SELECT * FROM table WHERE name LIKE '%$searchterm%' OR email LIKE
'%$searchterm%';

If you want to span the search across more fields, simply add them as extra
OR elements to the WHERE clause. 


 
 2) if i have a query that produces a number of rows, how/what would i need
 to do, to limit the number of rows displayed, and to allow the user to
 select a 'back/next' button that would generate/display the next 'N' items
 in the list/query results...
 
 if anybody could direct me to sample docs/code that kind of
 describes/solves
 what i've described, i'd appreciate it!!!

Here I'm making the assumption that you're using MySQL. If that's the case,
you need to familiarize yourself with the LIMIT clause. This allows you to
specify a starting point and number of rows to return for the resultset.

So, using the query above again:

$qry = SELECT * FROM table WHERE name LIKE '%$searchterm%' OR email LIKE
'%$searchterm%' LIMIT 0,10;

...will return the first 10 results from your query (records 0 to 9). Note
that the 'first' row is at position 0 in the recordset. Also note: if there
are less than 10 records returned by your query (ie in your example, only 2
match your pseudo request), only those records will be returned.

Then, issuing:

$qry = SELECT * FROM table WHERE name LIKE '%$searchterm%' OR email LIKE
'%$searchterm%' LIMIT 9,10;

...will return the next 10 results from your query (records 10 to 19), and
so on.

This requires you to pass some variables from one search result page to the
next, particularly the variable that indicates where the 'next' results
should begin, allowing you to factor that in when building the LIMIT clause
of the query string for the search results that should be displayed on that
page.

A Google search on PHP pagination or PHP paginate should return a number
of online resources explaining how to paginate results returned from a db
query in PHP.

Hope this helps.

Much warmth,

Murray
---
Lost in thought...
http://www.planetthoughtful.org

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



RE: [PHP] RE: PHP wiki recommendations

2005-09-09 Thread Murray @ PlanetThoughtful
  I'm not a Wiki expert, but have been using TikiWiki for a while and
 very much like it.  It does everything you say with the possible
 exception of CSS.  It may very well support CSS, I just don't need it so
 haven't investigated.  It also allows for the use of templates that can
 be applied globally or by each user (these may be the CSS bit, again, I
 just haven't played).
 
 User logins can be pre-assigned or user driven so you can control who
 does what.
 
 I think you can turn on/off the CamelCase feature.
 
 Doug
 
 
 -Original Message-
 From: Murray @ PlanetThoughtful [mailto:[EMAIL PROTECTED]
 Sent: Thursday, September 08, 2005 2:03 AM
 To: php-general@lists.php.net
 Subject: PHP wiki recommendations
 
 Hi All,
 
 I want to add a wiki to my blog site to help create a knowledgebase of
 the characters, localities, stories I write to make it easier for new
 visitors to delve into the areas that interest them.
 
 I've been experimenting with a couple of different wiki packages, but am
 always interested in others' thoughts and recommendations.
 
 In particular, I've looked at MediaWiki and PmWiki. Of the two, I like
 MediaWiki's 'completeness', but it's also quite slow and doesn't strike
 me as being particularly (or easily?) customizable. PmWiki is probably
 my current candidate, but again I'd like to make sure I'm not missing a
 more obvious choice.
 
 My shopping list for the ideal wiki application is:
 
 - wiki entries preferably stored in MySQL tables. I'm not adamant about
 this (eg PmWiki uses files rather than a db backend), but it would suit
 my purposes better to be able to draw from the wiki tables from the
 front page of my blog to show lists of recently added and recently
 updated wiki entries
 
 - non-reliance on CamelCase wiki links. Many of my characters etc use
 joined CamelCase names (eg KillFork and DangerSpoon), and to avoid
 confusion I'd rather explicitly define links to wiki content
 
 - ability to categorize wiki entries
 
 - ability to compare history of wiki edits and easily reinstate older
 edits if wiki pages get 'graffiti'd'
 
 - ability to allow others to edit / create wiki entries, thru a user id
 / password system, so that regulars who would like to participate can do
 so
 
 - ability to customize presentation of wiki pages, presumably through
 CSS etc, so that I can maintain the 'look and feel' of my blog thru the
 wiki content
 
 - PHP based, though my host does run Perl, so if the killer wiki app is
 a Perl-based one, I'm sure I can muddle thru implementing it
 
 If anyone has any recommendations for other wiki applications I should
 look at before making a decision, I'd love to hear from you!

Hi Doug,

Thanks for the recommendation -- I did take a brief glance at TikiWiki, but
my original impression was that it was too CMS-heavy for my needs.

Given your recommendation, though, I'll take another look at it, and will
probably download it and play around with it on my local machine.

If anyone else has any other recommendations, I'm still very open to
suggestions!

Much warmth,

Murray
---
Lost in thought...
http://www.planetthoughtful.org

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



[PHP] PHP wiki recommendations

2005-09-08 Thread Murray @ PlanetThoughtful
Hi All,

I want to add a wiki to my blog site to help create a knowledgebase of the
characters, localities, stories I write to make it easier for new visitors
to delve into the areas that interest them.

I've been experimenting with a couple of different wiki packages, but am
always interested in others' thoughts and recommendations.

In particular, I've looked at MediaWiki and PmWiki. Of the two, I like
MediaWiki's 'completeness', but it's also quite slow and doesn't strike me
as being particularly (or easily?) customizable. PmWiki is probably my
current candidate, but again I'd like to make sure I'm not missing a more
obvious choice.

My shopping list for the ideal wiki application is:

- wiki entries preferably stored in MySQL tables. I'm not adamant about this
(eg PmWiki uses files rather than a db backend), but it would suit my
purposes better to be able to draw from the wiki tables from the front page
of my blog to show lists of recently added and recently updated wiki entries

- non-reliance on CamelCase wiki links. Many of my characters etc use joined
CamelCase names (eg KillFork and DangerSpoon), and to avoid confusion I'd
rather explicitly define links to wiki content

- ability to categorize wiki entries

- ability to compare history of wiki edits and easily reinstate older edits
if wiki pages get 'graffiti'd' 

- ability to allow others to edit / create wiki entries, thru a user id /
password system, so that regulars who would like to participate can do so

- ability to customize presentation of wiki pages, presumably through CSS
etc, so that I can maintain the 'look and feel' of my blog thru the wiki
content

- PHP based, though my host does run Perl, so if the killer wiki app is a
Perl-based one, I'm sure I can muddle thru implementing it

If anyone has any recommendations for other wiki applications I should look
at before making a decision, I'd love to hear from you!

Much warmth,

Murray
---
Lost in thought...
http://www.planetthoughtful.org

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



RE: [PHP] Cleaning a resultset

2005-09-08 Thread Murray @ PlanetThoughtful
 Hi,
 
 I have a resultset from a query and need to remove some rows after doing
 some php processing then insert into another table i.e.
 
 /** Get data**/
  $qid = mysql_query('SELECT ...);
 
  /** Clean data **/
  while( $r = mysql_fetch_object( $qid ) ) {
 
  }
 
 How can i generate a new resultset / remove data from the existing
 resultset
 using this method?
 
 Thanks for your help

Hi Shaun,

Basically while iterating thru the resultset in $qid, test / cleans the data
row by row, and perform an INSERT query for each row within your while loop
that you want to be inserted into your other table.

Hope this helps.

Much warmth,

Murray
---
Lost in thought...
http://www.planetthoughtful.org



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



RE: [PHP] regular expression for integer range

2005-09-07 Thread Murray @ PlanetThoughtful
 Hi all,
 
 
 I want to write regular expression for checking the string format entered
 by user.
 
 the allowed formats are
 
 examples:
 10
 10,
 10,12-10
 12-10
 
 that is the valid strings are:
 1. only integer
 2. an integer, range of integers example 3
 
 and no other characters must be allowed.

Hi babu,

As you've pointed out, you have 4 distinct scenarios to deal with, and it
may be very difficult, without a great deal of tuning and tweaking, to
define a regular expression that can effectively match all 4 scenarios
without including false matches as well.

One way of dealing with this is to build more specialized and exact regular
expressions for each possible scenario and group them together in an if
statement.

Eg.

if (preg_match('/^\d+$/',$subject) || preg_match('/^\d+,$/',$subject) ||
preg_match('/^\d+,\d+-\d+$/', $subject) || etc etc){

// code for successful match of valid data in $subject

} else {

// code for invalid data in $subject

}

Basically, the if/else statement is testing each distinct possible pattern
and executing code if any of those distinct possible patterns match.

It may not ultimately be the most graceful way of dealing with the
situation, but having spent many hours attempting to tweak complex regular
expressions looking for the magic combination, I've learned that breaking
scenarios down this way can save a lot of development time and frustration.
This doesn't mean there isn't a benefit to finding the perfect regular
expression for your needs, just that it can often be difficult to guarantee
your code won't be plagued by false matches or false exclusions as your
expression becomes more and more complex.

Hope this helps a little.

Much warmth,

Murray
---
Lost in thought...
http://www.planetthoughtful.org

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



Re: [PHP] php/mysql web question

2005-09-06 Thread Murray @ PlanetThoughtful

 hi...
 
 if an app has a webpage that has to interface/display data from a mysql
 db,
 does the app have to essentially do a new db_connection for each time that
 a
 user accesses the page during the session.
 
 as far as i can tell, it does.
 
 in other words, the page would need to look something like:
 
   ?
 start the page
 do the db_connect
 do the db_query
 process the information from the db/tbl
 close the db_connection
   ?
 
 the only reason i ask is that it would be nice/good if there was some way
 of
 opening a connetion once for a given session (save bandwidth) as well as
 somehow saving data from the db/tbl (short of using session vars)

Hi Bruce,

Basically what you're asking about is persistent connections from PHP to
MySQL, which are performed using mysql_pconnect().

In the pseudo-code outline you have above, you don't need to perform the
'close the db_connection' step. Each time a page loads that has a
mysql_pconnect statement, it will check to see if an existing (or persisted)
connection is available, and will use it instead of creating a new
connection, if one does. If no persisted connection is found to be
available, mysql_pconnect goes ahead and creates the connection, and
persists it for future connection attempts.

Each page should still probably perform the mysql_pconnect function, since
unless you have a very statically defined interaction of pages, you may not
be able to guarantee that a connection already exists when a particular page
is loaded.

Don't forget that while closing the db connection isn't necessary on a
page-by-page basis when using persistent connections, you should still
habitually free recordsets either at the bottom of the page, or at a point
in your code where you know they are no longer needed.

Hope this helps a little.

Much warmth,

Murray
---
Lost in thought...
http://www.planetthoughtful.org

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



RE: [PHP] Saturdays and Sundays

2005-09-01 Thread Murray @ PlanetThoughtful
 Hi,
 
 Is it possible to get the number of saturdays and sundays for a given
 month
 / year?
 
 Thanks for your help.

Hi Shaun,

Not sure if there's a graceful PHP solution (there probably is, but can't
think of one, myself, right at this moment) but it sounds like what you
might need is a calendar table in your database.

This is a common approach to solving a number of date-related issues, of the
type you're asking about.

A typical structure might be

Recid (int autoincrement)
Date (datetime)
Year (int)
Month (int)
Day (int)
Day_name (varchar)
Month_name (varchar)
Etc..

A record for today's date would then look like:

1, '2005-09-01', 2005, 9, 1, 'Thursday', 'September'

There are a number of other fields you could add, depending on your needs
(financial_quarter, for example, if your site is a business application,
week_num and so on)

You would then write a routine that would populate the table with
appropriate values for any given time period (10 years into the future, for
example) and thus would be able to very simply perform operations like:

SELECT COUNT(*) FROM date_info WHERE year=2005 and month=9 and
(day_name='Saturday' or day_name='Sunday')

Again, there may be a better solution in PHP, but any date-intensive
application would probably benefit from the above approach. In particular,
it becomes very useful when you use the recid value for the date from your
calendar table in application data tables instead of the actual date,
allowing you to perform very flexible queries where you might be interested
in sales results for all the Thursdays in every September for the last 5
years, etc.

Regards,

Murray
---
Lost in thought...
http://www.planetthoughtful.org

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



RE: [PHP] conditional statement inside while loop?

2005-09-01 Thread Murray @ PlanetThoughtful
 Hello everyone,
 
 I'm using a while loop to display a list of people contained in my
 database.
 I'd like to assign different font colors to each depending on which city
 they're from, but I can't seem to get an if/elseif/else statement to work
 inside the while loop.  Is there another way to do this?

Hi Zach,

There should be no reason why you can't use if/elseif/else within your while
loop. The fact that you're experiencing problems strongly suggests that you
have a combination of conditionals in your if/elseif/else that is
effectively ignoring the data being returned from your recordset.

It may be something as simple as using = in your if statement instead of
== (ie, so the conditional is always true, because you're using the
assignment = operator instead of the evaluative == operator), or a
combination of conditions, each of which are accurate but which when placed
together cause problems.

To get an idea where your problem is occurring, try going from simple to
complex. Start with something like the following pseudo-code:

while ($row = get_data_from_your_recordset){
if (strlen($row['a_recordset_field'])  0){
echo Data found:  . $row['a_recordset_field'] . br /;
} else {
echo Data not foundbr /;
}
}

The assumption being made above is that you will be using a field from your
recordset that contains data that is ordinarily longer than 0 bytes.

Doing the above will demonstrate that at the very least you are returning a
valid recordset and that conditional statements work within while loops. If
even this fails, then check the SQL that is being used to populate the
recordset, and make sure that you are using the same field names in your PHP
code as is being returned from the table by the recordset.

Once the above is working, add back in your actual conditional(s), one by
one. You're looking for the point where 'working' code becomes 'broken'
code. Most of the time when you debug in this way it becomes obvious why the
code isn't behaving the way you expect it to. If there's still any confusion
at that point, at least you will be in a better position to supply actual
code to the list, so we can work out the real problem.

Much warmth,

Murray
---
Lost in thought...
http://www.planetthoughtful.org

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



RE: [PHP] (Yet another) I'm blind ... post

2005-08-31 Thread Murray @ PlanetThoughtful
 In this code, I'm not getting the value of $list passed to the Mailman
 page.
 I've checked this umpteen times by now, but fail to see the error. I've
 beaten myself suitably with a steel ruler -- but it didn't help. Nor does
 the cold I'm coming down with I suppose.
 
 Anyone see the error, and feel like pointing it out to me?
 
 Martin S

Hi Martin,

Try checking for the value in $_POST['lista'] on your subscribe page.
Failing that, try the following:

print_r($_POST);

This should give you all the variables and values being sent by the form to
the page being used to process that form.

Hope this helps.

Much warmth,

Murray
---
Lost in thought...
http://www.planetthoughtful.org

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



RE: [PHP] Problem With Inner Loop

2005-08-30 Thread Murray @ PlanetThoughtful
 Hi,
 
 The following code is attempting to display a list of work types for all
 the
 users in my database. However it only loops through the inner loop once
 and
 I can't work out why, can anyone help here please?
 
 Thanks for your help
 
 table
 ?php
 include('application.php');
 $staff_qid = mysql_query('SELECT
   U.User_ID,
   CONCAT_WS( , U.user_Firstname, U.User_Lastname) AS User_Name
   FROM Users U, Allocations A, Projects P
   WHERE U.User_ID = A.User_ID
   AND A.Project_ID = P.Project_ID
   AND P.Project_ID = 38
   AND (U.User_Type = Staff
OR U.User_Type = Manager
OR U.User_Type = Administrator)
   ORDER By User_Name');
 $work_type_qid = mysql_query('SELECT
Work_Type_ID,
Work_Type
FROM Work_Types
WHERE Project_ID = 38
ORDER BY Day_Type');
 ?
 table
 ?php while( $staff_r = mysql_fetch_object( $staff_qid ) ) { ?
  tr
  ?php while( $work_type_r = mysql_fetch_object( $work_type_qid ) ) { ?
   td?php echo $work_type_r-Work_Type; ?/td
  ?php } ?
  /tr
 ?php } ?
 /table

Hi Shaun,

Looking at your code, it doesn't appear that there's an actual relationship
between your two queries? Ie the select statement for the 'inner' query
doesn't reference any value returned by the select statement from the
'outer' query.

This means that for every record returned by the outer query, the same
record or records will be returned by the inner query, which doesn't seem to
match the intention of the summary you gave at the top of your email. This
could be an error of interpretation on my part. It may well be that every
record returned by the inner query is relevant to each and every record
returned by the outer query. It's hard to tell from the details you've
included.

Having said which, I'm personally more used to situations where the
following occurs (warning, pseudo-code alert!):

$outerrs = select_query;
while ($outerdata = get_result_from_outerrs){
$innerrs = select_query_using_value_in_where_clause_from_$outerdata;
while ($innerdata = get_result_from_innerrs){
display_information_from_outerdata_and_or_innerdata;
}
}

In the above situation, the inner query is called for each record in the
outer query, indicating a relationship between the two resultsets.

As another thought, have you run the inner select statement against your db
(ie using PHPMyAdmin / MySQL Query Browser / etc) to confirm that under
normal circumstances that query actually returns more than one record?

Regards,

Murray
---
Lost in thought...
http://www.planetthoughtful.org

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



RE: [PHP] How can I format text in textarea?

2005-08-30 Thread Murray @ PlanetThoughtful
 Hi
 When I enter text as more than on paragrahs in a textarea field,The text
 is displayed in one solid block of text even though I have entered it in
 paragraphs.
 How I can  to insert line breaks in the text. (The values of textarea is
 stored in database and then displayed.)
 
 
 Bushra

Hi Bushra,

When displaying the data stored in your db from a textarea field, use the
nl2br() function.

This converts newlines in the data into br / html tags. You're currently
not seeing the paragraph breaks because the HTML specification doesn't
display newline / carriage returns when a page is rendered in a browser --
you have to specifically indicate where paragraph breaks should take place
using HTML tags.

Eg:

echo nl2br($data_from_db_entered_via_textarea);

See: http://au2.php.net/nl2br

Regards,

Murray
---
http://www.planetthoughtful.org
Building a thoughtful planet...

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



RE: [PHP] divide-column?

2005-08-30 Thread Murray @ PlanetThoughtful
 Hi there!
 
 How do I do a sort in PHP where a column in a db must be two other columns
 divided...`?

snip

Hi Gustav,

You should be able to use the divide operation in your query's ORDER BY
clause.

Eg

SELECT * FROM mytable ORDER BY (field1 / field2)

Regards,

Murray
---
Lost in thought...
http://www.planetthoughtful.org

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



RE: [PHP] divide-column?

2005-08-30 Thread Murray @ PlanetThoughtful
 Murray @ PlanetThoughtful wrote:
 Hi there!
 
 How do I do a sort in PHP where a column in a db must be two other
 columns
 divided...`?
 
 
  snip
 
  Hi Gustav,
 
  You should be able to use the divide operation in your query's ORDER BY
  clause.
 
  Eg
 
  SELECT * FROM mytable ORDER BY (field1 / field2)
 
 You might need to do:
 
 SELECT *, (field1 / field2) AS divField FROM mytable ORDER BY divField
 
 as I'm not sure if you can use expressions like that in the ORDER BY
 clause. Maybe...

Hi Jasper,

The statement I included worked in testing when run against my local
installation of MySQL.

Still, good to point out different options, in the event that something goes
awry.

Regards,

Murray
---
Lost in thought...
http://www.planetthoughtful.org

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



[PHP] Resizing thumbnails to the browser

2005-08-21 Thread Murray @ PlanetThoughtful
Hello All,

 

I have a series of thumbnails on my site of photos I've taken that are all
150px in width, but of variable height. I want to randomly display one of
the thumbnails each time the home page of my site is loaded in a column that
is 140px wide.

 

I'm wondering if anyone can point me at some code that would achieve this?
All of the thumbnails are in jpg format.

 

So, essentially, I'm trying to resize the thumbnails down to 140px wide
while maintaining the aspect ratio of the image's height.

 

I have GD enabled.

 

Any help appreciated!

 

Much warmth,

 

Murray

---

http://www.planetthoughtful.org

Building a thoughtful planet,

one quirky comment at a time.

 



[PHP] Class for creating RSS 2 feed?

2005-07-26 Thread Murray @ PlanetThoughtful
Hi All,

Just curious if anyone knows of an existing class that will take MySQL
records containing HTML and create a valid RSS 2.0 newsfeed from them?

Much warmth,

Murray
---
http://www.planetthoughtful.org
Building a thoughtful planet,
one quirky comment at a time.

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



[PHP] Translating english into amglish

2005-07-19 Thread Murray @ PlanetThoughtful
Hi All,

 

I'm based in Australia but my blog is predominantly read by Americans. I'm
wondering if anyone knows of a class that will translate Australian / UK /
Canadian / Whathaveyou English spellings into their American English
equivalents?

 

In other words, a class that will take a string with spellings such as The
colour of my neighbour's car, I recently realised, isn't grey after all and
will return The color of my neighbor's car, I recently realized, isn't gray
after all, and so on.

 

Given time I'm sure I could work out many of the transformation rules
myself, and implement them via regular expressions, but why reinvent the
wheel if someone has already done so?

 

Much warmth,

 

Murray

---

http://www.planetthoughtful.org

Building a thoughtful planet,

one quirky comment at a time.

 



[PHP] Re: Ouput HTML w/PHP

2005-06-30 Thread Murray @ PlanetThoughtful

Rick Emery wrote:

This leads (sort of) to a second question: how can I validate my HTML? 
My applications run on an intranet (with database access), so I can't 
use the W3C Validator to point to the URL. If I try to upload the file, 
the validator doesn't parse the PHP to get the HTML output (which is why 
I wonder if I'm not better writing the HTML and sticking PHP where it's 
needed). Is there a way for me to maybe use the PHP tidy functions on 
the string containing the HTML ouput to validate it?


If you run FireFox you can download the entirely invaluable Web 
Developer plugin, one feature of which (under the Tools button) is 
Validate Local HTML. This automates a post of your page to the W3C 
Validator, thus not requiring a URL visible to the ineternet. The only 
caveat being, you do still need internet access from your development 
machine for the post to be possible.


This is a great way for developers to validate the output of their code 
while it still resides on their local machines, prior to actually 
uploading the code to a public (and therefore visible) site.


Regards,

Murray

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



RE: [PHP] Re: security question...??

2005-06-22 Thread Murray @ PlanetThoughtful
 if i as a bank, refuse to allow you to signin to my server, because i
 detect
 that your client is not valid/legitimate, meaning i think it's been
 hacked,
 how have i trampled the rights of anyone. i haven't. will some customers
 run, sure.. perhaps.. will i potentially feel better. yeah. will i
 potentially have something that i can promote as an extra level of
 security
 that others don't have, maybe..

The banking industry is generally not slow in exploring security issues. In
point of fact, I know a guy here in Australia who works as a consultant for
the major banks on encryption protocols and strategies (and his
encryption-related background before working privately for the banking
industry is *scary*), so it should be a given that banks do care about
security both generally and specifically.

That having been said, you're waving the stick around by the wrong end. It
is fundamentally more important to a bank that general access to customer
records be protected, not to specific records relating to any one customer
because of that customer's negligence. By this I mean, most of their money
is invested in attempting to stop hostile attempts to gain access to
customer databases at their end, not at stopping hostile attempts to gain
access to customer data at the client's end. Why? Because that's where the
liability lies. Follow the money.

If you expose your own records by being foolish enough to run spyware-ridden
browser software, this is your own issue. Again, as I mentioned before, once
the data is in your hands, it's your responsibility. Behave responsibly or
stupidly / ignorantly, the choice is ultimately yours.
 
 let people continue to read/hear about massive losses of data and see what
 happens...

Again, the massive losses of data we generally hear about are not as a
result of sniffer programs sitting at the client end. They're ordinarily
about hackers gaining access to the data at the source, where thousands or
millions of customer records can be compromised, not at the client. This
doesn't mean it's not an issue, but that it's an issue that can't and won't
be addressed by anything more than public awareness campaigns.

Which is why I think you're wasting energy on this topic. I'd much rather
see you or anyone else, for that matter, putting this care and attention
into reviewing how secure your app is, even if it's for the 20th time, than
wondering how you go about hypothetically doing something that can't be
done, and which, to the best of anyone's knowledge, isn't going to be
practically implemented by anyone any time soon.

Obligatory, Oh my god, can you really believe they did that? story: 

From a consultancy project I was hired on to extend a retail web site. SSL
encryption where customer data was being entered or viewed? Check. Efforts
to negate the potential of SQL / code injection? Check. Backup strategy?
Daily dump of all records using PHPMyAdmin. From a directory where SSL was
not being enforced. All that customer data. All that effort to protect it
from being exposed to hostile eyes. From a directory where SSL was not being
enforced. Makes you want to weep.

Regards,

Murray

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



RE: [PHP] Re: security question...??

2005-06-20 Thread Murray @ PlanetThoughtful
 from my perspective, i strongly disagree...
 
 if you're going to be writing apps that deal with sensitive information,
 you
 better damm well give some thought as to how secure the client is, or even
 if the client is actually valid!

To the best of my knowledge, if you're developing an app that uses a web
browser as the client, then you better damn well give up on lying awake at
night worrying about this as an issue.

IE, which still holds something like 80+% market share of the browser base,
is full of many, many holes. I'm sure this isn't news to you. Unless you're
talking about exposing this sensitive data only to a user base within a
strictly maintained network environment, then you *must* assume that some of
the data can and perhaps will be compromised at the client end some of the
time. There are an amazing number of variables to take into account, all of
which, under most circumstances, are entirely out of your control. Which
version of which browser is being used? Which operating system? What service
pack and security updates have been applied? Which firewall software or
hardware is in use, if any? Which antiviral software is being used, and how
often is it being updated?

Another way of looking at this is, where does your responsibility as a web
developer end? Is it up to you to be concerned what happens to the data
once it has been requested by the client, as opposed to it being the
client's concern? What if a particular user is writing this data down in a
notebook and loses it on the train on the way home from work? What if
they're printing it out on a communal printer and other people are leafing
through it while waiting for their own print jobs to finish? What if they're
copying and pasting it into an email and blindly sending it to a huge
distribution list? What if this data is stored in their browser cache and
their laptop gets stolen? And on, and on, and on.

Even given your suggestion re: browser vendors exposing some method of
independently verifying 'unhacked' browsers, the implications would probably
be many and varied. Do you suddenly stop communicating with every browser
that has an unregistered 3rd-party add-on? What would be the effect on your
business if customers objected to you telling them what browser add-ons they
are allowed to use? How would that trickle over into open-source and smaller
start-up initiatives that a company like Microsoft (infamously open-source
opposed, according to the EFF) might not like to see thrive? Do you simply
consolidate browser market dominance, and stifle innovation, by introducing
a defacto licensing requirement? And on, and on, and on.

If you're honestly concerned about the security of the data once it has been
requested, then all I can suggest is, don't use a browser as the client.
Develop a purpose-built client that enforces more security than you can hope
for out of a browser. Even then, accept that the people who request the data
may not have even the slightest respect for your security concerns once it's
in their possession. 

As a last resort, and purely as a public awareness initiative, you might
want to invite your users to check their browser for known spyware, etc,
using a service such as DoxDesk (http://www.doxdesk.com/parasite/). I
believe this site uses an activex control to specifically check details in
IE. I have no idea how accurate it is. Alternatively, you could encourage
them to use an application such as Ad-Aware (http://www.lavasoft.de/) etc to
perform routine security checks. Beyond that, like I said, get some sleep.

Regards,

Murray

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



[PHP] Retrievable weather service info?

2005-06-14 Thread Murray @ PlanetThoughtful
Hi All,

Just wondering if anyone knows of a free weather service that can be
interrogated by PHP for information such as current temperature for a range
of cities around the world?

Regards,

Murray

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



RE: [PHP] Re: Retrievable weather service info?

2005-06-14 Thread Murray @ PlanetThoughtful
 http://www.weather.com/services/xmloap.html
 
 Weather XML Data Feed
 Now you can include weather from The Weather Channel in your own
 application by signing up for access to our XML data feed. We'll enable
 you to search for a location and to integrate current conditions and the
 forecast for today and tomorrow in your application - for FREE!
 
 
 Hope that helps
 
 Zac

Hi Zac,

Thanks for the suggestion! Having downloaded weather.com's xml sdk I'm a
little bemused to see that you are required to display referral links
provided by weather.com to make use of the service.

I'd be very happy to include a weather details provided by... link on the
page in question, but carrying unspecified referral links, particularly when
the application is simply my personal blog, is a little more of a constraint
that I'm comfortable with.

However and again, thank you for the suggestion!

Regards,

Murray

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



RE: [PHP] Re: Retrievable weather service info?

2005-06-14 Thread Murray @ PlanetThoughtful
 http://weather.noaa.gov/pub/data/forecasts/zone/

Hi Philip,

This would probably have been ideal for what I have in mind (don't mind
going to a little effort to parse the text files) but appears to be limited
to US information only, whereas I'm hoping to be able to randomly select a
city from around the world and present it's current time and weather
information.

Thanks for the suggestion, though.

Regards,

Murray

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



RE: [PHP] Re: reverse MD5 ???

2005-06-13 Thread Murray @ PlanetThoughtful
 In that framework there is no such thing as decrypting an MD5 digest,
 because an MD5 digest is not an encrypted version of the message to
 start with.  No amount of CPU power will change this basic fact --
 though CPU power can be used to do a brute force search for strings
 which will generate a given MD5 value.  However, as stated before, at
 current levels of computing power this is not feasible for messages
 beyond I think 7 or 8 characters long (don't quote me on that).

One real-world example of the potential weakness of 'md5 out of the box'
comes from a consultancy project I was involved in not so long back.

The app in question was storing the md5 value of 4-digit PINs in the
background database, and the owners of the app were quietly confident that
this meant the PINs were 'encrypted' and 'secure'.

Of course, there are only 10,000 possible PIN values between  and ,
regardless of whether or not they're stored in plaintext or md5 hashed form,
and I guess it took me less than 15 minutes to build a reference table of
all md5 hash values for the possible plaintext PINs and therefore
effortlessly retrieve the plaintext PIN values from their table. Imagine
their surprise.

And if *I* could do it...

Md5 is a very handy way of 'securing' [1] password information, but only
when the plaintext value offers enough possible variation in length and / or
value to make building a 'possible variations' lookup table a difficult
proposition.

Regards,

Murray


Footnotes:

[1] Without wanting to get into a technical debate of exactly what
constitutes 'secure' when it comes to hashing / encrypting sensitive
information

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



RE: [PHP] Re: reverse MD5 ???

2005-06-13 Thread Murray @ PlanetThoughtful
 Amazing.
 
 Thanks for sharing that. It's a great example. :-)

You're very welcome! If it helps just one other developer avoid the same
pitfall, then today is a very good day. :-)

 Exactly, and this is why it's a good practice to use a seed when you
 generate MD5s for passwords.

Which is exactly what I suggested, and what they ended up implementing,
thanks to the fact that I could provide them with the original plaintext PIN
values for the existing records.

Still, once I'd had a chance to look at the plaintext PINs, it was
depressing to notice the frequency of 'easy' PIN values, such as '',
'1234', '' etc.

Even with a seed, those values would have been relatively easy to guess at
with frequency analysis, and it goes beyond my meager hostile decryption
skills to guess at whether that made deriving the seed any easier or not.

I suggested implementing a class that randomly selected from somewhere
between 5 to 10 possible seed values when hashing the PIN for storage, which
would have meant simply using all 5 or 10 seeds when comparing the PIN for
subsequent validation, to reduce the frequency of hash-to-easy-PIN
repetition, but it hadn't been implemented by the time my consultancy ended
and I'd be willing to bet a year's pay it, or any other method of providing
some sort of buffering against frequency analysis, hasn't been since.

Of course, there's a whole conversation to be had regarding the fact that if
your db server has been compromised to the point where the contents of
tables are exposed, then it's reasonable to at least speculate (depending on
your server setup and method by which it was accessed) that perhaps your
entire app has been compromised, and your seed values may now be known to
the hostile entity as well.

Still and all, there's absolutely no reason to make the job of compromising
your data any easier on a hypothetical hacker than is within your level of
competency as a developer. Adding a seed value to md5 hashes is a simple and
effective method under most circumstances that even beginner to intermediate
developers can employ. In other words, It Is A Very Good Thing. ;-)

Regards,

Murray

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



RE: [PHP] formatting paragraphs in to strings

2005-06-13 Thread Murray @ PlanetThoughtful
 Use the PHP str_replace function before writing it to the DB.  Replace
 all \n characters with an empty string .
 
 http://us2.php.net/manual/en/function.str-replace.php

I think it might be better to replace all \n characters with spaces  ,
otherwise you will end up with sentences that have no space break between
them.

Ie:

original text
This is the first sentence.

This is the second sentence.
/original text

...would become:

replaced text
This is the first sentence.This is the second sentence.
/replaced text

Regards,

Murray

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



RE: [PHP] formatting paragraphs in to strings

2005-06-13 Thread Murray @ PlanetThoughtful
 Good point.  Only problem is, if someone hit enter a-million times,
 you would end up with a-million spaces where the \n characters were.
  To take care of that repetition, maybe something like:
 
 
 while (strpos($textarea_text, \n\n)) {
  .
 }
 
 
 would be one way you could do it.

Ordinarily most browsers render multiple consecutive spaces as a single
space. This doesn't mean that it's not a good idea to remove them, just that
not doing so shouldn't effect the way the text is displayed in the div tag,
as the original poster mentioned was his intention.

Regards,

Murray

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



RE: [PHP] ampersands in href's

2005-06-04 Thread Murray @ PlanetThoughtful
 If I want to make a link to a URL which includes some GETs can I just do:
 
 a href='{$_SERVER['PHP_SELF']}?p={$p}c={$s}' ... etc etc
 
 or must I escape the ampersand somehow?

Depends very much on the document type of your page. Valid XHTML
(transitional, at least), for example, doesn't like single ampersands in a
href= links. For XHTML, you need to replace s with amp;s.

So the following link:

a href='http://www.somewhere.com/index.php?id1=1id2=2'Something/a

...should be changed to:

a href='http://www.somewhere.com/index.php?id=1amp;id=2'Something/a

Regards,

Murray

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



RE: [PHP] Frames or iframes? (Basically The devil or deap sea or A rock and a hard place etc) - - - - (0T)

2005-06-04 Thread Murray @ PlanetThoughtful
 Since its a forum and she is not doing any advertising its important the
 search engines index the site
 properly or shes going to have a big forum with no visitors.
 Then I read that the search engines dont like frames muchso I was
 thinking of using iframes and
 then I read about the evils of iframes...so I thought I'll ask you guys
 for your opinions/suggestions
 as I'm dead outa ideas and a bit confused...any alternate ideas too would
 be
 appreciated.

As a compromise solution, you could greet visitors to the forum with a
welcoming 'splash' page that displays your flash animation etc (please,
please put a 'skip intro' link for the sake of repeat visitors) and then
pass to your forum page(s). You could even put a static jpg at the top of
the forum of the final image (ie once all that funky animation has played
out) of your flash file, if you want to carry it over for a consistent look
/ feel.

Regards,

Murray

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



RE: [PHP] Re: Best way to use other objects within classes?

2005-06-03 Thread Murray @ PlanetThoughtful
 If you're developing with PHP5, but the production environment is PHP4
 then at the top of each script you probably want to add:
 
 ?php
 
 ini_set('zend.ze1_compatibility_mode', 1);
 
 ?
 
 This way you will have objects default to pass by value instead of by
 reference and you don't end up deploying to production server with some
 really hard-to-find dereferencing problems.

Hi Jason,

Not a bad tip, thank you! However, I've been, to the best of my knowledge,
explicit in passing by reference in my code wherever I've needed to access
objects within classes etc.

Many thanks,

Murray

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



[PHP] Best way to use other objects within classes?

2005-06-02 Thread Murray @ PlanetThoughtful

Hi All,

I'm using the MDB2 object to access my MySQL database. I have a number 
of classes that perform page-building activities that need db access, 
and I'm wondering what the best way to expose the MDB2 object to them is?


(Note: my development environment is PHP 5.0.3, but the production 
environment is 4.3.10. This is my first project built with 5.x local and 
4.1.x remote, so if anyone with more experience spots any fatal flaws 
where I'm using 5.x specific methods etc, I'd appreciate knowing about them)


Currently, I'm instantiating the MDB2 class in my main page, then 
passing it as an object reference to each of the other classes that 
require it.


A simple representation of my main page and a class would be:

?
 $db = connectMDB2(); // function that returns instantiated MDB2 object

 $comments = new displayComments(); // class that performs displaying 
of comments

 $comments-set_db($db); // passing the MDB2 object to the class
 $comments-doSomethingElse();
?

The displayComments() class might then look something like:

class displayComments{
private $db;

public function set_db($db){
$this-db = $db;
}

public function doSomethingElse(){
$sql = SELECT something FROM sometable;
$rs = $this-db-query($sql);
while ($row = $rs-fetchRow(MDB2_FETCHMODE_OBJECT)){
echo $row-something.br /;
}
$rs-free();
}   
}

My main page calls on at least 8 or 9 such classes as it is being built, 
and I'm concerned that I may not be handling the MDB2 object in respect 
to them in the most efficient way possible. In a way, I guess this isn't 
 specifically about the MDB2 package, but more about how to handle 
objects when they are required within classes.


I'd very much appreciate any comments or advice anyone might be able to 
give.


Much warmth,

Murray

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



Re: [PHP] Best way to use other objects within classes?

2005-06-02 Thread Murray @ PlanetThoughtful

Greg Donald wrote:

On 6/2/05, Murray @ PlanetThoughtful [EMAIL PROTECTED] wrote:


   private $db;



PHP4 doesn't have member visibility.



Hi Greg,

Thanks for this tip!

Regards,

Murray

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



RE: [PHP] Replacing 2 strings

2005-05-31 Thread Murray @ PlanetThoughtful
 ?
 
 function replace($string){
   preg_match(/^\^([a-zA-Z]+?)_([a-zA-Z]+?)/, $string, $matcharr);
   $string = str_replace($matcharr[0], $matcharr[1] .   .$matcharr[2]
 . :, $string);
   return $string;
 
 }
 
 $string = ^JIM_JONES Leicester, 1720.  Oxford, 1800 CONFIRMED: meeting
 at
 19.10;
 echo replace($string);
 
 ?
 
 One of the small benefits of this solution is that Will doesn't need to
 know
 what is contained in the target substring beforehand.

I should get into the habit of listing the assumptions my code makes.

In the above example, the following assumptions are present:

- The target substring (in this example, ^JIM_JONES) must *always*
appear at the beginning of the string for the function to perform its task

- The target substring will *always* begin with ^, will feature a _
between the two name elements, and will conclude with 

- There will only be two name elements within the target substring (ie will
match ^JIM_JONES and ^MARY_BETH but will not match ^JIM or
^MARY_BETH_JONES)

- The function will only replace the first incidence of the target
substring. In the eventuality that the target substring value appears
multiple times in the string being processed, all other instances will be
left unchanged.

- All other contents of the string being processed can vary without impact
on the function.

Regards,

Murray

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



RE: [PHP] Re: Free penetration test

2005-05-30 Thread Murray @ PlanetThoughtful
 For me, of course there is nothing wrong on the PHP Group help
 themselves making money with referrals. My point is that it is pretty
 common to not distract people with the details of who gets what with
 referrals because it does not change anything for who follows a link
 with our without the referral id. The price and the service is the same.
 
 
 What matters is who wants free help can get free help even if that help
 provides some benefit to the person that is providing it. If a person
 that gets free help does not like that whoever provides the help
 benefits from that too, that person is just being ungrateful and so does
 not deserve to be helped.

Sweet Mamma, are we *still* arguing about this?

Manuel (and whomever else): in general it is A Very Good Idea to declare
whenever you have a commercial interest in a solution you provide in a forum
such as this one.

The problem, whether you agree or not, is that others will ask themselves,
Did Manuel (or whomever) supply this link because it is the best solution
he (or she) knows of to my problem, or because it is the only one from which
he (or she) can earn money?

It boils down to a question of motive: are you trying to help, or to use the
forum as a method of earning extra income, or both?

I tend to think the best of people -- I assume you offered the link in good
faith, and you've said as much in posts since. That doesn't negate the fact
that the appropriate place to explain your commercial affiliation is at the
point where you originally supply such a link. It isn't hard. A simple
paragraph similar to the following would be more than adequate:

Please note: I have an affiliation relationship with this site. I picked it
because it was the best I found when I was looking for solutions to the same
problem you're asking about, and share it with you for the very same
reason.

See? Easy, and no-one questions your motives.

To everyone else: many if not most of us take direct commercial benefit from
being involved in this forum. I know I do. I ask questions about problems I
can't solve on my own. I follow and keep track of solutions to other
people's problems that seem innovative and better formulated than my own
methods of dealing with those problems. I keep my general skills sharpened
by helping people solve problems in areas where my skills are relatively
strong. It would be naïve of me not to admit that this has a direct impact
on my earning potential.

As a group of professionals and semi-professionals (and even those amongst
us who are simply learning or developing PHP skills out of general
interest), it should be enough to say: Hey, that wasn't the best way to
handle this. In future, you'd probably cause less aggravation by doing the
following... And then move on. The person doesn't have to agree. You've
done your part for peace-as-we-know-it in the PHP forum.

If that simply isn't good enough for you in situations such as these, if you
have to argue with Manuel (or whomever) until we've all but forgotten what
the original freaking question was that began the holy war, then can I make
a suggestion? If you happen to be a professional or semi-professional PHP
programmer, you might want to think about tagging any and all posts you make
to this forum about problems you're having with: I earn money from PHP
programming. If you help me with this problem it will have a commercial
benefit to me.

And, really, wouldn't that be ridiculous?

So, seriously, let's move on. At least until the next time someone posts an
affiliation link without declaring their commercial interest, and then we
can all look forward to having this argument again.

Regards,

Murray

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



RE: [PHP] Replacing 2 strings

2005-05-30 Thread Murray @ PlanetThoughtful
 Someone much more clever that I can probably come up with something much
 cleaner and efficient but This works...

Definitely not more clever and arguably not more efficient, but a different
way of handling this might be:

?

function replace($string){
  $string = preg_replace(/(|\^|)/, ,$string);
  $string = str_replace(_,  , $string);
  $string = ucwords(strtolower($string));
  $string = str_replace( , -, $string);
  return $string;
}

echo replace(^JIM_JONES);

?

Regards,

Murray

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



RE: [PHP] Replacing 2 strings

2005-05-30 Thread Murray @ PlanetThoughtful
 AHHH! ucwords(); I probably looked right at it a million times.. I knew
 there had to be something to do that

Lol, I know that feeling well!

One thing, btw, looking at the solution you provided. Once you'd
preg_split()ed the string into component words, you could have simply
applied strtoupper() directly to the first character of each word in your
foreach loop.

As an example:

?
  $string = this;
  $string{0} = strtoupper($string{0});
  echo $string; // should return value of This
?

Just thought it was worth mentioning.

Regards,

Murray

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



RE: [PHP] Replacing 2 strings

2005-05-30 Thread Murray @ PlanetThoughtful
 This is a great help, thanks to both.  One question I have though.
 How do I just leave the formatting as is?  In the loop you gave me,
 Brian...:

[snippage]
 
 I can't see how I can disregard strtolower without disrupting the rest
 of the function!  My problem is $string contains a whole load of text,
 the formatting of which needs to be retained...

Hmmm. Methinks your problem is a little more complex than originally
presented.

Can you give us a pseudo-example of what the string might actually contain?
I think both Brian and I took your original message to mean that your string
would ONLY contain a value like ^JIM_JONES, but from this message I get
the sense that the value you're trying to target may be buried in a string
with other text on either side?

Again, an example that is as close to your real-world needs as possible
would be very helpful.

Regards,

Murray

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



RE: [PHP] Replacing 2 strings

2005-05-30 Thread Murray @ PlanetThoughtful
 ?php // this will produce JIM JONES
 
 function replace($string, $search)
 {
 $string = strstr($string, $search)
 $string = preg_replace(/(|\^|)/, ,$string);
 $string = str_replace(_,  , $string);
 return $string;
 
 }
 
 $text = 'My name is ^JIM_JONES and I like ice cream';
 $search_string = '^JIM_JONES';
 echo replace($text, $search_string);
 
 ?

This is a pretty good solution, however for the sake of paranoia about
potentially removing characters that Will may not want targeted by the
function (i.e., what if , , ^ or _ legitimately appear later in
the string and are accidentally removed?), I'd do something like the
following:

?

function replace($string){
preg_match(/^\^([a-zA-Z]+?)_([a-zA-Z]+?)/, $string, $matcharr);
$string = str_replace($matcharr[0], $matcharr[1] .   .$matcharr[2]
. :, $string);
return $string;

}

$string = ^JIM_JONES Leicester, 1720.  Oxford, 1800 CONFIRMED: meeting at
19.10;
echo replace($string);

?

One of the small benefits of this solution is that Will doesn't need to know
what is contained in the target substring beforehand. 

Regards,

Murray

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



RE: [PHP] Regex question: replacing incidences of character when not enclosed within HTML tags? (somewhat solved)

2005-05-29 Thread Murray @ PlanetThoughtful
 So, thinking about it a little more, I decided what I was looking for was
 a
 regular expression that would allow me to replace any incidences of
 hyphens
 when not contained within tags (i.e., when not contained between  and
 ).
 
 And this is where things have ground to a halt.

Hi All,

After toying with this for several hours I decided to give up on trying to
work out a way to achieve this via a single regular expression replacement.

My simpler 'solution' now is to pull out all text not contained within tags
using preg_match_all(), and run a str_replace() across these values to
replace any incidences of hyphens, and then another str_replace() to replace
the content with the substring where hyphens were found.

So, something like:

?
preg_match_all(/(^|)(.+?)(|$)/m, $text,$hypharr);
for ($i=0; $i  count($hypharr[0]); $i++){

$rephyph = str_replace(-,-span style='font-size: 0px;'
/span, $hypharr[0][$i]);
if ($rephyph  $hypharr[0][$i]){
$text= str_replace($hypharr[0][$i],$rephyph,$text);
}
}

?

This seems to achieve what I'm looking for, ie replacing hyphens when not
contained in HTML tags.

Regards,

Murray

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



[PHP] Regex question: replacing incidences of character when not enclosed within HTML tags?

2005-05-28 Thread Murray @ PlanetThoughtful
Hi All,

I have content that contains several lengthy hyphenated sentences, such as:

This-is-a-sentence-in-which-all-the-words-are-hyphenated.

I've noticed that some (maybe all?) browsers, particularly Firefox, will not
wrap long strings of hyphenated words when they are contained in a DIV tag
-- instead, the sentence simply runs out across the right border of the DIV
and overlaps any content to the right.

After some experimentation, I discovered that a hack that seems to behave
well in Firefox, Opera, and IE6 is to replace all incidences of the hyphen
(-) character with -span style='font-size:0px;' /span. This
effectively creates a zero-width space character after each hyphen and
allows the sentence to wrap as desired.

My dilemma is that while I want to replace any hyphens with the above hack
when and where they appear within normal sentences, I don't want to replace
them when and where they appear within HTML tags.

So, imagine I have a string that contains:

div style='text-decoration: none;
font-size:11px;'This-is-a-sentence-that-contains-hyphenation. This is a
sentence that doesn't contain hyphenation. This is a a
href='http://www.nowhere.com/-4484784/index.html'link/a that will take
you span style='font-weight: bold;'nowhere/span./div

I managed to build a replacement regular expression that would ignore any
hyphenated strings that were terminated by a colon (:) character (which
effectively leaves inline style attributes in DIV and SPAN blocks
untouched).

?
$thingy = preg_replace(/(-)(?![\w-]+?:)/i, \$1span
style='font-size:0px;' /span, $whatever); ?

This seemed to work well in most circumstances, however, in testing I
discovered several incidences of a href= urls that also contain hyphens
(in particular, some that lead to Amazon.com).

So, thinking about it a little more, I decided what I was looking for was a
regular expression that would allow me to replace any incidences of hyphens
when not contained within tags (i.e., when not contained between  and
). 

And this is where things have ground to a halt.

I'm wondering if anyone can give me some help with this? I've tried to find
a solution via google, but most regex examples dealing with HTML tags are
concerned with finding tags and their contents, not with finding specific
instances of characters not contained within tags.

Any help appreciated!

Much warmth,

Murray

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



RE: [PHP] Very long delay posting to php-general (might be OT)

2005-05-25 Thread Murray @ PlanetThoughtful
  I don't know WHY posts take hours to get through, but I'm not honestly
  seeing it as a problem personally.
 
 
 I see one problem, some questions get the same answer from several
 people. This increases the list traffic without any benefit.

That, of course, is exacerbated by the delay. If it takes 4 hours for
responses to appear, it will seem to others on the list in that time that
no-one else has responded.

And I'd personally rather 'too many' people replied, than too few or none at
all.

Murray

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



RE: [PHP] Regex nightmares

2005-05-24 Thread Murray @ PlanetThoughtful
 [Course, when you *DO* need RegEx it's *more* than a bit of a headache.
 More like a migraine :-)]

One of these days I will truly master regular expressions. After that,
enlightenment should be easy.

Regards,

Murray

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



[PHP] db aware text editor? (slightly OT?)

2005-05-24 Thread Murray @ PlanetThoughtful
Hi All,

I'm wondering if anyone knows of a 'db aware' text editor? By 'db aware', I
mean one that can pull a recordset back from a local MySQL server and edit
the content of fields much like a standard text editor does with files.

I could probably build myself a simple one in Java, but before I undertake
that task I thought I'd ask if any of the better known editors are capable
of doing this, as I'd rather be able to use a feature-rich editor (ie one
that has features such as regex search and replace, macro recording etc)
than a hand-built alternative.

Much warmth,

Murray

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



RE: [PHP] html editor written in PHP

2005-05-19 Thread Murray @ PlanetThoughtful
 Has anyone seen an example of a HTML editor written in PHP (no JS)?
 You know the ones - for adding HTML tags to a text field, etc.
 
 Thanks!

You've already received a number of responses indicating that it's not
possible to have a pure PHP browser enabled HTML editor, mainly due to the
fact that the editing itself takes place on the client (which requires a
client-side language, such as JavaScript), while PHP is only run at the
server.

One lateral solution, however, would be using something like the PHP ports
of either the Markdown or Textile classes to provide HTML markup using a
simpler syntax.

Using Markdown as an example, you would type:

_This sentence will be displayed with emphasis_

When you next retrieve this content and pass it through the Markdown class,
it automatically becomes:

emThis sentence will be displayed with emphasis/em

The differences between the two classes is that Textile is more featured,
but in my personal opinion less intuitive, while Markdown is obviously less
featured, but easier to use 'without thinking about it' as you go about
generating content. [1]

Both of these classes are used extensively to provide content markup in
blogging systems such as MovableType and WordPress, etc. There may be
similar classes out there (another one is BBCode, which is popular on forum
applications such as Invision PowerBoard).

PHP Markdown: http://www.michelf.com/projects/php-markdown/

PHP Textile: http://jimandlissa.com/project/textilephp

Hope this helps,

Murray

[1] Note: which one you might use would depend on how comfortable you are
with their applicable syntaxes and how varied your markup needs are.

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



RE: [PHP] Image Verification - Problems in Safari, Mac OS X

2005-05-19 Thread Murray @ PlanetThoughtful
 But here's the problem that came afterwards in IE !
 IE is storing the image in it's cache.. And it's displaying the same image
 on the verification page whether you use the BACK button, FORWARD button,
 or
 actually go through the website and land back on the verification page. So
 in IE, right now, unless you actually HIT the REFRESH button, it's not
 changing the image as it's picking up the image from the Cache.
 
 Now I'm not sure what exactly I should do to fix this whole situation.

Try forcing the browser to bypass the cache by adding the lines at the
following link to your page:

http://www.faqts.com/knowledge_base/view.phtml/aid/21068/fid/51

Regards,

Murray

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



[PHP] PHP-GTK, or something else, for desktop app development?

2005-05-16 Thread Murray @ PlanetThoughtful
Hi All,

I'd like to do some desktop app development and I'm looking for others'
thoughts on whether PHP-GTK is a suitable environment in which to work?

Years ago I developed desktop apps in Access / VB6, but it's been long
enough now, and VB in particular has changed so much in the intervening
time, that I'd have to relearn these anyway, so it seems like a good time to
either consolidate my PHP coding or to pick up some other language. Not to
mention that Access is entirely despicable for any purpose, desktop app
development included [1].

I'm wondering if PHP-GTK is mature / featured enough to handle a relatively
complex desktop app project, using features like table grids for displaying
/ editing data stored in a MySQL backend and so on.

My other alternative is to bite the bullet and learn something like Java,
though I assume my learning curve would be steeper and more time-consuming.
I pick Java because a) Everyone Seems To Love Javatm, and b) there appear
to be at least a couple of decent free Java IDEs available in NetBeans and
Eclipse (and maybe others that I don't know about).

In essence, I'm looking for a desktop app development environment that is
featured, connects well to MySQL, and is relatively painless to learn. Java
may not suit the last of those criteria, but I don't know enough about it at
this point to be scared of it if it is painful to learn.

Anyone have any thoughts to share about PHP-GTK and / or other desktop app
development environments that might be more suitable? Freeness of
development tools is a big plus to me in this, if that needs to be
explicitly said.

Much warmth,

Murray

[1] Just my opinion. I know I'd get a healthy argument from several
developers that I know.

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



RE: [PHP] dynamically updating site

2005-05-16 Thread Murray @ PlanetThoughtful
 I looking for a way to update certain parts of a site that is highly
 dynamic. I've tried creating static files via cronjobs then including
 them,
 but it is a pain to do. for instance, i have a news page that utilizes
 mysql, rather than query the DB on each page load i would like to have it
 update at say 5 minute intervals.. not sure if this is possible to do
 without generating static files..
 
 any suggestions?

I can't see why you couldn't have a class that you call at the top of the
page that checks the date/time of the 'static' page, generates the content
into the static page from the DB if older than 5 minutes and then passes to
displaying the content of that static page.

In pseudo-logic, this would be something like:

If datetime_of_static_news_page  5 minutes ago:
Replace content of static news page with data from db
End if
Display content of static news page

I doubt there'd be significant overhead in the static page generation, since
it would only be called once per 5 mins. Though, I guess it depends on
exactly how much data / markup / etc is going into that page, and the
tradeoff between writing the file and then displaying it versus whatever
performance concern you're attempting to address in hitting the db each time
the page is viewed.

Regards,

Murray

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



RE: [PHP] Add to array problem

2005-05-16 Thread Murray @ PlanetThoughtful
 I'm having a little problem adding to an array. Each time I add to an
 array it wipes what was previously added. I'm using array_push().
 
 $items=array();
 $items=array_push($items, $_POST[whatever]);
 
 I'm missing something easy.

Try:

$items=array();
array_push($items, $_POST[whatever]);

In other words, remove the $items= in front of array_push(

Regards,

Murray

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



RE: [PHP] regex question

2005-05-16 Thread Murray @ PlanetThoughtful
 What pattern can I use to match ONLY single occurrences of a character in
 a string.
 
 e.g., Some text @ and some mo@@re and [EMAIL PROTECTED], etc @@@.
 
 I only want the two occurrences with a single occurrence of @.
 
 @{1} doesn't work; there are 4 matches.

/[EMAIL PROTECTED]@[EMAIL PROTECTED]/ seems to do what you're looking for. In 
other words, match the
@ symbol where it is not preceded or followed by another @ symbol.

To test, try:

preg_match_all('/[EMAIL PROTECTED]@[EMAIL PROTECTED]/','Some @ text with the @t 
sym@@bol  @@@',
$thing, PREG_OFFSET_CAPTURE); 

print_r($thing);

There may be a more intuitive way to do this, but at least it seems to work.

Regards,

Murray

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



RE: [PHP] regex question

2005-05-16 Thread Murray @ PlanetThoughtful
 What pattern can I use to match ONLY single occurrences of a character in
 a string.
 
 e.g., Some text @ and some mo@@re and [EMAIL PROTECTED], etc @@@.
 
 I only want the two occurrences with a single occurrence of @.
 
 @{1} doesn't work; there are 4 matches.
 
 Thanks

Please ignore my last email re: your question. I realized that the negation
of the range containing the @ would end up capturing unwanted characters.

As an alternative, try the following:

preg_match_all('/(?!@)@(?!@)/','Some @ text with the @t sym@@bol  ',
$thing, PREG_OFFSET_CAPTURE); 

print_r($thing);

Hope that's a little more relevant to your question.

Regards,

Murray

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



RE: [PHP] regex question

2005-05-16 Thread Murray @ PlanetThoughtful
 Try (for example if character was A) ...
 
 ([^A]|^)A([^A]|$)
 
 This matches four cases:
 A is at beginning of string and there is another letter after it,
 A has a letter before it and a letter after it,
 A is at end of string and there is a letter before it,
 or A is the only character in the string.

I think this has the same problem that my first attempt at this regex
experienced.

I.e., it will correctly 'find' single instances of 'A', but it will 'match'
against unwanted characters on either side of each 'found' 'A' because they
are not-A.

For example, the following:

preg_match_all('/([^A]|^)A([^A]|$)/','A sentence with instAnces of AAA
chArActers', $thing, PREG_OFFSET_CAPTURE);

print_r($thing);

produces:

Array
(
[0] = Array
(
[0] = Array
(
[0] = A
[1] = 0
)

[1] = Array
(
[0] = tAn
[1] = 19
)

[2] = Array
(
[0] = hAr
[1] = 34
)

)

[1] = Array
(
[0] = Array
(
[0] =
[1] = 0
)

[1] = Array
(
[0] = t
[1] = 19
)

[2] = Array
(
[0] = h
[1] = 34
)

)

[2] = Array
(
[0] = Array
(
[0] =
[1] = 1
)

[1] = Array
(
[0] = n
[1] = 21
)

[2] = Array
(
[0] = r
[1] = 36
)

)

)

Note the multiple instances of characters other than 'A' in the array. Also
note that the 4th qualifying 'A' (the second 'A' in 'chArActers') is missed,
because the 'r' is already part of the capture of the preceding 'A').

On the other hand, the following:


preg_match_all(' /(?!A)A(?!A)/','A sentence with instAnces of AAA
chArActers', $thing, PREG_OFFSET_CAPTURE);

print_r($thing);

produces:

Array
(
[0] = Array
(
[0] = Array
(
[0] = A
[1] = 0
)

[1] = Array
(
[0] = A
[1] = 20
)

[2] = Array
(
[0] = A
[1] = 35
)

[3] = Array
(
[0] = A
[1] = 37
)

)

)

Here, only the target characters are matched, without the confusion of extra
unwanted characters. All 4 target 'A's are caught, because the patterns on
either side of the 'A' in the regex pattern are non-capturing. So, basically
this is employing a non-capturing negative look-behind and a non-capturing
negative look-ahead, rather than capturing negated character classes.

I've probably only managed to confuse things more than they were, but I'm
hoping some of what I've said above makes sense (to me, if no-one else).

Regards,

Murray

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



RE: [PHP] marking words bold

2005-05-11 Thread Murray @ PlanetThoughtful

 I am trying to mark words inside a sentence bold. Problem is, if there is
 an
 overlap it does not work anymore.
 I am using this code:  $t = str_replace($word, b$word/b, $text);
 
 For eample:
 Mark those words bold: adventure in singapore
 Text: My adventure flying to singapore
 
 The problem lays in the word in. The code I use does produce following:
 bsbin/bgapore/b
 which of course does not work properly.
 
 Does anybody have a good sugestion on how to improve this?`
 

Hi Merlin,

Sounds like you need to use preg_replace, specifically testing for word
boundaries. See http://au2.php.net/preg_replace and
http://php.mirrors.ilisys.com.au/manual/en/reference.pcre.pattern.syntax.php
for the \b word boundary syntax.

Not tested, but something like the following would probably be along the
right lines:

$thing = preg_replace('/\bin\b/i','bin/b','adventures in singapore');
echo $thing;

produces: adventures bin/b singapore, ignoring the 'in' characters
within 'singapore' because they don't form a word boundary

Hope this helps,

Much warmth,

Murray

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



RE: [PHP] marking words bold

2005-05-11 Thread Murray @ PlanetThoughtful
 Include a space in your str_replace statement.
 
 For instance
 
 $t = str_replace( $word , B $word /B, $text);
 
 That should prevent the problem your having and ensure only individual
 words
 are bolded.

Not the best solution if Merlin's code needs to account for the possibility
of target words being preceded or followed by punctuation.

Consider wanting to bold the word tour in the following sentence:

$text = At this point we will commence our tour, guided by an operator
recommended by the department of tourism.;

$t = str_replace( tour , btour/b, $text);

... would fail, because the word tour in the sentence is immediately
followed by a comma.

$t = preg_replace(/\btour\b/, btour/b, $text);

... would work, because the comma forms a word boundary, with the added
benefit that the tour in tourism would also remain untouched because
there is word text directly after the r in tourism.

Note: I realize your solution fits the example Merlin gave, but preg_replace
offers a great deal more flexibility if you are not aware, ahead of time,
exactly what the target string will contain.

Just thought it was worth mentioning.

Much warmth,

Murray

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



RE: [PHP] expand array into function arguments?

2005-05-11 Thread Murray @ PlanetThoughtful
 -Original Message-
 From: Christopher J. Bottaro [mailto:[EMAIL PROTECTED]
 Sent: Thursday, 12 May 2005 5:13 AM
 To: php-general@lists.php.net
 Subject: [PHP] expand array into function arguments?
 
 You can do this in Python:
 
 code
 def myFunc(arg1, arg2, arg):
   #do something
 
 myList = [1, arg, 5]
 myFunc(*myList) # calls myFunc(1, arg, 2)
 code
 
 Can that be done in PHP, and if so, how?

Don't know if there's a better solution, but at the very least you could put
the values in an array, and pass the array to the function.

$arr = array();
$arr[] = First;
$arr[] = Second;
$arr[] = Third;

$val = my_function($arr);

function my_function($arr_in){
// do something with $arr_in[0];

// do something with $arr_in[1];

// do something with $arr_in[2];
}

Note: if you wanted the function to be able to change the actual values in
the array, you would need to pass it by reference rather than by value, eg:

Function my_function($arr_in){ etc...

The ampersand before the variable name in the function declaration indicates
the variable is being passed by reference.

Just a thought.

Much warmth,

Murray

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



RE: [PHP] Strange characters

2005-05-11 Thread Murray @ PlanetThoughtful
 I dunno what the hell 0x96 is in MS Word, but if you want a dash, use an
 ASCII dash and be done with it. :-)
 
 Or, if you REALLY want that ASCII extended Linux dash (assuming it
 exists) I'm sure you can strtr(0x96, 0xYY, $string) and get it.
 
 Then it won't work on Windows, of course, but who cares about Windows?

Cough. I care about windows. I hate windows, but I care about it.
Unfortunately, I get paid a lot of money to care about it. Which I also
hate. It would be nice to be poor and not have to care about windows.

Hang on just a minute...

Much warmth,

Murray

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



[PHP] Help with regex: breaking strings down to 'words' and 'phrases'

2005-05-10 Thread Murray @ PlanetThoughtful
Hi All,

 

I'd very much appreciate some help building a regular expression for
preg_match_all that can differentiate between 'words' and 'phrases'.

 

For example, say I have a string that contains: 'this is an example of a
phrase'

 

I'd like to be able to break that down to:

 

this

is

an

example of a phrase

 

My current preg_match_all regex:

 

preg_match_all('([\w\-]+|[\(]|[\)])',this is an \example of a
phrase\',$arr);

 

returns the following:

 

Array

(

[0] = Array

(

[0] = this

[1] = is

[2] = an

[3] = example

[4] = of

[5] = a

[6] = phrase

)

 

)

 

Note: I'm using this to break elements of a string down to build an sql
string, which is why I'm looking for ( and ) characters (ie the
[\(]|[\)] part of the regex) and maintaining them in the array. A
real-world example of the the value being supplied to the regex might be
completed and January 2005 and not (store or online) etc. I already have
the logic to handle and, or, not and () but haven't been able to
figure out how to maintain substrings in quotes as a single value in the
array.

 

Any help appreciated!

 

 

Much warmth,

 

Murray

 



RE: [PHP] Help with regex: breaking strings down to 'words' and 'phrases'

2005-05-10 Thread Murray @ PlanetThoughtful
 On Wed, 11 May 2005, Murray @ PlanetThoughtful wrote:
 
  Hi All,
 
  I'd very much appreciate some help building a regular expression for
  preg_match_all that can differentiate between 'words' and 'phrases'.
 
  For example, say I have a string that contains: 'this is an example of
 a
  phrase'
 
  I'd like to be able to break that down to:
 
  this
 
  is
 
  an
 
  example of a phrase
 
 
 I haven't thought this through fully, but what if you exploded the string
 on  into an array.  Then loop through the array and for every even
 element, explode on a space, otherwise just store the whole string into
 the new array.

I think I *may* have solved this at my end.

The following statement seems to work:

preg_match_all('/([\w\-]+?|[(]|[)]|\.+\)/U',strtoupper($prep_sql),$sqlarr)
;

I need to test it out with a whole series of different possible combinations
to see if it behaves the way I want it to, but so far the results are good.

If anyone can see any flaws, I'd love to know about them!

Many thanks,

Murray

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



[PHP] Templating systems for single developers?

2005-05-10 Thread Murray @ PlanetThoughtful
Hi All,

Given that templating seems to be a hot topic at the moment, I'm wondering
if anyone here uses templating in a single developer environment, and why if
so?

I've looked at various template systems from time-to-time but I've always
come away thinking, 'yep, I can see the point in a team environment,
particularly one that mixes designers and coders, but what would be the
benefit to a lone developer like me?'

So, if anyone out there uses a templating system (ie Smarty, PHPSavant etc)
and they don't work in a team environment, I'd love to hear what benefits
you derive from so doing.

Much warmth,

Murray

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



[PHP] Any alternative to POST method FTP uploads from client computer?

2005-05-08 Thread Murray @ PlanetThoughtful
Hi All,

 

I need to implement the ability to ftp upload files from client machines via
a form in a web application I'm developing.

 

From reading the PHP help, all I can find to perform this is the POST method
for handling file uploads
(http://au2.php.net/manual/en/features.file-upload.php).

 

From my perspective, while this seems to work, there are a couple of
drawbacks, most important of which is that it seems you can only do
comparisons of the uploaded file, against the potential that the file has
already been uploaded, once the file has already been uploaded and is
sitting in the server temp directory.

 

This is a drawback to our application because the files can typically vary
on a daily basis in size from 20mb thru to 400mb, and 400mb seems like a lot
of bandwidth to consume to discover that the file already exists on our
server.

 

I had hoped there was a way in which I could retrieve stats of the file
being uploaded prior to beginning the upload, to compare against files in
the target directory, so that the application can advise the user that the
file already exists and to give them the option to cancel the upload.

 

Another minor drawback is that it seems the Post upload method changes the
file datetime to the datetime of the upload. 

 

So, can anyone confirm that there is no other way to upload files from a
client machine using a form? (and assuming they don't have an ftp server at
their end).

 

Much warmth,

 

Murray

 



RE: [PHP] Any alternative to POST method FTP uploads from client computer?

2005-05-08 Thread Murray @ PlanetThoughtful
 Hi,
 
 On 5/9/05, Murray @ PlanetThoughtful [EMAIL PROTECTED] wrote:
  Hi All,
 
  I need to implement the ability to ftp upload files from client machines
 via
  a form in a web application I'm developing.
 
  From reading the PHP help, all I can find to perform this is the POST
 method
  for handling file uploads
  (http://au2.php.net/manual/en/features.file-upload.php).
 
  From my perspective, while this seems to work, there are a couple of
  drawbacks, most important of which is that it seems you can only do
  comparisons of the uploaded file, against the potential that the file
 has
  already been uploaded, once the file has already been uploaded and is
  sitting in the server temp directory.
 
 Instead use the dynamic file names
 
 say you upload a file filename.jpg
 
 when u upload it name it dynamiccaly by appending date and time before
 the file name
  like this
 
 2005050501010-filename.jpg

Hi, yes, I'm already doing this. Conflict of filename isn't my issue -- it's
whether or not the file should be uploaded at all, in the first place.

The difficulty being that you can't examine the file until *after* it has
been uploaded.

As others have suggested, using an ftp client application is one way to
handle it, however, users being users, the feedback has been Why do we need
to upload the files via an ftp client, *then* go to the web application and
attach the filename to a job entry? Why can't we do it all at once?

The answer being, Well, you can, but I bet you're going to be even more
annoyed when you've uploaded a huge file via the web application using the
POST upload method, only to find that the file is already there. Serves you
right for having too many stakeholders in uploading the files, dunnit?

Sometimes, you just can't win. Not that I don't understand the
practicalities involved, but this one feature would have been nice.

Regards,

Murray

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



[PHP] Problem with array

2005-05-01 Thread Murray @ PlanetThoughtful
Hi All,

 

I have 2 function, 1 which calls another, that I am attempting to use in a
page with, currently, some problems.

 

In essence, I have a hierarchical recordset table called tbl_content (contid
and parid, where parid contains the contid of the record to which the
current record belongs). A record without a parid value indicates that the
record is a project level record. I have another table with messages that
have been attached to records in tbl_content, called tbl_content_messages.
Tbl_content_messages contains a contid field indicating the record from
tbl_content to which each message has been attached.

 

I'm trying to create a summary page at the project level (ie all records in
tbl_content that do not have a parid value) displaying the number of
messages in each project (ie, attached to any record in tbl_content that is
part of the hierarchy chain underneath the relevant project record).

 

To do this, for each project I'm trying to determine the list of child
contid values so that I can do a count(*) in tbl_content_messages using the
IN operator, so that only messages attached to records in that project's
hierarchy chain are counted.

 

To generate that child list in the summary page, I'm using:

 

?

$leaflist = listProjectChildren($d-contid); // $d-contid
contains the contid of the project being summarised

?

 

The two functions I'm calling are:

 

?

 

function listProjectChildren($contid, $list=''){

if ($contid''){

$arrtree = array();

$arrtree = buildProjectTree($contid, $level=1);

for ($i=0;$i  count($arrtree);$i++){

$list .= '{$arrtree[$i][2]}',;

 }

}

$list = substr($list, 0,-1);

unset($arrtree);

return $list;

}

 

function buildProjectTree($contid, $level=1){

if ($contid''){

global $arrtree;

$sql = SELECT contid, parid, title FROM tbl_content
WHERE parid='$contid';

$rs = mysql_query($sql);

while ($d= mysql_fetch_object($rs)){

$ind = count($arrtree);

 

$arrtree[$ind][0] = $d-title;

$arrtree[$ind][1] = $level;

$arrtree[$ind][2] = $d-contid;

$arrtree[$ind][3] = $d-parid;

buildProjectTree($d-contid, $level+1);

 

}

mysql_free_result($rs);

}

return $arrtree;

}

?

 

My problem is that when I'm iterating through all of the project level
records, it appears that the content of $arrtree is never reset. New entries
are simply placed on the end, causing the for. loop that builds the
returned $list variable in listProjectChildren() to progressively return
larger and larger lists of contid values. As you can see, I try to UNSET()
the array prior to returning the $list variable, but this doesn't seem to
help.

 

Can anyone help me figure out what I'm doing wrong?

 

Many thanks in advance!

 

Murray

 



RE: [PHP] Problem with array

2005-05-01 Thread Murray @ PlanetThoughtful
Hi Richard,

Color me confused. I removed global $arrtree; and added $arrtree =
array(); to the function buildProjectTree() and now the parent function
(listProjectChildren) returns no values at all.

I've checked the page from which listProjectChildren() is being called, and
$arrtree does not appear as a variable in it at all, so it seems global
$arrtree; was doing SOMETHING, but at this point I have no idea what.

Still trying to work this out, if anyone else has any suggestions?

Much warmth,

Murray

 -Original Message-
 From: Richard Lynch [mailto:[EMAIL PROTECTED]
 Sent: Monday, 2 May 2005 5:04 AM
 To: Murray @ PlanetThoughtful
 Cc: php-general@lists.php.net
 Subject: Re: [PHP] Problem with array
 
 On Sun, May 1, 2005 10:21 am, Murray @ PlanetThoughtful said:
  ?
 
[Here there be snippage: please see original post for outline of problem]

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



  1   2   >