|
Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com |
php-general Digest 22 Jan 2007 23:58:39 -0000 Issue 4584
php-general-digest-help
lists.php.net
Date: Mon Jan 22 2007 - 17:58:39 CST
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
php-general Digest 22 Jan 2007 23:58:39 -0000 Issue 4584
Topics (messages 247541 through 247584):
Re: Newbie - help with a foreach
247541 by: Németh Zoltán
Re: socket_write buffer problem
247542 by: Roman Neuhauser
Function returning but continues execution
247543 by: David Mytton
247546 by: Roman Neuhauser
247547 by: David Mytton
247549 by: Roman Neuhauser
247551 by: David Mytton
247554 by: Robert Cummings
247555 by: David Mytton
247556 by: Roman Neuhauser
247557 by: Jim Lucas
247558 by: David Mytton
247559 by: Roman Neuhauser
247560 by: David Mytton
247561 by: Roman Neuhauser
247564 by: David Mytton
247566 by: Roman Neuhauser
247567 by: Roman Neuhauser
247569 by: David Mytton
247571 by: Roman Neuhauser
247573 by: David Mytton
247574 by: Roman Neuhauser
247576 by: David Mytton
247577 by: Roman Neuhauser
smsSend
247544 by: Marcelo Ferrufino Murillo
247548 by: Roman Neuhauser
247550 by: Jay Blanchard
Re: os php scheduler?
247545 by: David Giragosian
Re: Help With Inventory
247552 by: Jim Lucas
Re: wierd slash
247553 by: Jim Lucas
Embeded image on mail()
247562 by: Bagus Nugroho
247563 by: Roman Neuhauser
247565 by: Pinter Tibor (tibyke)
247568 by: Sergiu Voicu
ouput the contents of a folder for download
247570 by: Ross
247572 by: Roman Neuhauser
Network Time Protocol
247575 by: Ron Piggott
247578 by: Roman Neuhauser
[HELP] Fatal error when uploading large files!
247579 by: Jay Paulson
247581 by: Jim Lucas
exec('make') Q
247580 by: james.jwm-art.net
247583 by: Roman Neuhauser
preg_match problem
247582 by: Beauford
247584 by: Paul Novitski
Administrivia:
To subscribe to the digest, e-mail:
php-general-digest-subscribe
lists.php.net
To unsubscribe from the digest, e-mail:
php-general-digest-unsubscribe
lists.php.net
To post to the list, e-mail:
php-general
lists.php.net
----------------------------------------------------------------------
attached mail follows:
On v, 2007-01-21 at 01:28 -0800, pub wrote:
> On Jan 18, 2007, at 2:43 AM, Németh Zoltán wrote:
>
> > first, do you want to allow several jobs for the same company to be
> >
> > stored in the DB and appear on the page, right? (if not, then why
> > are
> >
> > you storing them in separate tables?)
> >
> >
> Yes, I have the name of the company with address etc in the "client"
> table
> and all the jobs in the "job" table, so that I can display several
> jobs per client
> > second, you should do it with one query I think
> >
> >
> > something like "SELECT t1.*, t2.* FROM client t1, job t2 WHERE
> >
> > t1.companyId=t2.companyId ORDER BY t1.companyId"
> >
> >
> > and then you can do all stuff in one loop
> >
> >
> > while ($aaa = mysql_fetch_array($result))
> >
> >
> > and you don't need that foreach stuff at all (which also seems to be
> >
> > screwed up...)
> >
>
> I am working on my query as you suggested. I have a joint query that
> seems to work except that I get the name of the company twice. Could
> you please help me figure out how to make it echo the company once and
> list all the jobs next to it on the same line and start a new line
> with the next company?
>
>
ehh, I thought you want the jobs on separate lines, sorry.
this can be achieved for example like this:
$prev_cname = "";
while ($aaa = mysql_fetch_array($result,MYSQL_ASSOC))
{
if ($aaa['companyName'] != $prev_cname) {
echo "<span class='navCompany'>{$aaa['companyName']}</span>";
}
echo "<span class='navArrow'> > </span><span class='navText'><a
href='single_page_t10.php?art=".$aaa['pix']."'>{$aaa['jobType']}</a></span>";
if ($aaa['companyName'] != $prev_cname) {
echo "<br/>\n";
$prev_cname = $aaa['companyName'];
}
}
hope that helps
Zoltán Németh
> Here is the code I have now:
>
>
> $query = "SELECT client.companyName, job.jobType, job.pix, job.info,
> job.url
> FROM client, job
> WHERE client.companyId=job.companyId
> AND client.view='yes'
> order by client.companyName";
>
>
>
> $result = mysql_query($query)
> or die ("Couldn't execute query");
>
> while ($aaa = mysql_fetch_array($result,MYSQL_ASSOC))
> {
> echo "<span class='navCompany'>{$aaa['companyName']}</span><span
> class='navArrow'> > </span><span class='navText'><a
> href='single_page_t10.php?art=".$aaa['pix']."'>{$aaa['jobType']}</a></span><br>\n";
> }
>
attached mail follows:
# stuttle
gmail.com / 2007-01-22 11:33:51 +0000:
> rluckhurst
resmaster.com wrote:
> >> You've already been given a clue... read the manual:
> >> http://php.net/socket_write
> >>
> >> I know you said you read it, but you obviously haven't. To quote...
> >
> > Now you are making an assumption and you are making a "fsckup". Just
> > because I did not show in my simplified example that I had tested the
> > number of bytses sent does not mean for a second that I had not done
> > it.
Richard,
I had almost sent a message very similar to the one from Stut you're
complaining about here, but cancelled it because I expected you would
react the way you have, and I'd just waste energy.
One last try so that you know Stut is not alone in his assessment:
You might have actually played with a "simplified example", but judging
from your previous questions (and reactions to replies), you don't pay
much attention to your own observations, and/or you make too many
assumptions, and your subsequent fuckups bring you here.
You come claiming it's broken, you've tried everything, and show us code
that's simply broken. We never see the correct code you claim to have
tried (after you've been told to fix bugs in what you have shown).
Programming is not like waving a magic wand, it's not our fault the
computer does what you tell it instead of what you want it to do!
Until-you-pull-your-head-from-wherever-it-is'ly yours,
...
--
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man. You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991
attached mail follows:
Hi,
I have come across what appears to be a bug in PHP, but one that I am
having difficulty writing test code for. Also, the bug only happens on a
Linux build of PHP - the code is working as expected on Windows. This is
on both PHP 5.2.0 and the very latest snapshots:
Windows: 5.2.1RC4-dev Jan 19 2007 16:16:57
Linux: PHP Version 5.2.1RC4-dev Jan 22 2007 11:54:28
(php5.2-200701221130.tar.gz)
The configure line is:
'./configure' '--with-apxs2=/usr/local/apache2/bin/apxs' '--with-curl'
'--with-freetype-dir=/usr' '--with-gd' '--with-gettext'
'--with-jpeg-dir=/usr' '--with-mysql' '--with-openssl'
'--with-pdo-mysql' '--with-pear' '--with-png-dir=/usr' '--with-zlib'
'--enable-calendar' '--enable-exif' '--enable-gd-native-ttf'
'--enable-pdo' '--enable-soap' '--enable-sockets'
and no 3rd party extensions are enabled.
The code that is causing the problem exists within a class in a function
called approve_friend. This is called by a "public" page with a
parameter provided in GET being passed to the function approve_friend:
$username = filter_input(INPUT_GET, 'username', FILTER_SANITIZE_STRING);
if (!empty($username))
{
if ($username != $_SESSION['user']['username'])
{
if ($core->user->add_friend($username))
{
echo 1;
}
else
{
echo 2;
}
}
}
There is code in place of echo 1 and echo 2 but it's not relevant. Here,
the code checks to make sure the username submitted is the not the same
as the currently logged in use. If not, it will execute the
$core->user->add_friend function.
add_friend runs through as follows:
1. Makes a call to $this->get_user where it gets data for the username
$username provided when calling the function. It returns an array.
$friend = $this->get_user(1, NULL, $username);
2. Grabs some data from the session about the currently logged in user
$user['name'] = filter_var($_SESSION['user']['name'],
FILTER_SANITIZE_STRING);
$user['user_id'] = filter_var($_SESSION['user']['user_id'],
FILTER_SANITIZE_NUMBER_INT);
$user['username'] = filter_var($_SESSION['user']['username'],
FILTER_SANITIZE_STRING);
$user['friend_count'] = filter_var($_SESSION['user']['friend_count'],
FILTER_SANITIZE_NUMBER_INT);
3. Checks to make sure $friend has a value
if (empty($friend))
{
return false;
}
4. Checks to make sure that the friend being added is not already added.
if (!empty($_SESSION['user']['friends']))
{
if (in_array($friend['user_id'], $_SESSION['user']['friends']))
{
return false;
}
}
This is the point at which there is a problem. If I add this code before #4:
print_r($_SESSION['user']['friends']);
echo $friend['user_id']; exit;
Then I get the following output:
Array ( [0] => 3 ) 3
i.e. $_SESSION['user']['friends'] is an array with the key 0 and the
value 3 and $friend['user_id'] has a value of 3. Therefore, the
in_array() check above will return true and the function will return
false. No further code in the function should execute. This is what
happens on Windows - 2 is output to the page because the add_friend
function has returned false.
Now, after #4, there is more code. This code is only supposed to execute
if the friend doesn't already exist - it adds the friend, increments the
friend count and sends an e-mail.
// Insert into friends
$core->database->exec('INSERT INTO users_friends SET user_id =
"'.$user['user_id'].'", user_friend_id = "'.$friend['user_id'].'",
status = 1');
$core->database->exec('INSERT INTO users_friends SET user_id =
"'.$friend['user_id'].'", user_friend_id = "'.$user['user_id'].'"');
// Update friend count
$core->database->exec('UPDATE users_insiders SET friend_count =
"'.++$user['friend_count'].'" WHERE user_id = "'.$user['user_id'].'"');
// E-mail sending code using phpmailer
return true;
On my Linux server, the function returns false at step #4 as it should
do, but it appears to continue executing. The friend count is
incremented and the page execution slows temporarily whilst the mail is
being sent (not a problem in testing). However, no e-mail actually gets
sent.
The key is that the function is returning false but it continues to
execute! If I stick in an exit; after the in_array() check at point #4,
this doesn't happen. There are no other places where this function is
called, and it is only called once.
Strangely, if I force the values of the 2 variables
before the in_array() check:
$_SESSION['user']['friends'] = array(0 => 3);
$friend['user_id'] = 3;
it reacts as expected - the function returns false and no further code
is executed.
Anyone have any suggestions?
Regards,
David Mytton
attached mail follows:
# david
emomentum.co.uk / 2007-01-22 15:17:16 +0000:
> The key is that the function is returning false but it continues to
> execute! If I stick in an exit; after the in_array() check at point #4,
> this doesn't happen. There are no other places where this function is
> called, and it is only called once.
>
> Strangely, if I force the values of the 2 variables
> before the in_array() check:
>
> $_SESSION['user']['friends'] = array(0 => 3);
> $friend['user_id'] = 3;
>
> it reacts as expected - the function returns false and no further code
> is executed.
>
> Anyone have any suggestions?
You have a bug somewhere in your code.
--
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man. You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991
attached mail follows:
I can't see how there is a bug in my code if when I echo the contents of
the 2 variables, they are exactly the same as when I set them manually.
Except in the former the function "continues executing" but in the
latter it doesn't.
I also cannot see how the function can return false and execute the SQl
query when it is only called once.
David
Roman Neuhauser wrote:
> # david
emomentum.co.uk / 2007-01-22 15:17:16 +0000:
>> The key is that the function is returning false but it continues to
>> execute! If I stick in an exit; after the in_array() check at point #4,
>> this doesn't happen. There are no other places where this function is
>> called, and it is only called once.
>>
>> Strangely, if I force the values of the 2 variables
>> before the in_array() check:
>>
>> $_SESSION['user']['friends'] = array(0 => 3);
>> $friend['user_id'] = 3;
>>
>> it reacts as expected - the function returns false and no further code
>> is executed.
>>
>> Anyone have any suggestions?
>
> You have a bug somewhere in your code.
>
attached mail follows:
# david
emomentum.co.uk / 2007-01-22 15:31:55 +0000:
> Roman Neuhauser wrote:
> ># david
emomentum.co.uk / 2007-01-22 15:17:16 +0000:
> >>The key is that the function is returning false but it continues to
> >>execute! If I stick in an exit; after the in_array() check at point #4,
> >>this doesn't happen. There are no other places where this function is
> >>called, and it is only called once.
> >>
> >>Strangely, if I force the values of the 2 variables
> >>before the in_array() check:
> >>
> >>$_SESSION['user']['friends'] = array(0 => 3);
> >>$friend['user_id'] = 3;
> >>
> >>it reacts as expected - the function returns false and no further code
> >>is executed.
> >>
> >>Anyone have any suggestions?
> >
> >You have a bug somewhere in your code.
>
> I can't see how there is a bug in my code if when I echo the contents of
> the 2 variables, they are exactly the same as when I set them manually.
> Except in the former the function "continues executing" but in the
> latter it doesn't.
>
> I also cannot see how the function can return false and execute the SQl
> query when it is only called once.
You have presented no proof that there's a bug in the PHP. What you
have presented looks like you have a bug, and the function gets called
more than once. Have you used a debugger? See http://xdebug.org/.
--
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man. You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991
attached mail follows:
Yes, I know it looks like a bug in my code because I'm not able to write
a test case that can reproduce it simply enough to report as a bug -
hence why I am posting here. However, the behaviour I am describing
surely suggests some kind of issue somewhere in PHP itself.
My reasoning for this is if I echo the 2 variables I get:
Array ( [0] => 3 )
and
3
and the bug appears. But if I set them manually before the in_array test:
$_SESSION['user']['friends'] = array(0 => 3);
$friend['user_id'] = 3;
it works as expected. Am I wrong in thinking that this has to be a bug
in PHP?
I have used debug_backtrace() to find out what is going on as regards
how many times the function is being executed - that is the first thing
I checked because it does indeed suggest that it is being executed
multiple times, however, the back trace only reveals 1 call/execution.
David
Roman Neuhauser wrote:
> # david
emomentum.co.uk / 2007-01-22 15:31:55 +0000:
>> Roman Neuhauser wrote:
>>> # david
emomentum.co.uk / 2007-01-22 15:17:16 +0000:
>>>> The key is that the function is returning false but it continues to
>>>> execute! If I stick in an exit; after the in_array() check at point #4,
>>>> this doesn't happen. There are no other places where this function is
>>>> called, and it is only called once.
>>>>
>>>> Strangely, if I force the values of the 2 variables
>>>> before the in_array() check:
>>>>
>>>> $_SESSION['user']['friends'] = array(0 => 3);
>>>> $friend['user_id'] = 3;
>>>>
>>>> it reacts as expected - the function returns false and no further code
>>>> is executed.
>>>>
>>>> Anyone have any suggestions?
>>> You have a bug somewhere in your code.
>> I can't see how there is a bug in my code if when I echo the contents of
>> the 2 variables, they are exactly the same as when I set them manually.
>> Except in the former the function "continues executing" but in the
>> latter it doesn't.
>>
>> I also cannot see how the function can return false and execute the SQl
>> query when it is only called once.
>
> You have presented no proof that there's a bug in the PHP. What you
> have presented looks like you have a bug, and the function gets called
> more than once. Have you used a debugger? See http://xdebug.org/.
>
attached mail follows:
On Mon, 2007-01-22 at 16:36 +0000, David Mytton wrote:
> Yes, I know it looks like a bug in my code because I'm not able to write
> a test case that can reproduce it simply enough to report as a bug -
> hence why I am posting here. However, the behaviour I am describing
> surely suggests some kind of issue somewhere in PHP itself.
>
> My reasoning for this is if I echo the 2 variables I get:
>
> Array ( [0] => 3 )
> and
> 3
>
> and the bug appears. But if I set them manually before the in_array test:
>
> $_SESSION['user']['friends'] = array(0 => 3);
> $friend['user_id'] = 3;
>
> it works as expected. Am I wrong in thinking that this has to be a bug
> in PHP?
>
> I have used debug_backtrace() to find out what is going on as regards
> how many times the function is being executed - that is the first thing
> I checked because it does indeed suggest that it is being executed
> multiple times, however, the back trace only reveals 1 call/execution.
A backtrace won't indicate multiple calls unless they are recursive. Try
add the following to your function:
<?php
static $foo = 0;
$foo++;
echo "I've been called $foo times\n";
?>
Cheers,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'
attached mail follows:
I added this in and it outputs 1 as I suspected - the function is being
called only once.
David
Robert Cummings wrote:
> On Mon, 2007-01-22 at 16:36 +0000, David Mytton wrote:
>> Yes, I know it looks like a bug in my code because I'm not able to write
>> a test case that can reproduce it simply enough to report as a bug -
>> hence why I am posting here. However, the behaviour I am describing
>> surely suggests some kind of issue somewhere in PHP itself.
>>
>> My reasoning for this is if I echo the 2 variables I get:
>>
>> Array ( [0] => 3 )
>> and
>> 3
>>
>> and the bug appears. But if I set them manually before the in_array test:
>>
>> $_SESSION['user']['friends'] = array(0 => 3);
>> $friend['user_id'] = 3;
>>
>> it works as expected. Am I wrong in thinking that this has to be a bug
>> in PHP?
>>
>> I have used debug_backtrace() to find out what is going on as regards
>> how many times the function is being executed - that is the first thing
>> I checked because it does indeed suggest that it is being executed
>> multiple times, however, the back trace only reveals 1 call/execution.
>
> A backtrace won't indicate multiple calls unless they are recursive. Try
> add the following to your function:
>
> <?php
>
> static $foo = 0;
> $foo++;
>
> echo "I've been called $foo times\n";
>
> ?>
>
> Cheers,
> Rob.
attached mail follows:
Please don't top post and trim the quoted material if you want me to
discuss this with you.
# david
emomentum.co.uk / 2007-01-22 16:36:40 +0000:
> Roman Neuhauser wrote:
> ># david
emomentum.co.uk / 2007-01-22 15:31:55 +0000:
> >>I also cannot see how the function can return false and execute the SQl
> >>query when it is only called once.
> >
> >You have presented no proof that there's a bug in the PHP. What you
> >have presented looks like you have a bug, and the function gets called
> >more than once. Have you used a debugger? See http://xdebug.org/.
>
> Yes, I know it looks like a bug in my code because I'm not able to write
> a test case that can reproduce it simply enough to report as a bug -
Write tests that prove the code does what you think it does. Which of
these tests will break?
> However, the behaviour I am describing surely suggests some kind of
> issue somewhere in PHP itself.
I still have no reason to believe it. Such a bug in PHP would require
memory corruption in the Zend engine. I run complex code in 5.2 on Linux,
and haven't seen anything like that.
> My reasoning for this is if I echo the 2 variables I get:
>
> Array ( [0] => 3 )
> and
> 3
>
> and the bug appears. But if I set them manually before the in_array test:
>
> $_SESSION['user']['friends'] = array(0 => 3);
> $friend['user_id'] = 3;
>
> it works as expected. Am I wrong in thinking that this has to be a bug
> in PHP?
You haven't shown the complete code, and what you *have* shown didn't
prove anything. Show me that it really gets past the return. var_dump() the
two things your comparing there with in_array() *after* the if() block,
and prove that it's in the same invocation as that return false.
function f()
{
static $x = 0;
$i++;
if (!in_array($friend, $friends)) {
var_dump("inside", $i, $friend, $friends);
return false;
}
var_dump("after", $i, $friend, $friends);
$core->database->exec(...);
}
> I have used debug_backtrace() to find out what is going on as regards
> how many times the function is being executed - that is the first thing
> I checked because it does indeed suggest that it is being executed
> multiple times, however, the back trace only reveals 1 call/execution.
Not suprprising. This code outputs
#0 f(1) called at [/usr/home/roman/tmp/scratch30:8]
#0 f(2) called at [/usr/home/roman/tmp/scratch30:8]
<?php
function f($i)
{
debug_print_backtrace();
}
foreach (range(1, 2) as $i) {
f($i);
}
--
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man. You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991
attached mail follows:
David Mytton wrote:
> Hi,
>
> I have come across what appears to be a bug in PHP, but one that I am
> having difficulty writing test code for. Also, the bug only happens on a
> Linux build of PHP - the code is working as expected on Windows. This is
> on both PHP 5.2.0 and the very latest snapshots:
>
> Windows: 5.2.1RC4-dev Jan 19 2007 16:16:57
> Linux: PHP Version 5.2.1RC4-dev Jan 22 2007 11:54:28
> (php5.2-200701221130.tar.gz)
>
> The configure line is:
>
> './configure' '--with-apxs2=/usr/local/apache2/bin/apxs' '--with-curl'
> '--with-freetype-dir=/usr' '--with-gd' '--with-gettext'
> '--with-jpeg-dir=/usr' '--with-mysql' '--with-openssl'
> '--with-pdo-mysql' '--with-pear' '--with-png-dir=/usr' '--with-zlib'
> '--enable-calendar' '--enable-exif' '--enable-gd-native-ttf'
> '--enable-pdo' '--enable-soap' '--enable-sockets'
>
> and no 3rd party extensions are enabled.
>
> The code that is causing the problem exists within a class in a function
> called approve_friend. This is called by a "public" page with a
> parameter provided in GET being passed to the function approve_friend:
>
> $username = filter_input(INPUT_GET, 'username', FILTER_SANITIZE_STRING);
> if (!empty($username))
> {
> if ($username != $_SESSION['user']['username'])
> {
> if ($core->user->add_friend($username))
> {
> echo 1;
> }
> else
> {
> echo 2;
> }
> }
> }
>
> There is code in place of echo 1 and echo 2 but it's not relevant. Here,
> the code checks to make sure the username submitted is the not the same
> as the currently logged in use. If not, it will execute the
> $core->user->add_friend function.
>
> add_friend runs through as follows:
>
> 1. Makes a call to $this->get_user where it gets data for the username
> $username provided when calling the function. It returns an array.
>
> $friend = $this->get_user(1, NULL, $username);
>
> 2. Grabs some data from the session about the currently logged in user
>
> $user['name'] = filter_var($_SESSION['user']['name'],
> FILTER_SANITIZE_STRING);
> $user['user_id'] = filter_var($_SESSION['user']['user_id'],
> FILTER_SANITIZE_NUMBER_INT);
> $user['username'] = filter_var($_SESSION['user']['username'],
> FILTER_SANITIZE_STRING);
> $user['friend_count'] = filter_var($_SESSION['user']['friend_count'],
> FILTER_SANITIZE_NUMBER_INT);
>
> 3. Checks to make sure $friend has a value
>
> if (empty($friend))
> {
> return false;
> }
>
> 4. Checks to make sure that the friend being added is not already added.
>
> if (!empty($_SESSION['user']['friends']))
> {
> if (in_array($friend['user_id'], $_SESSION['user']['friends']))
> {
> return false;
> }
> }
>
> This is the point at which there is a problem. If I add this code before
> #4:
>
> print_r($_SESSION['user']['friends']);
> echo $friend['user_id']; exit;
>
> Then I get the following output:
>
> Array ( [0] => 3 ) 3
>
> i.e. $_SESSION['user']['friends'] is an array with the key 0 and the
> value 3 and $friend['user_id'] has a value of 3. Therefore, the
> in_array() check above will return true and the function will return
> false. No further code in the function should execute. This is what
> happens on Windows - 2 is output to the page because the add_friend
> function has returned false.
>
> Now, after #4, there is more code. This code is only supposed to execute
> if the friend doesn't already exist - it adds the friend, increments the
> friend count and sends an e-mail.
>
> // Insert into friends
> $core->database->exec('INSERT INTO users_friends SET user_id =
> "'.$user['user_id'].'", user_friend_id = "'.$friend['user_id'].'",
> status = 1');
> $core->database->exec('INSERT INTO users_friends SET user_id =
> "'.$friend['user_id'].'", user_friend_id = "'.$user['user_id'].'"');
>
> // Update friend count
> $core->database->exec('UPDATE users_insiders SET friend_count =
> "'.++$user['friend_count'].'" WHERE user_id = "'.$user['user_id'].'"');
>
> // E-mail sending code using phpmailer
>
> return true;
>
> On my Linux server, the function returns false at step #4 as it should
> do, but it appears to continue executing. The friend count is
> incremented and the page execution slows temporarily whilst the mail is
> being sent (not a problem in testing). However, no e-mail actually gets
> sent.
>
> The key is that the function is returning false but it continues to
> execute! If I stick in an exit; after the in_array() check at point #4,
> this doesn't happen. There are no other places where this function is
> called, and it is only called once.
>
> Strangely, if I force the values of the 2 variables
> before the in_array() check:
>
> $_SESSION['user']['friends'] = array(0 => 3);
> $friend['user_id'] = 3;
>
> it reacts as expected - the function returns false and no further code
> is executed.
>
> Anyone have any suggestions?
>
> Regards,
>
> David Mytton
>
At the very bottom of your function place another return with a string
like return 'FOUND THE END OF FUNCTION';
now, echo the return of the function and see if it really the return
function that you think it is that is returning false, or you are just
hitting the end of the function.
Jim
attached mail follows:
> At the very bottom of your function place another return with a string
> like return 'FOUND THE END OF FUNCTION';
>
> now, echo the return of the function and see if it really the return
> function that you think it is that is returning false, or you are just
> hitting the end of the function.
>
> Jim
>
Yeah I tried this - I have confirmed that the return is the one I think
it is.
However, it seems this is actually being caused by some weirdness with
mod_rewrite. Basically, if I use the rewritten URL e.g.
example.com/section/addfriend/will/ which rewrites to
index.php?cmd=section/addfriend&username=will
I get this bug. But if I access
index.php?cmd=section/addfriend&username=will directly then it works fine.
This is definitely not a bug in my code but something to do with PHP,
Apache and/or mod_rewrite.
Unless anyone can suggest otherwise, I think it's going to be far too
complex to debug and produce a test case because of the complexity of
the code and working out where the bug actually is in PHP, Apache or
mod_rewrite. So I'm just going to work around it.
David
attached mail follows:
# david
emomentum.co.uk / 2007-01-22 17:45:23 +0000:
> However, it seems this is actually being caused by some weirdness with
> mod_rewrite. Basically, if I use the rewritten URL e.g.
>
> example.com/section/addfriend/will/ which rewrites to
> index.php?cmd=section/addfriend&username=will
>
> I get this bug. But if I access
> index.php?cmd=section/addfriend&username=will directly then it works fine.
>
> This is definitely not a bug in my code but something to do with PHP,
> Apache and/or mod_rewrite.
Can we see your mod_rewrite configuration? RewriteCond, RewriteRule, all
that jazz.
--
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man. You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991
attached mail follows:
Roman Neuhauser wrote:
> Can we see your mod_rewrite configuration? RewriteCond, RewriteRule, all
> that jazz.
There are a number of rules but the only one that is relevant for this
page is:
RewriteRule ^section/addfriend(/)?(.*)$
index.php?cmd=section/addfriend&username=$2
David
attached mail follows:
# david
emomentum.co.uk / 2007-01-22 18:48:27 +0000:
> Roman Neuhauser wrote:
> >Can we see your mod_rewrite configuration? RewriteCond, RewriteRule, all
> >that jazz.
>
> There are a number of rules but the only one that is relevant for this
> page is:
>
> RewriteRule ^section/addfriend(/)?(.*)$ index.php?cmd=section/addfriend&username=$2
Ok, what does RewriteLog contain for one such request?
RewriteLogLevel 9.
--
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man. You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991
attached mail follows:
Roman Neuhauser wrote:
> Ok, what does RewriteLog contain for one such request?
> RewriteLogLevel 9.
http://paste.lisp.org/display/35779
David
attached mail follows:
# david
emomentum.co.uk / 2007-01-22 19:28:29 +0000:
> Roman Neuhauser wrote:
> >Ok, what does RewriteLog contain for one such request?
> >RewriteLogLevel 9.
>
> http://paste.lisp.org/display/35779
As you can see, the processing doesn't stop when it hits the RewriteRule
you thought was the only relevant (lines 6, 7):
91.84.87.114 - - [22/Jan/2007:19:20:56 +0000] [example.com/sid#91e8128][rid#9235280/initial] (3) [perdir /home/example/public_html/] applying pattern '^section/addfriend(/)?(.*)$' to uri 'section/addfriend/will'
91.84.87.114 - - [22/Jan/2007:19:20:56 +0000] [example.com/sid#91e8128][rid#9235280/initial] (2) [perdir /home/example/public_html/] rewrite 'section/addfriend/will' -> 'index.php?cmd=section/addfriend&username=will'
I think this paragraph from the apache manual applies to you:
# Note: When you use this flag, make sure that the substitution field is
# a valid URL! Otherwise, you will be redirecting to an invalid
# location. Remember that this flag on its own will only prepend
# http://thishost[:thisport]/ to the URL, and rewriting will continue.
# Usually, you will want to stop rewriting at this point, and redirect
# immediately. To stop rewriting, you should add the 'L' flag.
--
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man. You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991
attached mail follows:
# neuhauser
sigpipe.cz / 2007-01-22 20:45:42 +0000:
> # david
emomentum.co.uk / 2007-01-22 19:28:29 +0000:
> > Roman Neuhauser wrote:
> > >Ok, what does RewriteLog contain for one such request?
> > >RewriteLogLevel 9.
> >
> > http://paste.lisp.org/display/35779
>
> As you can see, the processing doesn't stop when it hits the RewriteRule
> you thought was the only relevant (lines 6, 7):
>
> 91.84.87.114 - - [22/Jan/2007:19:20:56 +0000] [example.com/sid#91e8128][rid#9235280/initial] (3) [perdir /home/example/public_html/] applying pattern '^section/addfriend(/)?(.*)$' to uri 'section/addfriend/will'
> 91.84.87.114 - - [22/Jan/2007:19:20:56 +0000] [example.com/sid#91e8128][rid#9235280/initial] (2) [perdir /home/example/public_html/] rewrite 'section/addfriend/will' -> 'index.php?cmd=section/addfriend&username=will'
>
> I think this paragraph from the apache manual applies to you:
Bzzzt, I'm an idiot. It doesn't, of course. You're still missing [L]
and that's what I was trying to point you at until the cat ran over my
keyboard...
--
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man. You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991
attached mail follows:
Roman Neuhauser wrote:
> Bzzzt, I'm an idiot. It doesn't, of course. You're still missing [L]
> and that's what I was trying to point you at until the cat ran over my
> keyboard...
Alright. So if the rewrite rules were (and they are):
RewriteRule ^section/account(/)?$ index.php?cmd=section/account
RewriteRule ^section/addfriend(/)?(.*)$
index.php?cmd=section/addfiend&username=$2
RewriteRule ^section/approvefriend(/)?(.*)$
index.php?cmd=section/approvefriend&username=$
RewriteRule ^section/deletefriend(/)?(.*)$
index.php?cmd=section/deletefriend&username=$2
RewriteRule ^section(/)?$ index.php?cmd=section/index
RewriteRule ^anothersection(/)?(.*)$
index.php?cmd=listingnav&url=anothersection/$2
Where would the correct place be?
David
attached mail follows:
# david
emomentum.co.uk / 2007-01-22 19:56:58 +0000:
> Roman Neuhauser wrote:
> >Bzzzt, I'm an idiot. It doesn't, of course. You're still missing [L]
> >and that's what I was trying to point you at until the cat ran over my
> >keyboard...
>
> Alright. So if the rewrite rules were (and they are):
>
> RewriteRule ^section/account(/)?$ index.php?cmd=section/account
> RewriteRule ^section/addfriend(/)?(.*)$ index.php?cmd=section/addfiend&username=$2
> RewriteRule ^section/approvefriend(/)?(.*)$ index.php?cmd=section/approvefriend&username=$
> RewriteRule ^section/deletefriend(/)?(.*)$ index.php?cmd=section/deletefriend&username=$2
> RewriteRule ^section(/)?$ index.php?cmd=section/index
>
> RewriteRule ^anothersection(/)?(.*)$ index.php?cmd=listingnav&url=anothersection/$2
>
> Where would the correct place be?
append [L,NS] to all RewriteRules
--
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man. You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991
attached mail follows:
Roman Neuhauser wrote:
> append [L,NS] to all RewriteRules
Done that, but the problem is still there - doesn't seem to have made
any difference.
David
attached mail follows:
# david
emomentum.co.uk / 2007-01-22 21:17:04 +0000:
> Roman Neuhauser wrote:
> >append [L,NS] to all RewriteRules
>
> Done that, but the problem is still there - doesn't seem to have made
> any difference.
Can I see the rewrite log for a single request now? Please make sure
it's only one request.
--
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man. You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991
attached mail follows:
Roman Neuhauser wrote:
> Can I see the rewrite log for a single request now? Please make sure
> it's only one request.
http://paste.lisp.org/display/35791
David
attached mail follows:
# david
emomentum.co.uk / 2007-01-22 22:03:30 +0000:
> Roman Neuhauser wrote:
> >Can I see the rewrite log for a single request now? Please make sure
> >it's only one request.
>
> http://paste.lisp.org/display/35791
Are you sure you added the NS flag? It looks like the RewriteRules
are applied to the result of the original rewrite.
And, I see TWO requests for addfriend:
rewrite 'section/addfriend/will' -> 'index.php?cmd=section/addfriend&username=will'
rewrite 'section/addfriend/templates/js/jquery.js' -> 'index.php?cmd=section/addfriend&username=templates/js/jquery.js'
--
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man. You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991
attached mail follows:
Hi guys, I´m beginner in php, so I need some help. I have to make a
script to send SMS to moviles phones, can you give some ideas how to
make it please... Thank you
attached mail follows:
# marcefm
gmail.com / 2007-01-22 11:17:55 -0400:
> Hi guys, I´m beginner in php, so I need some help. I have to make a
> script to send SMS to moviles phones, can you give some ideas how to
> make it please... Thank you
Are you new to PHP or SMS? What specific problems do you have? Did you
google for "php sms gateway"?
If you came here for a complete menu, sorry: TANSTAAFL (before you ask:
google for "define tanstaafl").
--
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man. You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991
attached mail follows:
[snip]
Hi guys, I´m beginner in php, so I need some help. I have to make a
script to send SMS to moviles phones, can you give some ideas how to
make it please... Thank you
[/snip]
SMS can be sent to mobiles as an email. Most cellphone providers offer a gateway for this. See:
http://www.tech-recipes.com/rx/939/sms_email_cingular_nextel_sprint_tmobile_verizon_virgin
for more information and a list of major carriers (for the US at least).
Regards,
Jesse R. Castro
Applications Developer, Pocket Communications jcastro
pocket.com
attached mail follows:
On 1/20/07, blackwater dev <blackwaterdev
gmail.com> wrote:
>
> Does anyone have recommendations for an open source php based,
> 'lightweight', scheduling app? I just want something clean that I can use
> to schedule trainings within our company. I need to be able to put in
> details for each training and then see a synopsis on a calender. Just a
> basic scheduler but clean and useful.
>
> Thanks!
>
>
We've used something called Meeting Room Booking ... "System", I believe
(MRBS). It's been a great help.
David
attached mail follows:
Here is my rendition of your script. Give it a shot...
Let me know if you have any question about what is going on.
I was curious, what is the point of having the alternating column
colors? Was that your intention?
<?php
function invlistONE(){
dbconnect('connect');
$invlist = mysql_query("SELECT * FROM sp_dvd
ORDER BY dvdGenre");
echo <<<HEREDOC
<style type="text/css">
.dvdDisplay th {
font-size: 9pt;
text-align: left;
}
.dvdDisplay td {
font-size: 8pt;
}
</style>
<table cellspacing="0" id='dvdDisplay">
<thead>
<tr>
<th width="20" class="body">DVD ID</th>
<th width="225">TITLE</th>
<th width="75" class="body">GENRE 1</th>
<th width="75">GENRE 2</th>
<th width="75" class="body">GENRE 3</th>
<th width="10">ACT</th>
<th width="10" class="body">QTY</th>
<th width="10">BCK</b></th>
<th width="10" class="body">HLD</th>
<th width="10">INC</b></th>
<th width="50" class="body">OG USR</th>
<th width="30">OUT DATE</th>
<th width="55" class="body">OUT USR</th>
<th width="30">IN DATE</th>
<th width="50" class="body">IN USR</th>
<th width="10">CY</th>
</tr>
</thead>
<tbody>
HEREDOC;
$count = 0;
while ( $row = mysql_fetch_array( $invlist ) ) {
if ( $count % 1 ) {
$rowColor = '#c1c1c1';
} else {
$rowColor = '';
}
echo <<<HEREDOC
<tr bgcolor="{$rowColor}">
<td class='body'>{$row['dvdId']</td>
<td>{$row['dvdTitle']}</td>
<td class='body'>{$row['dvdGenre']}</td>
<td>{$row['dvdGenre2']}</td>
<td class='body'>{$row['dvdGenre3']}</td>
<td>{$row['dvdActive']}</td>
<td class='body'>{$row['dvdOnHand']}</td>
<td>{$row['backordered']}</td>
<td class='body'>{$row['dvdHoldRequests']}</td>
<td>{$row['incomingInverntory']}</td>
<td class='body'>{$row['ogUserId']}</td>
<td>{$row['outDate']}</td>
<td class='body'>{$row['outUserId']}</td>
<td>{$row['inDate']}</td>
<td class='body'>{$row['inUserId']}</td>
<td>{$row['cycles']}</td>
</tr>
HEREDOC;
$count++;
echo '</tbody></table>';
}
}
?>
attached mail follows:
Don wrote:
> magic_quotes_gpc On On
> magic_quotes_runtime Off Off
> magic_quotes_sybase Off Off
>
> but I know if I can change that
>
> is there some other way to fix this problem?
>
> Don
>
>
>
> # don.rzeszut
gmail.com / 2007-01-20 21:50:48 -0700:
>> I have a line of code that validates form info for some POST vars, but not
>> others.
>>
>> if (!ereg("^[A-Za-z' -]{1,50}$",$_POST[$field]) )
>>
>> when I put O'Toole in the form to test, my script kicks the page back (I
>> thought this entry would be OK)
>>
>> but moreover, when it redisplays the form and populates the new form with
>> the entries previously entered, O'Toole becomes O\
>
> magic_quotes_gpc?
>
stripslashes() ?
attached mail follows:
Hi All,
It was possible to send embeded image on mail() function.
Curently, I'm using linked image to send image on mail.
Thanks in advance
bn
attached mail follows:
# bnugroho
aitemail.com / 2007-01-23 02:10:45 +0700:
> It was possible to send embeded image on mail() function.
> Curently, I'm using linked image to send image on mail.
Yes, see RFC2045 and perhaps http://pear.php.net/package/Mail_Mime
--
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man. You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991
attached mail follows:
so what?
t
Bagus Nugroho wrote:
> Hi All,
>
> It was possible to send embeded image on mail() function.
> Curently, I'm using linked image to send image on mail.
>
> Thanks in advance
> bn
>
>
>
>
>
>
>
attached mail follows:
There is a nice website with tons of PHP classes:
http://www.phpclasses.org
Once I have found on it a class that was doing what you need now (send
emails with attachements in it). Can't remember the name, but I'm sure
that you can find it.
Sergiu
Bagus Nugroho wrote:
> Hi All,
>
> It was possible to send embeded image on mail() function.
> Curently, I'm using linked image to send image on mail.
>
> Thanks in advance
> bn
>
>
>
>
>
>
>
attached mail follows:
I want to output the file contents of a folder to a php page and provide a
link for them to be downloaded.
This is what I have so far but I cannot get a filename or get it to iterate
through all the files in a folder.
<?php
$dir = "mydirectory";
// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
echo filetype($file) . "\n";
echo filesize($file);
}
closedir($dh);
}
}
?>
attached mail follows:
# ross
aztechost.com / 2007-01-22 20:25:49 -0000:
> $dir = "mydirectory";
>
> // Open a known directory, and proceed to read its contents
> if (is_dir($dir)) {
> if ($dh = opendir($dir)) {
> while (($file = readdir($dh)) !== false) {
>
> echo filetype($file) . "\n";
> echo filesize($file);
> }
> closedir($dh);
> }
> }
>
>
> This is what I have so far but I cannot get a filename or get it to iterate
> through all the files in a folder.
What does it do instead?
--
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man. You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991
attached mail follows:
Where could I get instructions to set up a network time protocol through
my web site hosting server? Ron
attached mail follows:
# ron.php
actsministries.org / 2007-01-22 16:44:32 -0500:
> Where could I get instructions to set up a network time protocol through
> my web site hosting server? Ron
enter "man ntpd" on your web site hosting server.
--
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man. You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991
attached mail follows:
Hi everyone,
Hopefully you all can help! I¹m at a loss as to what to do next. I¹m
running PHP 5.1.2 with Apache 2.0.55 on RedHat ES4 and I keep getting the
following PHP error when trying to upload a larger file. I have
AllowOverride turned on in the httpd.conf file so my .htaccess file is below
as well. When I look at phpinfo() it reflects the changes in the .htaccess
file but yet still I get the following PHP fatal error. Anyone have any
ideas what could be going on? Could it be the Zend Memory Manager
(something that I know nothing about)? Or anything else I may not be aware
of?
Any help would be greatly appreciated!
Fatal error: Allowed memory size of 20971520 bytes exhausted (tried to
allocate 19590657 bytes) in /path/to/php/file on line 979
LimitRequestBody 0
php_value memory_limit 40M
php_value post_max_size 30M
php_value upload_max_filesize 30M
php_value display_errors On
php_value max_execution_time 300
php_value max_input_time 300
attached mail follows:
Jay Paulson wrote:
> Hi everyone,
>
> Hopefully you all can help! I¹m at a loss as to what to do next. I¹m
> running PHP 5.1.2 with Apache 2.0.55 on RedHat ES4 and I keep getting the
> following PHP error when trying to upload a larger file. I have
> AllowOverride turned on in the httpd.conf file so my .htaccess file is below
> as well. When I look at phpinfo() it reflects the changes in the .htaccess
> file but yet still I get the following PHP fatal error. Anyone have any
> ideas what could be going on? Could it be the Zend Memory Manager
> (something that I know nothing about)? Or anything else I may not be aware
> of?
>
> Any help would be greatly appreciated!
>
>
> Fatal error: Allowed memory size of 20971520 bytes exhausted (tried to
> allocate 19590657 bytes) in /path/to/php/file on line 979
>
> LimitRequestBody 0
> php_value memory_limit 40M
> php_value post_max_size 30M
> php_value upload_max_filesize 30M
> php_value display_errors On
> php_value max_execution_time 300
> php_value max_input_time 300
>
doesn't seem to me that it is following the directives for memory size
OR or you are up against a 20mb disk quota possibly???
--
Enjoy,
Jim Lucas
Different eyes see different things. Different hearts beat on different
strings. But there are times for you and me when all such things agree.
- Rush
attached mail follows:
Here's a simple makefile I want PHP's exec to execute make on:
KEYLIST := keylist.txt
DEPS := $(wildcard *.txt)
FILES := *.txt
$(KEYLIST): $(DEPS)
grep ^keywords $(FILES) > $
now when I use make from command line, it works as expected,
the keylist.txt file is created. however, when I use PHP exec
to run make on the makefile, the keylist.txt file is not generated.
* if keylist.txt does not need updating, PHP exec make works,
make says keylist.txt is up to date.
* if i remove redirection, PHP exec make shows that grep is
making the same matches as make from commandline.
Why does the redirection of the grep command (within the makefile)
only work when I execute make from the commandline but not from
PHP exec||shell_exec?
One sollution is to abandon redirection and get the output from
grep into a string and then get PHP to create keylist.txt, but
why do that?
Any help appreciated.
Cheers,
James.
attached mail follows:
# james
jwm-art.net / 2007-01-22 23:45:09 +0000:
> Here's a simple makefile I want PHP's exec to execute make on:
>
> KEYLIST := keylist.txt
> DEPS := $(wildcard *.txt)
> FILES := *.txt
>
> $(KEYLIST): $(DEPS)
> grep ^keywords $(FILES) > $
Does that line in the real Makefile begin with a tab? It must.
Why is it so roundabout about $(DEPS)/$(FILES)? The target *actuall*
depends on different files than those declared in the sources list!
What does $(DEPS) (and $(FILES)) contain?
This is what your Makefile does, BTW:
grep ^keywords keylist.txt ... > keylist.txt
Try it with this instead (rename keylist.txt to key.list), but make sure
you have at least one file ending in .txt in that directory first!):
KEYLIST := key.list
FILES := $(wildcard *.txt)
$(KEYLIST): $(FILES) ; grep '^keywords' $^ > $
--
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man. You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991
attached mail follows:
I'm trying to get this but not quite there. I want to allow the following
characters.
A-Za-z0-9!
#$%&()*;:_.'/\ and a space.
Is there a special order these need to be in or escaped somehow. For
example, if I just allow _' the ' is fine, if I add the other characters,
the ' gets preceded by a \ and an error is returned. If I take the ' out of
the sting below it works fine, I get no errors returned. I am also using
stripslashes on the variable.
This is my code. (although I have tried various things with it trying to get
it right)
if(preg_match("/^[-A-Za-z0-9!
#%&\(\)\*;:_.\'\$ ]+$/", $string)) {
Thanks
attached mail follows:
At 1/22/2007 03:04 PM, Beauford wrote:
>I'm trying to get this but not quite there. I want to allow the following
>characters.
>
>A-Za-z0-9!
#$%&()*;:_.'/\ and a space.
>
>Is there a special order these need to be in or escaped somehow. For
>example, if I just allow _' the ' is fine, if I add the other characters,
>the ' gets preceded by a \ and an error is returned. If I take the ' out of
>the sting below it works fine, I get no errors returned. I am also using
>stripslashes on the variable.
>
>This is my code. (although I have tried various things with it trying to get
>it right)
>
>if(preg_match("/^[-A-Za-z0-9!
#%&\(\)\*;:_.\'\$ ]+$/", $string)) {
Please read this page:
Pattern Syntax -- Describes PCRE regex syntax
http://ca.php.net/manual/en/reference.pcre.pattern.syntax.php
specifically the section on character classes:
http://ca.php.net/manual/en/reference.pcre.pattern.syntax.php#regexp.reference.squarebrackets
In PREG there are few characters that you need to escape in a
character class expression:
1) ^ must be escaped (\^) if it's the first character (it negates the
match when it's unescaped in the first position).
2) ] must be escaped (\]) unless it's the first character of the
class (it closes the class if it appears later and is not escaped).
3) \ must be escaped (\\) if you're referring to the backslash
character rather than using backslash to escape another character.
4) Control codes such as \b for backspace (not to be confused with \b
which means word boundary outside of a character class).
In addition, you may need to escape certain characters in PHP if
you're expressing the RegExp pattern in a quoted string, such as
single or double quotes (whichever you're using to quote the pattern):
'[\'"]' escape the apostophe
"['\"]" escape the quotation mark
Those are PHP escapes -- by the time PREG sees the pattern, the PHP
compiler has rendered it to:
['"]
And then of course there's the complication that both PREG and PHP
use the backslash as the escape character, so the pattern:
[\\] escape the backslash
must be expressed in PHP as:
[\\\\] escape the escape and the backslash
Interestingly, PHP compiles both \\\ and \\\\ as \\, go figure. I
use \\\\ to escape both backslashes to maintain some semblance of
logic and order in these eye-crossing expressions.
Because PHP requires quotes to be escaped, I find it easier to write
& debug patterns in PHP if I express them in heredoc where quoting
and most escaping is unnecessary:
$sPattern = <<<_
['"\\\\]
_;
becomes the PREG pattern ['"\\].
So to address your character class:
>A-Za-z0-9!
#$%&()*;:_.'/\ and a space.
I'd use the pattern:
[A-Za-z0-9!
#$%&()*;:_.'/\\ ]
where the only character I need to escape is the backslash itself.
In PHP this would be:
$sPattern = '[A-Za-z0-9!
#$%&()*;:_.\'/\\\\ ]';
(escaped apostrophe & blackslash)
or:
$sPattern = "[A-Za-z0-9!
#$%&()*;:_.'/\\\\ ]";
(escaped blackslash)
or:
$sPattern = <<<_
[A-Za-z0-9!
#$%&()*;:_.'/\\\\ ]
_;
(escaped blackslash)
Regards,
Paul
__________________________
Juniper Webcraft Ltd.
http://juniperwebcraft.com
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]