php-general Digest 5 Dec 2005 01:43:49 -0000 Issue 3832
Topics (messages 226832 through 226850):
Re: PDF Generator
226832 by: Norbert Wenzel
226835 by: Dan Harrington
Re: need session_start() to recall session data.
226833 by: M
Re: Count and Preg_Replace Using Version 4.4.1
226834 by: comex
226840 by: Shaun
226843 by: Curt Zirzow
226848 by: Shaun
test
226836 by: mr php
Exception
226837 by: mr php
226839 by: Anas Mughal
226841 by: Curt Zirzow
226842 by: Christian Herrnbock
Problem with pdf_show_boxed()
226838 by: ±i ®p»Ê
Re: How would you write this?
226844 by: Curt Zirzow
226850 by: Michael B Allen
Re: Mail SMTP settings
226845 by: Curt Zirzow
Re: Sessions, Expire-headers and Firefox's back button
226846 by: Curt Zirzow
Re: why php not running ?
226847 by: Curt Zirzow
226849 by: Mehmet Fatih AKBULUT
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 ---
Rick Lim wrote:
What is the best FREE pdf generator for PHP?
i used FPDF without any problems.
--- End Message ---
--- Begin Message ---
I have a TON of forms that I have to populate, can I make a PDF file using
Acrobat Professional, and then use PHP to populate those forms and have text
inserted into the pre-made text fields that I made using Acrobat? And if
so, what is the best tool for that? I'd prefer to do it for free, but
spending $$ is fine too.
Thanks
Dan
Rick Lim wrote:
> What is the best FREE pdf generator for PHP?
--- End Message ---
--- Begin Message ---
Matt Monaco wrote:
Yes, I actually changed the destructors to handle the session as you
indicated a few minutes after I posted, however I still have no clue as to
why I would need to do a session_start() to get data from the session.
How else would php know you want session started? You can turn
session.auto_start on, but then you don't have control over session
parameters.
--- End Message ---
--- Begin Message ---
> form'.$count.'...
You can use preg_replace_callback or the e pattern modifier to let you
run php code for the replacement:
http://us3.php.net/manual/en/function.preg-replace-callback.php
http://us3.php.net/manual/en/reference.pcre.pattern.modifiers.php
--- End Message ---
--- Begin Message ---
"comex" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> form'.$count.'...
You can use preg_replace_callback or the e pattern modifier to let you
run php code for the replacement:
http://us3.php.net/manual/en/function.preg-replace-callback.php
http://us3.php.net/manual/en/reference.pcre.pattern.modifiers.php
Hi Comex,
Thanks for your reply, I have modified the code so I have a call back
function:
echo = preg_replace_callback( '/<p[^>]*>(.*?)<\/p>/ms', "callback",
file_get_contents($_GET['file']) );
function callback($matches){
return
'<form name="form" target="_parent"
action="/index.php?action=edit_paragraph&file='.$_GET['file'].'"
method="post">
<input type="hidden" name="old_html"
value="'.htmlentities($matches[0]).'">
<p><a href="javascript:;"
onclick="document.form.submit();">'.$matches[1].'</a></p>
</form>';
}
But I still can't see how I can increment a value in each return string?
--- End Message ---
--- Begin Message ---
On Sun, Dec 04, 2005 at 07:00:00PM -0000, Shaun wrote:
>
> "comex" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > form'.$count.'...
> You can use preg_replace_callback or the e pattern modifier to let you
> run php code for the replacement:
> http://us3.php.net/manual/en/function.preg-replace-callback.php
> http://us3.php.net/manual/en/reference.pcre.pattern.modifiers.php
>
> Hi Comex,
>
> Thanks for your reply, I have modified the code so I have a call back
> function:
>
> echo = preg_replace_callback( '/<p[^>]*>(.*?)<\/p>/ms', "callback",
> file_get_contents($_GET['file']) );
>
> function callback($matches){
> return
> '<form name="form" target="_parent"
> ...
>
> But I still can't see how I can increment a value in each return string?
function callback($matches) {
static $i = 0; // <-- maintains counter within function scope
$i++;
return "<form name="form$i">....</form>";
}
btw, i've been meaning to mention this in the last few posts of
yours, but have you considered using DOM to make this happen. When
ever I see a regex solution for parsing an html document, it makes
me cringe.
Curt.
--
cat .signature: No such file or directory
--- End Message ---
--- Begin Message ---
"Curt Zirzow" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> On Sun, Dec 04, 2005 at 07:00:00PM -0000, Shaun wrote:
>>
>> "comex" <[EMAIL PROTECTED]> wrote in message
>> news:[EMAIL PROTECTED]
>> > form'.$count.'...
>> You can use preg_replace_callback or the e pattern modifier to let you
>> run php code for the replacement:
>> http://us3.php.net/manual/en/function.preg-replace-callback.php
>> http://us3.php.net/manual/en/reference.pcre.pattern.modifiers.php
>>
>> Hi Comex,
>>
>> Thanks for your reply, I have modified the code so I have a call back
>> function:
>>
>> echo = preg_replace_callback( '/<p[^>]*>(.*?)<\/p>/ms', "callback",
>> file_get_contents($_GET['file']) );
>>
>> function callback($matches){
>> return
>> '<form name="form" target="_parent"
>> ...
>>
>> But I still can't see how I can increment a value in each return string?
>
> function callback($matches) {
> static $i = 0; // <-- maintains counter within function scope
> $i++;
>
> return "<form name="form$i">....</form>";
> }
>
> btw, i've been meaning to mention this in the last few posts of
> yours, but have you considered using DOM to make this happen. When
> ever I see a regex solution for parsing an html document, it makes
> me cringe.
>
> Curt.
> --
> cat .signature: No such file or directory
Hi Curt,
Thanks for your reply. So basically I do something like:
$doc = new DOMDocument();
$doc->loadHTML($file);
$p = $doc->getElementsByTagName('p');
How would then wrap the following around each <p> tag:
<form name="form" target="_parent"
action="/index.php?action=edit_paragraph&file='.$_GET['file'].'"
method="post">
<input type="hidden" name="old_html"
value="'.htmlentities($matches[0]).'">
<p><a href="javascript:;"
onclick="document.form.submit();">'.$matches[1].'</a></p>
</form>
BTW if its not obvious I am trying to create a CMS that lets users edit
anything within a <p> tag!
--- End Message ---
--- Begin Message ---
test
--- End Message ---
--- Begin Message ---
Hello
Is it good to use exception handling for error handling or I should use only
for exceptions?
For example:
Is it good to throwing user input errors with throw new Exception().
Thanks
--- End Message ---
--- Begin Message ---
I would recommend keeping error handling and exceptions separate.
On 12/4/05, mr php <[EMAIL PROTECTED]> wrote:
>
> Hello
> Is it good to use exception handling for error handling or I should use
> only
> for exceptions?
> For example:
> Is it good to throwing user input errors with throw new Exception().
> Thanks
>
>
--
Anas Mughal
--- End Message ---
--- Begin Message ---
On Sun, Dec 04, 2005 at 08:07:48PM +0330, mr php wrote:
> Hello
> Is it good to use exception handling for error handling or I should use only
> for exceptions?
> For example:
> Is it good to throwing user input errors with throw new Exception().
I'm not sure if I understand how you mean by this but it sounds to
me that your asking if you should use exception catching vs if
statments:
try {
is_valid_username($username);
catch (Exception $e) {
$errors[] = $e->errorMessage;
}
imo, programming like that doesn't make sense, exceptions are more
designed for errors in assumed succesfull code. Consider:
<?php
try {
$dbh = new PDO('mysql:host=localhost;dbname=test', '', '');
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "select bar from foo";
$stmt = $dbh->prepare($sql);
$stmt->execute();
}
catch (PDOException $e) {
echo $e, "\n";
exit();
}
// some code to use the valid $stmt object
?>
There are two places where that code will issue an exception:
1. if a connection to the db fails, which it shouldn't
2. if the column bar doesn't exit of table foo doesn't exist
which should exist (unless the DBA decides to rename the table
or column.
After the catch statement, I know that $stmt is going to be valid
and can check for valid results or not.
The use of the try catch is to ensure that something that is
suppose to happen 100% of the time succesfully, if it doesn't we
have an exceptional case and should bail out in a friendly
manner.
Curt.
--
cat .signature: No such file or directory
--- End Message ---
--- Begin Message ---
mr php wrote:
> Hello
> Is it good to use exception handling for error handling or I should use
> only for exceptions?
> For example:
> Is it good to throwing user input errors with throw new Exception().
> Thanks
Hello,
I would also go by keeping them separate; it helps both in logic-flow, and
maintenence. Not to mention, exception handlers are design to do just that
- handle exceptions.
Regards,
Christian
--- End Message ---
--- Begin Message ---
Hello, Sir:
I just installed PHP with pdflib :
--------------------------------------------------------------------
PHP-4.4.1
pdflib PDFlib GmbH Version 6.0.2
pdflib PECL Version 2.0.3
apache 1.3.34
in Liunx FC1.
----------------------------------------------------------------------
When I run the script , I got the error messages as following:
---------------------------------------------------------------------------------------------------------
Fatal error: pdf_show_boxed(): [2102] PDF_show_boxed: Function not supported
for 'CID' in /home/apache/htdocs/004.php on line 8
---------------------------------------------------------------------------------------------------------
Some thing wrong with this function at the 8th parameter, I think:
>>>>>>pdf_show_boxed($pdf,$text,50,650,150,100,'right','');
if I remove the 8th parameter, It would tell me :
---------------------------------------------------------------------------------------------------------
Warning: pdf_show_boxed() expects exactly 8 parameters, 7 given in
/home/apache/htdocs/004.php on line 8
---------------------------------------------------------------------------------------------------------
What should I do?
Thanks form Any help.
###########################################################
The code:
###########################################################
$pdf = PDF_new();
pdf_open_file($pdf,"");
pdf_begin_page($pdf,595,842); //a4
$font = pdf_findfont($pdf,"MSung-Light","ETen-B5-H",0);
pdf_setfont($pdf,$font,12);
$text="MY TEST WORD";
pdf_show_boxed($pdf,$text,50,650,150,100,'right','');
pdf_end_page($pdf);
pdf_close($pdf);
$buffer=pdf_get_buffer($pdf);
$leng = strlen($buffer);
header ("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-type: application/pdf; charset: big5");
header("Content-Length: $leng");
header("Content-Disposition: inline; filename=hello.pdf");
print($buffer);
pdf_delete($pdf);
___________________________________________________ 最新版 Yahoo!奇摩即時通訊
7.0,免費網路電話任你打! http://messenger.yahoo.com.tw/
--- End Message ---
--- Begin Message ---
On Sat, Dec 03, 2005 at 10:00:14PM -0500, Michael B Allen wrote:
> The following code works but I'm a little new to PHP and I'd like to
> know if there are better ways to achive the same thing.
>
> In the below form example, if the user supplies one or more fields but
> not all that are required, the form is redisplayed but fields that were
> supplied are prepopulated and the ones that are required but are missing
> are highlighted in red.
>
> Can anyone recommend a better technique or elighten me about features of
> the language that I've missed?
>
> Mike
>
> <html>
> <body>
>
> <?php
> $set = 0;
> $username = "";
> $password = "";
>
> if (isset($_POST['username'])) {
> $username = trim($_POST['username']);
> if (strlen($username) > 0) {
> $set |= 0x01;
> }
> }
> if (isset($_POST['password'])) {
> $password = trim($_POST['password']);
> if (strlen($password) > 0) {
> $set |= 0x02;
> }
> }
> if (($set & 0x03) == 0x03) {
> echo "Logging in with: " . $username . ':' . $password;
> } else {
> ?>
>
> <form action="login.php" method="post">
> <table>
> <tr><td colspan="2">Login:</td></tr>
> <tr><td>Username:</td>
>
> <?php
> if ($set != 0 && ($set & 0x01) == 0) {
> echo "<td bgcolor=\"#ff0000\">";
> } else {
> echo "<td>";
> }
> echo "<input type=\"username\" name=\"username\" value=\"" . $username .
> "\"/>";
> ?>
>
> </td></tr>
> <tr><td>Password:</td>
>
> <?php
> if ($set != 0 && ($set & 0x02) == 0) {
> echo "<td bgcolor=\"#ff0000\">";
> } else {
> echo "<td>";
> }
> ?>
>
> <input type="password" name="password"/>
> </td></tr>
> <tr><td colspan="2"><input type="submit" value="Login"/></td></tr>
> </table>
> </form>
<style>
.errored {
color: #FF0000;
}
</style>
<?php
$set_class = array(0 => '', 1 => 'errored');
define('SET_USERNAME', 0x01);
define('SET_PASSWORD', 0x02);
define('SET_ALL', SET_USERNAME & SET_PASSWORD);
$set = 0;
$username = "";
$password = "";
if (isset($_POST['username'])) {
$username = trim($_POST['username']);
if (strlen($username) > 0) {
$set |= SET_USERNAME;
}
}
> ...
if (($set & SET_ALL) == SET_ALL) {
echo "Logging in with: " . $username . ':' . $password;
} else {
?>
<form action="login.php" method="post">
<table>
<tr><td colspan="2">Login:</td></tr>
<tr><td>Username:</td>
<?php
$class = $set_class[ $set & SET_USERNAME ];
echo "<td class="$class">
echo "<input type=\"username\" name=\"username\" value=\"" . $username .
"\"/>";
> ...
It might be a bit overkill for such a simple thing.. but heck.. i
was bored :)
Curt.
--
cat .signature: No such file or directory
--- End Message ---
--- Begin Message ---
On Sun, 4 Dec 2005 11:44:12 -0800
Curt Zirzow <[EMAIL PROTECTED]> wrote:
> <style>
> .errored {
> color: #FF0000;
> }
> </style>
> <?php
> $set_class = array(0 => '', 1 => 'errored');
> define('SET_USERNAME', 0x01);
> define('SET_PASSWORD', 0x02);
> define('SET_ALL', SET_USERNAME & SET_PASSWORD);
> $set = 0;
> $username = "";
> $password = "";
>
> if (isset($_POST['username'])) {
> $username = trim($_POST['username']);
> if (strlen($username) > 0) {
> $set |= SET_USERNAME;
> }
> }
> > ...
> if (($set & SET_ALL) == SET_ALL) {
> echo "Logging in with: " . $username . ':' . $password;
> } else {
> ?>
> <form action="login.php" method="post">
> <table>
> <tr><td colspan="2">Login:</td></tr>
> <tr><td>Username:</td>
> <?php
> $class = $set_class[ $set & SET_USERNAME ];
> echo "<td class="$class">
> echo "<input type=\"username\" name=\"username\" value=\"" . $username .
> "\"/>";
> > ...
>
> It might be a bit overkill for such a simple thing.. but heck.. i
> was bored :)
Interesting. This gives me some ideas. I'm also happy to know I wasn't
too far off :->
Thanks,
Mike
--- End Message ---
--- Begin Message ---
On Sat, Dec 03, 2005 at 10:17:59PM -0700, Dan wrote:
> Yes that does work but the return path and my mail headers still show
> the main domain. My point is that PHP should be acessing my SMTP
> server specified but it is using the default local host instead.
If you note at php.net/mail that the SMTP setting is only for
windows. Under *nix only as current installed MTA like sendmail can
be used.
you can set your sendmail_path to pass parameters like :
/sbin/sendmail -f [EMAIL PROTECTED]
Curt.
--
cat .signature: No such file or directory
--- End Message ---
--- Begin Message ---
On Fri, Dec 02, 2005 at 07:21:43PM -0500, Chris Shiflett wrote:
> Hi Peter,
>
> >When I begin session with session_start() PHP sets an Expired-header.
> >I suppose that's fine for the sake of unwanted caching.
> >
> >Unfortunately, Firefox seem to reload a page that's expired when using
> >the browser's "Back" navigation instead of showing the page as it was
> >as the user left it.
>
> You might find this article helpful:
>
> http://shiflett.org/articles/guru-speak-nov2004
>
> I don't really fault Firefox for abiding by the no-store directive, nor
> do I fault Internet Explorer for ignoring it.
iirc, Firefox 1.5 has improved its caching system, in paticular to the
back button drama.
Curt.
--
cat .signature: No such file or directory
--- End Message ---
--- Begin Message ---
On Fri, Dec 02, 2005 at 11:53:13AM +0200, Mehmet Fatih AKBULUT wrote:
> hi all.
> i installed php5_extensions on my system (Freebsd5.4)
> please look the lines below and tell me where i am doing something wrong.
>
> [EMAIL PROTECTED] -> [~]#php /*hit the tab*/
> php php-config phpize
> [EMAIL PROTECTED] -> [~]#php
>
> a simple php code:
>
> [EMAIL PROTECTED] -> [~]#cat first.php
> <%php
> echo "Hello World!";
> %>
> [EMAIL PROTECTED] -> [~]#
>
> /* chmod a+x first.php*/
>
> when trying to run the code :
>
> [EMAIL PROTECTED] -> [~]#php first.php
> PHP Warning: Method panda::__set() must take exactly 2 arguments in Unknown
> on line 0
According to the code you cat'ed there is no panda object that is
defined so my first assumption is that you have a file that is set
in your php.ini:
auto_prepend_file=/some/panda.php
> Segmentation fault (core dumped)
Even at that, this core dump shouldn't be happening. I'm assuming
you installed this via ports. There are two thing i can think of
that should be checked before getting a backtrace:
1) are you uptodate on your ports? have you done a cvsup
recently?
2) what does 'php -v' say?
Curt.
--
cat .signature: No such file or directory
--- End Message ---
--- Begin Message ---
hi Curt.
for the first question :
yes i always do the things below:
#portupgrade -arR
and
#cvsup -g -L 2 /etc/por...
i mean yes my ports up to date.
and for the second :
[EMAIL PROTECTED] php -v
Segmentation fault (core dumped)
[EMAIL PROTECTED] php-config --version
5.0.5
[EMAIL PROTECTED]
dont know how to solve this troublesome problem.
--- End Message ---