php-general Digest 2 Jan 2008 19:18:34 -0000 Issue 5213
Topics (messages 266468 through 266492):
Re: best way for PHP page
266468 by: Casey
266469 by: Sancar Saran
266471 by: Brady Mitchell
266473 by: Nathan Nobbe
266474 by: Dave Goodchild
266480 by: tedd
Wrong parameter count for imap_open()
266470 by: Adam Williams
266472 by: Daniel Brown
266476 by: Jim Lucas
automatic caller
266475 by: blackwater dev
266477 by: Nathan Nobbe
First stupid post of the year.
266478 by: tedd
266479 by: Nathan Nobbe
266481 by: David Giragosian
266482 by: tedd
266483 by: Warren Vail
266484 by: Daniel Brown
266485 by: Nathan Nobbe
266486 by: Daniel Brown
266487 by: Afan Pasalic
266488 by: Scott Wilcox
266489 by: tedd
266490 by: Jim Lucas
266491 by: Nathan Nobbe
266492 by: Daniel Brown
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[EMAIL PROTECTED]
----------------------------------------------------------------------
--- Begin Message ---
On Jan 1, 2008 11:17 PM, Alain Roger <[EMAIL PROTECTED]> wrote:
> Hi,
>
> i would like to improve my coding quality when i use PHP code and for that i
> would request your help.
> in my web developer experience, i have to confess that i've never succeeded
> in spliting PHP code from HTML code.
>
> i mean that all my web pages consist of PHP code mixed with HTML code (for
> rendering pages).
> Some developers tell it's possible to write only PHP code for web page. i
> agree with them but only when those PHP pages do not render web elements
> (write text, display pictures, display formular, ...).
>
> the purpose of my post is to know if i can really (at 100%) split client
> code (display images, write text,...) from server code (move or copy data to
> DB, create connection objects,...)
>
> so what do you think about that ?
>
> --
> Alain
> ------------------------------------
> Windows XP SP2
> PostgreSQL 8.2.4 / MS SQL server 2005
> Apache 2.2.4
> PHP 5.2.4
> C# 2005-2008
>
Yes, you can.
function foo() {
global $data;
//Fetch from database, format, etc. etc.
//Stuff all the data into $data variable
}
function bar() {
global $data;
//Output with HTML
}
$data = array();
foo();
bar();
I'm pretty sure this is what they mean.
-Casey
--- End Message ---
--- Begin Message ---
On Wednesday 02 January 2008 09:17:50 Alain Roger wrote:
> Hi,
>
> i would like to improve my coding quality when i use PHP code and for that
> i would request your help.
> in my web developer experience, i have to confess that i've never succeeded
> in spliting PHP code from HTML code.
>
> i mean that all my web pages consist of PHP code mixed with HTML code (for
> rendering pages).
> Some developers tell it's possible to write only PHP code for web page. i
> agree with them but only when those PHP pages do not render web elements
> (write text, display pictures, display formular, ...).
>
> the purpose of my post is to know if i can really (at 100%) split client
> code (display images, write text,...) from server code (move or copy data
> to DB, create connection objects,...)
>
> so what do you think about that ?
Hello,
I believe TYPO3 has good implementation about splitting code and template.
And to archieve clean php code.
1-) Left <html> <?php echo $this; ?></html> model development
2-) Find good template engine. (no not that smarty, it was too big)
3-) use strict dicipline to move html to outside of the code.
Also if you can use the php based template files you can lift off the template
overhead.
like.
template.php
$strPage = "
<html>
<head.
<title>".$strPageTitle."</title>
</head>
<body>
<table>
<tr>
<td>".$strLeftBlock."</td>
<td>".$strRigthBlock."</td>
</tr>
</table>
</body>
</html>";
process.php
$strPageTitle = getPageTitle($_REQUEST['page']);
$strLeftBlock = getPageBlock($_REQUEST['page'],'left');
$strRightBlock = getPageBlock($_REQUEST['page'],'right');
include('template.php');
echo $strPage;
regards
Sancar
--- End Message ---
--- Begin Message ---
i would like to improve my coding quality when i use PHP code and
for that i
would request your help.
in my web developer experience, i have to confess that i've never
succeeded
in spliting PHP code from HTML code.
There's a myth that by separating html and php your code is cleaner,
it's a little more than that. What you should consider doing is
separating the "business logic" from the "display logic".
The business logic includes things like database calls, data
calculations, etc.
Display logic is what the page actually looks like. This will likely
include both HTML and PHP, but the PHP will be limited to echoing out
variables, as you should have already done all calculations.
One very good way to do this separation is by using the MVC pattern - http://en.wikipedia.org/wiki/Model-view-controller
. I've found that using the MVC pattern helps me to write cleaner,
more maintainable code as you always know where the code for a given
function is located. Need to edit what the page looks like? It's in
the view. Need to edit your database calls? It's in the model.
Anything else? It's in the controller.
There are lots of great frameworks out there that use the MVC pattern.
Personally I use and recommend CodeIgniter (http://
www.codeigniter.com) - it's been a great one for me, but there are
plenty of other well written frameworks out there if CodeIgniter isn't
a good fit for you.
HTH,
Brady
--- End Message ---
--- Begin Message ---
On Jan 2, 2008 2:17 AM, Alain Roger <[EMAIL PROTECTED]> wrote:
> Hi,
>
> i would like to improve my coding quality when i use PHP code and for that
> i
> would request your help.
> in my web developer experience, i have to confess that i've never
> succeeded
> in spliting PHP code from HTML code.
>
> i mean that all my web pages consist of PHP code mixed with HTML code (for
> rendering pages).
> Some developers tell it's possible to write only PHP code for web page. i
> agree with them but only when those PHP pages do not render web elements
> (write text, display pictures, display formular, ...).
>
> the purpose of my post is to know if i can really (at 100%) split client
> code (display images, write text,...) from server code (move or copy data
> to
> DB, create connection objects,...)
>
> so what do you think about that ?
>
study up on mvc
http://en.wikipedia.org/wiki/Model-view-controller
then look at some of the popular open source php implementations.
code igniter is very thin and straightforward.
you can quickly see how a php application can be separated into layers.
-nathan
--- End Message ---
--- Begin Message ---
If MVC is too heavy for you it may also be worth exploring templating
engines such as Smarty:
http://www.smarty.net/
On Jan 2, 2008 4:10 PM, Nathan Nobbe <[EMAIL PROTECTED]> wrote:
> On Jan 2, 2008 2:17 AM, Alain Roger <[EMAIL PROTECTED]> wrote:
>
> > Hi,
> >
> > i would like to improve my coding quality when i use PHP code and for
> that
> > i
> > would request your help.
> > in my web developer experience, i have to confess that i've never
> > succeeded
> > in spliting PHP code from HTML code.
> >
> > i mean that all my web pages consist of PHP code mixed with HTML code
> (for
> > rendering pages).
> > Some developers tell it's possible to write only PHP code for web page.
> i
> > agree with them but only when those PHP pages do not render web elements
> > (write text, display pictures, display formular, ...).
> >
> > the purpose of my post is to know if i can really (at 100%) split client
> > code (display images, write text,...) from server code (move or copy
> data
> > to
> > DB, create connection objects,...)
> >
> > so what do you think about that ?
> >
>
> study up on mvc
> http://en.wikipedia.org/wiki/Model-view-controller
>
> then look at some of the popular open source php implementations.
> code igniter is very thin and straightforward.
> you can quickly see how a php application can be separated into layers.
>
> -nathan
>
--- End Message ---
--- Begin Message ---
At 8:17 AM +0100 1/2/08, Alain Roger wrote:
the purpose of my post is to know if i can really (at 100%) split client
code (display images, write text,...) from server code (move or copy data to
DB, create connection objects,...)
so what do you think about that ?
Alain:
What do I think about that?
I think there is only one web language and it's called
php/mysql/html/js/css. For no one language can do it all.
The bigger point is to learn how to separate data, presentation, and
functionality.
Cheers,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
--- End Message ---
--- Begin Message ---
I'm running PHP 5.2.4 and getting the error:
*Warning*: Wrong parameter count for imap_open() in
*/var/www/sites/intra-test/contract/login.php* on line *9
*My code is:
$mbox =
imap_open("\"{mail.mdah.state.ms.us/imap/novalidate-cert:143}INBOX\",
\"".$_POST["username"]."\", \"".$_POST["password"]."\""); // line 9
but when I echo it out, it looks fine:
echo "\"{mail.mdah.state.ms.us/imap/novalidate-cert:143}INBOX\",
\"".$_POST["username"]."\", \"".$_POST["password"]."\"";
prints:
"{mail.mdah.state.ms.us/imap/novalidate-cert:143}INBOX", "awilliam",
"xxxxxxx"
any ideas?
*
*
--- End Message ---
--- Begin Message ---
On Jan 2, 2008 10:00 AM, Adam Williams <[EMAIL PROTECTED]> wrote:
> I'm running PHP 5.2.4 and getting the error:
>
> *Warning*: Wrong parameter count for imap_open() in
> */var/www/sites/intra-test/contract/login.php* on line *9
>
> *My code is:
>
> $mbox =
> imap_open("\"{mail.mdah.state.ms.us/imap/novalidate-cert:143}INBOX\",
> \"".$_POST["username"]."\", \"".$_POST["password"]."\""); // line 9
[snip!]
You just forgot to encapsulate your parameters properly. You
escape the strings, but don't close the parameter, so PHP reads that
all as one parameter passed to imap_open().
Change it to one of the following:
$mbox =
imap_open("\"{mail.mdah.state.ms.us/imap/novalidate-cert:143}INBOX\"","\"".$_POST["username"]."\"","\"".$_POST["password"]."\"");
// line 9
---- OR ----
$mbox =
imap_open('"{mail.mdah.state.ms.us/imap/novalidate-cert:143}INBOX"','"'.$_POST['username'].'"','".$_POST['password'].'"');
--
Daniel P. Brown
[Phone Numbers Go Here!]
[They're Hidden From View!]
If at first you don't succeed, stick to what you know best so that you
can make enough money to pay someone else to do it for you.
--- End Message ---
--- Begin Message ---
Adam Williams wrote:
> I'm running PHP 5.2.4 and getting the error:
>
> *Warning*: Wrong parameter count for imap_open() in
> */var/www/sites/intra-test/contract/login.php* on line *9
>
> *My code is:
>
> $mbox =
> imap_open("\"{mail.mdah.state.ms.us/imap/novalidate-cert:143}INBOX\",
> \"".$_POST["username"]."\", \"".$_POST["password"]."\""); // line 9
>From the documentation, it looks to me like you are makings things much more
>complicated then they
need to be.
imap_open('{mail.mdah.state.ms.us/imap/novalidate-cert:143}INBOX',
$_POST["username"],
$_POST["password"]);
>From what the documentation shows, you do not need to have quotes around the
>username/password fields.
Enjoy.
>
> but when I echo it out, it looks fine:
>
> echo "\"{mail.mdah.state.ms.us/imap/novalidate-cert:143}INBOX\",
> \"".$_POST["username"]."\", \"".$_POST["password"]."\"";
>
> prints:
>
> "{mail.mdah.state.ms.us/imap/novalidate-cert:143}INBOX", "awilliam",
> "xxxxxxx"
>
>
> any ideas?
> *
> *
>
--
Jim Lucas
"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."
Twelfth Night, Act II, Scene V
by William Shakespeare
--- End Message ---
--- Begin Message ---
I'm working on a prototype now and was wondering if anyone new of a service
where I could pass in text and a number and the service would call the
number and read the text. I know I can do this with asterisk and it's php
api but don't have time to set up all the outgoing code/functionality. Does
anyone know of a service that does this so I can show it as a proof of
concept. I looked at GrandCentral but it doesn't appear to have this
feature.
Thanks!
--- End Message ---
--- Begin Message ---
On Jan 2, 2008 12:23 PM, blackwater dev <[EMAIL PROTECTED]> wrote:
> I'm working on a prototype now and was wondering if anyone new of a
> service
> where I could pass in text and a number and the service would call the
> number and read the text. I know I can do this with asterisk and it's php
> api but don't have time to set up all the outgoing code/functionality.
> Does
> anyone know of a service that does this so I can show it as a proof of
> concept. I looked at GrandCentral but it doesn't appear to have this
> feature.
im wondering if it would be prudent for a service to allow you to
call just any number? obviously a company A providing service to company B
could supply a service to company B to call any number at company B, no
sweat.
there could also be an SLA that defines misuse of the service; like if
company B is
spamming some people or w/e, then company A defers responsibility to them
legally.
but im guessing there could be some legal implications regarding a generic
service
to call any number..
anyway this is all just speculation :O
-nathan
--- End Message ---
--- Begin Message ---
Hi gang:
I have a
$submit = $_POST['submit'];
The string contains:
A
(it's there to make a submit button wider)
How can I strip out the " " from the $submit string leaving "A"?
I've tried
trim($submit);
but, that don't work.
Neither does:
$submit = str_replace(' ','',$submit);
or this:
$submit = str_replace(' ';','',$submit);
I should know what to do, but in this case I don't.
Help is always appreciated.
Cheers,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
--- End Message ---
--- Begin Message ---
On Jan 2, 2008 1:34 PM, tedd <[EMAIL PROTECTED]> wrote:
> Hi gang:
>
> I have a
>
> $submit = $_POST['submit'];
>
> The string contains:
>
> A
>
> (it's there to make a submit button wider)
>
> How can I strip out the " " from the $submit string leaving "A"?
>
> I've tried
>
> trim($submit);
>
> but, that don't work.
>
> Neither does:
>
> $submit = str_replace(' ','',$submit);
>
> or this:
>
> $submit = str_replace(' ';','',$submit);
>
> I should know what to do, but in this case I don't.
>
> Help is always appreciated.
why dont you just style the button w/ css?
style="width:200px"
-nathan
--- End Message ---
--- Begin Message ---
On 1/2/08, Nathan Nobbe <[EMAIL PROTECTED]> wrote:
>
> On Jan 2, 2008 1:34 PM, tedd <[EMAIL PROTECTED]> wrote:
>
> > Hi gang:
> >
> > I have a
> >
> > $submit = $_POST['submit'];
> >
> > The string contains:
> >
> > A
> >
> > (it's there to make a submit button wider)
> >
> > How can I strip out the " " from the $submit string leaving "A"?
> >
> > I've tried
> >
> > trim($submit);
> >
> > but, that don't work.
> >
> > Neither does:
> >
> > $submit = str_replace(' ','',$submit);
> >
> > or this:
> >
> > $submit = str_replace(' ';','',$submit);
> >
> > I should know what to do, but in this case I don't.
> >
> > Help is always appreciated.
>
>
> why dont you just style the button w/ css?
>
> style="width:200px"
>
> -nathan
>
Parse the string character by character discarding '&' , 'n' , 'b' , 's'
, 'p' , and ';'. Assuming of course that the part of the label you want to
keep is none of those characters.
-David
--- End Message ---
--- Begin Message ---
At 1:46 PM -0500 1/2/08, Nathan Nobbe wrote:
On Jan 2, 2008 1:34 PM, tedd
<<mailto:[EMAIL PROTECTED]>[EMAIL PROTECTED]> wrote:
A
(it's there to make a submit button wider)
why dont you just style the button w/ css?
style="width:200px"
-nathan
-nathan:
Have you tried that?
I have, and it don't work.
I can create wider <button>whatever</button> but I cannot create a
wider <input type="submit" value="A"> submit button.
Cheers,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
--- End Message ---
--- Begin Message ---
I often identify each of my submit buttons with different names and identify
which one was pressed by;
If(isset($_POST["submit1"]))
Only one will ever be pressed at a time, and that allows me to use the same
page with multiple languages (substituting different values for different
languages). As you can see I can ignore the value, and submit buttons are
not sent in the form if they are not clicked.
Another option,
Warren Vail
> -----Original Message-----
> From: Nathan Nobbe [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, January 02, 2008 10:46 AM
> To: tedd
> Cc: PHP General list
> Subject: Re: [PHP] First stupid post of the year.
>
> On Jan 2, 2008 1:34 PM, tedd <[EMAIL PROTECTED]> wrote:
>
> > Hi gang:
> >
> > I have a
> >
> > $submit = $_POST['submit'];
> >
> > The string contains:
> >
> > A
> >
> > (it's there to make a submit button wider)
> >
> > How can I strip out the " " from the $submit string leaving "A"?
> >
> > I've tried
> >
> > trim($submit);
> >
> > but, that don't work.
> >
> > Neither does:
> >
> > $submit = str_replace(' ','',$submit);
> >
> > or this:
> >
> > $submit = str_replace(' ';','',$submit);
> >
> > I should know what to do, but in this case I don't.
> >
> > Help is always appreciated.
>
>
> why dont you just style the button w/ css?
>
> style="width:200px"
>
> -nathan
--- End Message ---
--- Begin Message ---
On Jan 2, 2008 1:34 PM, tedd <[EMAIL PROTECTED]> wrote:
> Hi gang:
>
> I have a
>
> $submit = $_POST['submit'];
>
> The string contains:
>
> A
>
> (it's there to make a submit button wider)
>
> How can I strip out the " " from the $submit string leaving "A"?
>
> I've tried
>
> trim($submit);
>
> but, that don't work.
>
> Neither does:
>
> $submit = str_replace(' ','',$submit);
>
> or this:
>
> $submit = str_replace(' ';','',$submit);
>
> I should know what to do, but in this case I don't.
>
> Help is always appreciated.
<?
// Your existing code here....
$submit = trim(str_replace(' ','',$submit);
?>
--
Daniel P. Brown
[Phone Numbers Go Here!]
[They're Hidden From View!]
If at first you don't succeed, stick to what you know best so that you
can make enough money to pay someone else to do it for you.
--- End Message ---
--- Begin Message ---
On Jan 2, 2008 1:55 PM, tedd <[EMAIL PROTECTED]> wrote:
> At 1:46 PM -0500 1/2/08, Nathan Nobbe wrote:
> >On Jan 2, 2008 1:34 PM, tedd
> ><<mailto:[EMAIL PROTECTED]>[EMAIL PROTECTED]> wrote:
> >
> >
> > A
> >
> >(it's there to make a submit button wider)
> >
> >
> >why dont you just style the button w/ css?
> >
> >style="width:200px"
> >
> >-nathan
>
>
> -nathan:
>
> Have you tried that?
>
> I have, and it don't work.
>
> I can create wider <button>whatever</button> but I cannot create a
> wider <input type="submit" value="A"> submit button.
it appears to work for me using firefox:
<html>
<head>
<title>
</title>
</head>
<body>
<form>
<input type="submit" style="width:250px" value="Submit">
<form>
</body>
</html>
-nathan
--- End Message ---
--- Begin Message ---
On Jan 2, 2008 1:55 PM, tedd <[EMAIL PROTECTED]> wrote:
> At 1:46 PM -0500 1/2/08, Nathan Nobbe wrote:
> >On Jan 2, 2008 1:34 PM, tedd
> ><<mailto:[EMAIL PROTECTED]>[EMAIL PROTECTED]> wrote:
> >
> >
> > A
> >
> >(it's there to make a submit button wider)
> >
> >
> >why dont you just style the button w/ css?
> >
> >style="width:200px"
> >
> >-nathan
>
>
> -nathan:
>
> Have you tried that?
>
> I have, and it don't work.
>
> I can create wider <button>whatever</button> but I cannot create a
> wider <input type="submit" value="A"> submit button.
Try this:
<input type="submit" value="A"
style="width:160px;align:center;text-align:center;">
--
Daniel P. Brown
[Phone Numbers Go Here!]
[They're Hidden From View!]
If at first you don't succeed, stick to what you know best so that you
can make enough money to pay someone else to do it for you.
--- End Message ---
--- Begin Message ---
tedd wrote:
At 1:46 PM -0500 1/2/08, Nathan Nobbe wrote:
On Jan 2, 2008 1:34 PM, tedd
<<mailto:[EMAIL PROTECTED]>[EMAIL PROTECTED]> wrote:
A
(it's there to make a submit button wider)
why dont you just style the button w/ css?
style="width:200px"
-nathan
-nathan:
Have you tried that?
I have, and it don't work.
I can create wider <button>whatever</button> but I cannot create a wider
<input type="submit" value="A"> submit button.
Cheers,
tedd
Yes you can:
<input type="submit" value="A" style="width: 25px; height: 10px;">
-afan
--- End Message ---
--- Begin Message ---
Add it inline, and it'll override everything else.
<input type="submit" style="width: 200px;" name="bob" />
tedd wrote:
At 1:46 PM -0500 1/2/08, Nathan Nobbe wrote:
On Jan 2, 2008 1:34 PM, tedd
<<mailto:[EMAIL PROTECTED]>[EMAIL PROTECTED]> wrote:
A
(it's there to make a submit button wider)
why dont you just style the button w/ css?
style="width:200px"
-nathan
-nathan:
Have you tried that?
I have, and it don't work.
I can create wider <button>whatever</button> but I cannot create a
wider <input type="submit" value="A"> submit button.
Cheers,
tedd
--- End Message ---
--- Begin Message ---
At 1:57 PM -0500 1/2/08, Daniel Brown wrote:
On Jan 2, 2008 1:34 PM, tedd <[EMAIL PROTECTED]> wrote:
from this:
A
to this A
<?
// Your existing code here....
$submit = trim(str_replace(' ','',$submit);
?>
Even with adding an additional ")", that didn't work either. :-)
Cheers,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
--- End Message ---
--- Begin Message ---
Nathan Nobbe wrote:
> On Jan 2, 2008 1:55 PM, tedd <[EMAIL PROTECTED]> wrote:
>
>> At 1:46 PM -0500 1/2/08, Nathan Nobbe wrote:
>>> On Jan 2, 2008 1:34 PM, tedd
>>> <<mailto:[EMAIL PROTECTED]>[EMAIL PROTECTED]> wrote:
>>>
>>>
>>> A
>>>
>>> (it's there to make a submit button wider)
>>>
>>>
>>> why dont you just style the button w/ css?
>>>
>>> style="width:200px"
>>>
>>> -nathan
>>
>> -nathan:
>>
>> Have you tried that?
>>
>> I have, and it don't work.
>>
>> I can create wider <button>whatever</button> but I cannot create a
>> wider <input type="submit" value="A"> submit button.
>
>
> it appears to work for me using firefox:
>
> <html>
> <head>
> <title>
> </title>
> </head>
> <body>
> <form>
> <input type="submit" style="width:250px" value="Submit">
> <form>
> </body>
> </html>
>
> -nathan
>
I prefer this approach instead.
<html>
<head>
<title></title>
<style>
button,
input[type=submit],
input[type=reset],
input[type=button] {
width: 250px;
}
</style>
</head>
<body>
<form>
<input type="submit" value="Submit">
<form>
</body>
</html>
This way, you hit all your buttons with one style tag.
--
Jim Lucas
"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."
Twelfth Night, Act II, Scene V
by William Shakespeare
--- End Message ---
--- Begin Message ---
i wonder what the record will be this year for the number of identical
responses
to a question in a single thread ;)
looks like this one is already out in front!
-nathan
--- End Message ---
--- Begin Message ---
On Jan 2, 2008 2:05 PM, tedd <[EMAIL PROTECTED]> wrote:
> At 1:57 PM -0500 1/2/08, Daniel Brown wrote:
> >On Jan 2, 2008 1:34 PM, tedd <[EMAIL PROTECTED]> wrote:
>
> from this:
>
> A
>
> to this A
>
> ><?
> >// Your existing code here....
> >$submit = trim(str_replace(' ','',$submit);
> >?>
>
> Even with adding an additional ")", that didn't work either. :-)
That was a typo on my part, but check it out here and you'll see
it works (you can view full source there, too):
http://pilotpig.net/code-library/tedds-button.php
--
Daniel P. Brown
[Phone Numbers Go Here!]
[They're Hidden From View!]
If at first you don't succeed, stick to what you know best so that you
can make enough money to pay someone else to do it for you.
--- End Message ---