OSEC

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 31 Oct 2005 17:59:29 -0000 Issue 3768

php-general-digest-helplists.php.net
Date: Mon Oct 31 2005 - 11:59:29 CST


php-general Digest 31 Oct 2005 17:59:29 -0000 Issue 3768

Topics (messages 224863 through 224894):

Re: Type of form element
        224863 by: Richard Lynch
        224871 by: Marcus Bointon
        224878 by: Chris Shiflett
        224885 by: Marcus Bointon
        224887 by: Robert Cummings
        224890 by: Chris Shiflett
        224893 by: Richard Lynch
        224894 by: Richard Lynch

Re: [DONE] Substr by words
        224864 by: Richard Lynch
        224868 by: Marcus Bointon

Re: eval();
        224865 by: Josh McDonald

php mail function vs smtp server
        224866 by: Clive
        224867 by: Paul Waring
        224869 by: Richard Davey
        224870 by: Richard Heyes
        224873 by: Paul Waring
        224874 by: Marcus Bointon
        224875 by: Paul Waring

Re: Substr by words
        224872 by: Marcus Bointon
        224876 by: Gustavo Narea

PHP 4.4.1 has been released
        224877 by: Derick Rethans

Problem with Regexp
        224879 by: Yannick Mortier
        224883 by: Richard Heyes
        224892 by: Richard Lynch

getting rid of bad characters
        224880 by: Dan McCullough
        224881 by: tg-php.gryffyndevelopment.com
        224882 by: Ben Litton
        224884 by: Chris Shiflett
        224891 by: Richard Lynch

Re: Using Ajax to spit out a php-generated embed tag
        224886 by: Graham Anderson

pls suggest a good and tested B2B software
        224888 by: Denis L. Menezes
        224889 by: Robert Cummings

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscribelists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscribelists.php.net

To post to the list, e-mail:
        php-generallists.php.net

----------------------------------------------------------------------

attached mail follows:


On Sun, October 30, 2005 5:52 am, Marcus Bointon wrote:
> On 29 Oct 2005, at 20:59, Richard Lynch wrote:
>
>> So you will most likely be using isset($_POST['checkbox_name'])
>> rather
>> than testing for "on"
>
> I classify using isset for checking for the existence of array keys
> to be a bad habit as in some common cases it will not work as you
> expect, for example:
>
> <input type="checkbox" name="checkbox_name" />

A)
If you do not specify a "value=" in HTML for a checkbox, the value is
"on" by default.

So this should give you checkbox_name=on in a GET form.

If it doesn't, your browser is very very very broken.
[Probably Internet Explorer would be the one to get this wrong, if any
of them do]

B)
I dunno what version of PHP you are using, nor what php.ini settings
you have, but, at least in my version/settings:

http://example.com/test.php?checkbox_name=
isset($_GET['checkbox_name']) returns 1

Since HTTP and HTML have no concept of NULL, I'm not real worried that
$_GET will have NULL values in it.

I am certainly not going to pollute $_GET/$_POST/$_REQUEST by stuffing
NULL values into them!

If you want to do things that way, go right ahead.

But I really do believe isset($_POST['checkbox_name']) is a "good"
coding practice.

DSFDD

--
Like Music?
http://l-i-e.com/artists.htm

attached mail follows:


On 31 Oct 2005, at 06:18, Richard Lynch wrote:

> But I really do believe isset($_POST['checkbox_name']) is a "good"
> coding practice.

OK, so PHP may not pass through unset params as NULL (it's not up to
the browser), but if you don't select any checkboxes at all, the
param won't exist, and asking for an index of something that doesn't
exist is normally a good way to generate notices. isset's job is not
to tell you if an array key exists, so why use it for that purpose?

This is the difference I'm on about:

$z = array('a' => 1, 'b' => NULL);
echo array_key_exists('a', $z)?"yes\n":"no\n";
echo isset($z['a'])?"yes\n":"no\n";
echo array_key_exists('b', $z)?"yes\n":"no\n";
echo isset($z['b'])?"yes\n":"no\n";

This prints:

yes
yes
yes
no

That last 'no' has huge bug potential.

I'm not saying it doesn't have practical use, but I wouldn't call it
good practice, and I wouldn't advise people to do it that way in new
code. As it happens, isset _will_ usually work for things that come
through the web-driven superglobals, but not all arrays come from
there - if you use the same syntax for dealing with databases or your
own objects you could be creating some very entertaining bugs. I
don't know about you but I often deal with arrays containing NULL
values where using isset would be very wrong.

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
marcussynchromedia.co.uk | http://www.synchromedia.co.uk

attached mail follows:


Marcus Bointon wrote:
> OK, so PHP may not pass through unset params as NULL (it's not up to
> the browser)

Well, it's certainly not up to PHP. Think about it.

Let me give you an example to try:

<form action="test.php" method="POST">
<input type="checkbox" name="foo" value="" />
<input type="submit" />
</form>
<pre>
<?php print_r($_POST); ?>
</pre>

If you don't check the checkbox, the HTTP request sent by the browser
looks something like this:

POST /test.php HTTP/1.1
Host: example.org
  Referer: http://example.org/test.php
Content-Type: application/x-www-form-urlencoded
Content-Length: 0

  If you do check it, the request looks like this:

POST /test.php HTTP/1.1
Host: example.org
Referer: http://example.org/test.php
Content-Type: application/x-www-form-urlencoded
Content-Length: 4

foo=

Given this, it should come as no surprise that $_POST['foo'] does not
exist when you do not check the checkbox, but it does exist when you do.

Hopefully it is also clear that your argument revolves around the idea
that PHP would create $_POST['foo'] as NULL if the checkbox is not
checked. This is wrong for two reasons:

1. How would PHP know what to name it? :-)
2. NULL is not a string, and everything in $_POST is a string.

Hope that helps.

Chris

--
Chris Shiflett
Brain Bulb, The PHP Consultancy
http://brainbulb.com/

attached mail follows:


On 31 Oct 2005, at 14:54, Chris Shiflett wrote:

> Hopefully it is also clear that your argument revolves around the
> idea that PHP would create $_POST['foo'] as NULL if the checkbox is
> not checked. This is wrong for two reasons:

No, no, that's not what I said - I wouldn't contemplate such
silliness! The thing I was wrong on is that PHP converts unset
parameters (as opposed to nonexistent ones which it obviously can't
do anything about) to an empty string, e.g. given ?a=&b=1, $_REQUEST
['a'] is "", not NULL. However, it still serves to underline my other
point that using isset without actually knowing that is a potentially
dangerous thing. Getting into the habit of using it for looking in
the likes of $_REQUEST means you're likely to use it other places
where you have no such guarantee, and you'll have a bug to track
down. Using array_key_exists means you will never be exposed to this
possibility, no matter where your data comes from.

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
marcussynchromedia.co.uk | http://www.synchromedia.co.uk

attached mail follows:


On Mon, 2005-10-31 at 11:33, Marcus Bointon wrote:
> On 31 Oct 2005, at 14:54, Chris Shiflett wrote:
>
> > Hopefully it is also clear that your argument revolves around the
> > idea that PHP would create $_POST['foo'] as NULL if the checkbox is
> > not checked. This is wrong for two reasons:
>
> No, no, that's not what I said - I wouldn't contemplate such
> silliness! The thing I was wrong on is that PHP converts unset
> parameters (as opposed to nonexistent ones which it obviously can't
> do anything about) to an empty string, e.g. given ?a=&b=1, $_REQUEST
> ['a'] is "", not NULL.

Ummm that's not a conversion, the 'a' parameter is there with exactly 0
characters, thus it is a 0 length string. That's not a PHP idiosyncrasy,
I'm pretty sure that's the standard.

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:


Marcus Bointon wrote:
> The thing I was wrong on is that PHP converts unset parameters (as
> opposed to nonexistent ones which it obviously can't do anything
> about) to an empty string, e.g. given ?a=&b=1, $_REQUEST ['a'] is
> "", not NULL.

That's right, except we seem to have a vocabulary discrepancy:

1. To me, "unset" and "not set" are not the same thing (sort of like how
"untie" and "not tied" are also not the same). I'm assuming you always
mean "not set" in your comments. Otherwise, it sounds like you're
describing some sort of conversion from one state to another. PHP is
just taking what it is given.

2. Given the above assumption, there is no difference between something
not being set and something not existing.

If you want to distinguish between $_GET['a'] and $_GET['b'] in your
example above, empty() does the trick. Some people use strlen() if they
want to also distinguish between the string 0 and the empty string, and
you can always just compare something to the empty string.

> However, it still serves to underline my other point that using
> isset without actually knowing that is a potentially dangerous
> thing.

I think Richard knew what he was doing. :-) If his approach is wrong,
then so is mine, because I also use isset() to see whether a checkbox
was checked. If you go back to my previous example, you'll see that array

> Getting into the habit of using it for looking in the likes of
> $_REQUEST means you're likely to use it other places where you
> have no such guarantee, and you'll have a bug to track down.
> Using array_key_exists means you will never be exposed to this
> possibility, no matter where your data comes from.

I understand and appreciate your argument. However, you're now
describing a social issue, not a technical one. These issues tend to be
more subjective, so "right" answers are difficult to find. :-)

In this case, the only concern would be that PHP considers something set
to NULL to be the same as not being set at all (as far as isset() is
concerned). This situation can never exist with things like $_GET and
$_POST, because everything in those arrays is a string.

Hope that helps.

Chris

--
Chris Shiflett
Brain Bulb, The PHP Consultancy
http://brainbulb.com/

attached mail follows:


On Mon, October 31, 2005 4:38 am, Marcus Bointon wrote:
> On 31 Oct 2005, at 06:18, Richard Lynch wrote:
>
>> But I really do believe isset($_POST['checkbox_name']) is a "good"
>> coding practice.
>
> OK, so PHP may not pass through unset params as NULL (it's not up to
> the browser), but if you don't select any checkboxes at all, the
> param won't exist, and asking for an index of something that doesn't
> exist is normally a good way to generate notices. isset's job is not
> to tell you if an array key exists, so why use it for that purpose?

You're wrong.

isset() does not, under any circumstances, create an index nor a
variable.

Its entire purpose *IS* to tell you if something has been set to a value.

That's why it's CALLED "isSet"

> This is the difference I'm on about:
>
> $z = array('a' => 1, 'b' => NULL);
> echo array_key_exists('a', $z)?"yes\n":"no\n";
> echo isset($z['a'])?"yes\n":"no\n";
> echo array_key_exists('b', $z)?"yes\n":"no\n";
> echo isset($z['b'])?"yes\n":"no\n";
>
> This prints:
>
> yes
> yes
> yes
> no
>
> That last 'no' has huge bug potential.

I really don't want to argue with you about the semantics of NULL,
but, as far as I'm concerned, the number of places where a NULL value
existing in an array should have meaning are essentially... NULL

If your code relies on NULL as a value in an array and the key
thereof, I'd guess that you're probably using the wrong data
structure, algorithm, or query in the first place.

But that's just me. [shrug]

--
Like Music?
http://l-i-e.com/artists.htm

attached mail follows:


On Mon, October 31, 2005 10:33 am, Marcus Bointon wrote:
> On 31 Oct 2005, at 14:54, Chris Shiflett wrote:
>
>> Hopefully it is also clear that your argument revolves around the
>> idea that PHP would create $_POST['foo'] as NULL if the checkbox is
>> not checked. This is wrong for two reasons:
>
> No, no, that's not what I said - I wouldn't contemplate such
> silliness! The thing I was wrong on is that PHP converts unset
> parameters (as opposed to nonexistent ones which it obviously can't
> do anything about) to an empty string, e.g. given ?a=&b=1, $_REQUEST
> ['a'] is "", not NULL. However, it still serves to underline my other
> point that using isset without actually knowing that is a potentially
> dangerous thing. Getting into the habit of using it for looking in
> the likes of $_REQUEST means you're likely to use it other places
> where you have no such guarantee, and you'll have a bug to track
> down. Using array_key_exists means you will never be exposed to this
> possibility, no matter where your data comes from.

Once again:

HTTP and HTML have no NULL.

It would be INSANE for PHP to interpret any HTTP data, which, by
definition, is all TEXT as NULL.

In the better part of a decade, I've never had a bug from using
isset() and having NULL as a value in an array. I'm not really
concerned about it happening tomorrow.

--
Like Music?
http://l-i-e.com/artists.htm

attached mail follows:


On Sun, October 30, 2005 6:04 am, Marcus Bointon wrote:
> On 29 Oct 2005, at 20:41, Richard Lynch wrote:
>
>> It was probably replacing *TWO* spaces with one.
>>
>> If so, it should really be in a while loop, because there could be 3
>> or more spaces in a row, and if the goal is only single-spaced
>> words...
>
> I can hardly think of a better application for a regex:
>
> $text = preg_replace('/ */', ' ', $text);

Sure.

Now you wanna go re-write all my code that pre-dates preg_* functions
being added to PHP? :-)

Un-paid? :-) :-) :-)

Cuz I probably still do have a while(ststr(...)) str_replace() loop or
two in there somewhere from PHP3.0rc2 days...

Yes, ereg_* were in then.

But they were kinda slow and I didn't undestand Regex then.

Hell, I barely understand it now, really.

There's a certain point where the Regex expression reaches a level of
complexity that I'm just not willing to accept in my code and call it
"maintainable"

/ */ is fine, of course.

But there's lots of times when I know there must be a one-line regex
to replace 10 lines of code, but I don't WANT to use it because I'll
stumble over that one-line Regex every time I have to change it.

--
Like Music?
http://l-i-e.com/artists.htm

attached mail follows:


On 31 Oct 2005, at 06:27, Richard Lynch wrote:

> There's a certain point where the Regex expression reaches a level of
> complexity that I'm just not willing to accept in my code and call it
> "maintainable"
>
> / */ is fine, of course.
>
> But there's lots of times when I know there must be a one-line regex
> to replace 10 lines of code, but I don't WANT to use it because I'll
> stumble over that one-line Regex every time I have to change it.

I quite agree that many regexes are 'write only', but I don't think
that that means that using substr and friends is necessarily any
clearer. I sometimes find that a nested mass of string functions is
even more confusing - at least a regex has a fixed grammar. I've just
written a load of stuff that uses preg_replace_callback that I'm
quite pleased with.

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
marcussynchromedia.co.uk | http://www.synchromedia.co.uk

attached mail follows:


Keep in mind, eval()ing code you pull from the database will also raise the
damage from a SQL injection attack or similar from a PITA
restore-your-database to a much bigger PITA format-webserver.

-Josh
 
--
 
My name was Brian McGee
I stayed up listening to Queen
When I was seventeen

  Josh 'G-Funk' McDonald :: Pirion Systems, Brisbane
 
 07 3257 0490 :: 0437 221 380 :: joshgfunk007.com
 

-----Original Message-----
From: Richard Lynch [mailto:ceol-i-e.com]
Sent: Monday, 31 October 2005 3:57 PM
To: John Taylor-Johnston
Cc: php-generallists.php.net; Jasper Bryant-Greene
Subject: Re: [PHP] eval();

On Sun, October 30, 2005 8:51 pm, John Taylor-Johnston wrote:
> eval( " ?> $contents <?php " );
>
>>However, if eval() is the answer, you're probably asking the wrong
>>question. You should take a hard look at your code and think of a
>>better way to do what you need to do.
>>
>>
> Back to the drawing board? It is either store my html+embedded code in
> a mysql record, or in an html file, which means playing with fopen.
> It's easier to hand tweak in phpmyadmin.
> Nonetheless, even though your test code worked (thanks!) this doesn't.
> Sigh.
>
> if ($contents = displaynew()){
echo "CONTENTS:<pre>", htmlentities($contents), "</pre>\n"; eval( " ?>
$contents <?php " ); }

I'm guessing $contents ain't what you think.

>
> function displaynew()
> {
> $file = basename($_SERVER['PHP_SELF']);
> require 'connect.inc';
> $sql = "SELECT HTML FROM `$db`.`$table_editor` WHERE `Filename`
> LIKE '".addslashes($file)."' LIMIT 1;";
> if ($myquery = mysql_query($sql) and mysql_num_rows($myquery) > 0)

This 'and' should probably be '&&' ...

Though I never really used 'and' enough to know for sure.

At any rate, you've got *NO* error-checking for an invalid query here.

> {
> $mydata = mysql_fetch_array($myquery, MYSQL_NUM);
> return $mydata[0];
> }
> return false;
> }

--
Like Music?
http://l-i-e.com/artists.htm

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

attached mail follows:


Hi

does anyone know whats better/uses less resource etc:

If I run a loop to send a 1000 emails, should I use php's mail fucntions
or send directly to the servers smtp server.

clive

attached mail follows:


On Mon, Oct 31, 2005 at 12:10:02PM +0200, Clive wrote:
> does anyone know whats better/uses less resource etc:
>
> If I run a loop to send a 1000 emails, should I use php's mail fucntions
> or send directly to the servers smtp server.

What do you mean by "send directly"? Are you thinking of sending mail
manually through making a socket connection or something?

Paul

--
Rogue Tory
http://www.roguetory.org.uk

attached mail follows:


Hi Clive,

Monday, October 31, 2005, 10:10:02 AM, you wrote:

> does anyone know whats better/uses less resource etc:

> If I run a loop to send a 1000 emails, should I use php's mail fucntions
> or send directly to the servers smtp server.

Use PEAR Mail Queue.

Cheers,

Rich
--
Zend Certified Engineer
http://www.launchcode.co.uk

attached mail follows:


Clive wrote:
> Hi
>
> does anyone know whats better/uses less resource etc:
>
> If I run a loop to send a 1000 emails, should I use php's mail fucntions
> or send directly to the servers smtp server.

Depends on your setup. If you're on Linux/Unix you could use the mail()
function along with the "-odq" option to Sendmail/Postfix/Exim etc
(fifth argument to the mail() function) which will dump all the mails
into the MTAs queue. After this, the MTA will handle delivery. This is
probably the quickest for this platform.

--
Richard Heyes
http://www.phpguru.org

attached mail follows:


On Mon, Oct 31, 2005 at 12:38:09PM +0200, Clive wrote:
> what I mean is: im using a class called phpmailer and it has the option
> to sent to a smtp server, I suppose this means that they do open a
> socket to the smtp server.

All that means is that you can specify an external SMTP server (e.g.
mail.myisp.com), whereas mail() will use localhost instead. In this case
mail() would probably be quite a bit faster (though only if you're
sending thousands and thousands of emails) because it won't have to send
stuff out beyond the local machine.

Depending on what you want to do and how much control you have over the
machine your PHP scripts are running on, you might want to run a local
mail server that just relays everything to an external source (whatever
SMTP server you're currently using) - that way you can send everything
to that and your PHP script should return control a bit faster.

Paul

--
Rogue Tory
http://www.roguetory.org.uk

attached mail follows:


On 31 Oct 2005, at 10:34, Richard Heyes wrote:

> Depends on your setup. If you're on Linux/Unix you could use the
> mail() function along with the "-odq" option to Sendmail/Postfix/
> Exim etc (fifth argument to the mail() function) which will dump
> all the mails into the MTAs queue. After this, the MTA will handle
> delivery. This is probably the quickest for this platform.

I agree. Sending directly is usually reserved for Windows machines
with no local MTA and is usually way slower and doesn't handle
queuing. I'd advise anyone to use PHPMailer for mail anyway as it
makes it much more reliable to deal with all the other stuff like
MIME encoding, plus it has support for all these sending methods
without having to change much code. I use it with qmail.

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
marcussynchromedia.co.uk | http://www.synchromedia.co.uk

attached mail follows:


On Mon, Oct 31, 2005 at 12:56:01PM +0200, Clive wrote:
> Thanks I actually want to send 24 000 emails with 2 meg attachments.

Oh. You definitely don't want to be using an external SMTP server if you
can help it then, and you should really be splitting those up into
chunks (no more than 1,000 at a time really) using something like PEAR
Queue as has already been suggested.

> There also another option with the class: using the sendmail program,
> but won't the php mail function use sendmail anyway

As far as I know, mail() just sends stuff to whatever the sendmail
binary is on your system, although I haven't really looked into it. Of
course you don't have to be running sendmail as most MTA will install
binaries such as /usr/sbin/sendmail which actually point to postfix or
qmail or whatever you're running.

Paul

--
Rogue Tory
http://www.roguetory.org.uk

attached mail follows:


On 31 Oct 2005, at 03:29, Gustavo Narea wrote:

> I think It is OK what I said about the caret, but what we need to
> change is the position of \W*:
> Your suggestion: /(\b\w+\b\W*){1,$MaxWords}/
> My suggestion: /^(\W*\b\w+\b){1,$MaxWords}/
>
> We need the *first* ($MaxWords)th words.

I makes no difference - they will both work. Mine doesn't care where
the first word starts because it doesn't use ^, and yours doesn't
care where the first word starts because it's got ^ followed by \W*.
Your overall match will end up with leading spaces, mine will end up
with trailing spaces - the subsequent trim fixes them both. I like
mine because it has 1 less char ;^)

Ultimately, if it works for you, great!

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
marcussynchromedia.co.uk | http://www.synchromedia.co.uk

attached mail follows:


Hello, Marcus.

No, you are right. Your script is better.

I just forgot something I learned about REGEXES: The REGEX engine is
eager. Thus, in this case, It's not necessary to use the caret. The
REGEX engine will start from the first word It finds.

I would use yours ;-).

Best regards,

Gustavo Narea.
PHP Documentation - Spanish Translation Team.
Valencia, Venezuela.

Marcus Bointon wrote:
>
> On 31 Oct 2005, at 03:29, Gustavo Narea wrote:
>
>> I think It is OK what I said about the caret, but what we need to
>> change is the position of \W*:
>> Your suggestion: /(\b\w+\b\W*){1,$MaxWords}/
>> My suggestion: /^(\W*\b\w+\b){1,$MaxWords}/
>>
>> We need the *first* ($MaxWords)th words.
>
>
> I makes no difference - they will both work. Mine doesn't care where
> the first word starts because it doesn't use ^, and yours doesn't care
> where the first word starts because it's got ^ followed by \W*. Your
> overall match will end up with leading spaces, mine will end up with
> trailing spaces - the subsequent trim fixes them both. I like mine
> because it has 1 less char ;^)
>
> Ultimately, if it works for you, great!
>
> Marcus

attached mail follows:


Hello!

PHP 4.4.1 is now available for download [1]. This version is a
maintenance release, that contains numerous bug fixes, including a
number of security fixes related to the overwriting of the GLOBALS
array. All users of PHP 4.3 and 4.4 are encouraged to upgrade to this
version.

The full list of changes in PHP 4.4.1 is available in the PHP 4
ChangeLog [2] and a list with the most important changes is available
through the release announcement [3].

[1] http://php.net/downloads.php#v4
[2] http://php.net/ChangeLog-4.php#4.1.1
[3] http://php.net/release_4_4_1.php

regards,
Derick

--
http://derickrethans.nl | http://ez.no | http://xdebug.org

attached mail follows:


Hello,

I have the string:

<tr><td><img src="http://www.runescape.com/img/hiscores/attack.gif" valign="bottom" width=16 height=16 /></td><td>&nbsp;</td><td><a href="hiscoreuser.cgi?username=zezima&category=1" class=c>Attack</a></td><td align="right">4</td><td align="right">99</td><td align="right">53,156,556</td></tr>

and I apply preg_match_all:

preg_match_all("/(<tr><td><img
src=\"http:\/\/www.runescape.com\/img\/hiscores\/attack.gif\"
valign=\"bottom\" width=16 height=16 \/><\/td><td>&nbsp;<\/td><td><a
href=\"hiscoreuser.cgi\?username=)([\w])+(&category=1\"
class=c>Attack<\/a><\/td><td align=\"right\">)([1-9])+(<\/td><td
align=\"right\">)([1-9])+(<\/td><td
align=\"right\">)([1-9,])+(<\/td><\/tr>)/",$seite,$attack);

($seite is the string)

If i make print_r($attack); then I get:

Array
(
    [0] => Array
        (
            [0] => <tr><td><img src="http://www.runescape.com/img/hiscores/attack.gif" valign="bottom" width=16 height=16 /></td><td>&nbsp;</td><td><a href="hiscoreuser.cgi?username=zezima&category=1" class=c>Attack</a></td><td align="right">4</td><td align="right">99</td><td align="right">53,156,556</td></tr>
        )

    [1] => Array
        (
            [0] => <tr><td><img src="http://www.runescape.com/img/hiscores/attack.gif" valign="bottom" width=16 height=16 /></td><td>&nbsp;</td><td><a href="hiscoreuser.cgi?username=
        )

    [2] => Array
        (
            [0] => a
        )

    [3] => Array
        (
            [0] => &category=1" class=c>Attack</a></td><td align="right">
        )

    [4] => Array
        (
            [0] => 4
        )

    [5] => Array
        (
            [0] => </td><td align="right">
        )

    [6] => Array
        (
            [0] => 9
        )

    [7] => Array
        (
            [0] => </td><td align="right">
        )

    [8] => Array
        (
            [0] => 6
        )

    [9] => Array
        (
            [0] => </td></tr>
        )

)

But I would expect to get

[2] => Array
        (
            [0] => zezima
        )
[6] => Array
        (
            [0] => 99
        )
[8] => Array
        (
            [0] => 53,156,556
        )

Instead of the values above.

Can you explain me how I can get those values?

Yannick Mortier

attached mail follows:


Yannick Mortier wrote:
> Hello,
>
> I have the string:
>
> <tr><td><img src="http://www.runescape.com/img/hiscores/attack.gif"
> valign="bottom" width=16 height=16 /></td><td>&nbsp;</td><td><a
> href="hiscoreuser.cgi?username=zezima&category=1"
> class=c>Attack</a></td><td align="right">4</td><td
> align="right">99</td><td align="right">53,156,556</td></tr>
>
>
> and I apply preg_match_all:
>
> preg_match_all("/(<tr><td><img
> src=\"http:\/\/www.runescape.com\/img\/hiscores\/attack.gif\"
> valign=\"bottom\" width=16 height=16 \/><\/td><td>&nbsp;<\/td><td><a
> href=\"hiscoreuser.cgi\?username=)([\w])+(&category=1\"
> class=c>Attack<\/a><\/td><td align=\"right\">)([1-9])+(<\/td><td
> align=\"right\">)([1-9])+(<\/td><td
> align=\"right\">)([1-9,])+(<\/td><\/tr>)/",$seite,$attack);

...

> But I would expect to get
> [2] => Array
> (
> [0] => zezima
> )
> [6] => Array
> (
> [0] => 99
> )
> [8] => Array
> (
> [0] => 53,156,556 )
>
> Instead of the values above.
>
> Can you explain me how I can get those values?

Try something like:

preg_match_all('#username=([^&]+).+<td align="right">\d+</td><td
align="right">(\d+)</td><td align="right">([\d, ]+)</td>#i', $seite,
$matches);

print_r($matches);

Not tested - might need tweaking.

--
Richard Heyes
http://www.phpguru.org

attached mail follows:


On Mon, October 31, 2005 9:27 am, Yannick Mortier wrote:
> <tr><td><img src="http://www.runescape.com/img/hiscores/attack.gif"
> valign="bottom" width=16 height=16 /></td><td>&nbsp;</td><td><a
> href="hiscoreuser.cgi?username=zezima&category=1"
> class=c>Attack</a></td><td align="right">4</td><td
> align="right">99</td><td align="right">53,156,556</td></tr>
>
>
> and I apply preg_match_all:
>
> preg_match_all("/(<tr><td><img
> src=\"http:\/\/www.runescape.com\/img\/hiscores\/attack.gif\"
> valign=\"bottom\" width=16 height=16 \/><\/td><td>&nbsp;<\/td><td><a
> href=\"hiscoreuser.cgi\?username=)([\w])+(&category=1\"
> class=c>Attack<\/a><\/td><td align=\"right\">)([1-9])+(<\/td><td
> align=\"right\">)([1-9])+(<\/td><td
> align=\"right\">)([1-9,])+(<\/td><\/tr>)/",$seite,$attack);
>
> ($seite is the string)

When trying to web-scrape data like this, I would recommend that you
try to focus on things that are NOT likely to change, rather than the
HTML bits that probably will change.

When you HAVE to use the HTML, focus on the smallest elements of HTML
that you can to identify what you want, so your odds of an altered
HTML page will be less likely to affect you.

I would try this:
'/username=(.*)\\&.*"right">([0-9]*).*"right>([0-9]*).*"right>([0-9,]*)/'

PS FOR SURE, you need 0-9 and not 1-9 for your numbers:
Rank: 10
Score: 45,067,13
etc

> Can you explain me how I can get those values?

< and > are probably being interpreted as special characters or
something.

--
Like Music?
http://l-i-e.com/artists.htm

attached mail follows:


I having been looking for some snippet to help me with changing MS
Word double, quotes, single quotes and other characters to acceptable
HTML safe characters. The problem comes about when the people using
the forms paste large articles from Word into the form, I do a normal
check and add slashes but lately they have been getting lazy and using
the special characters from Word.

attached mail follows:


Have you tried using htmlentities()? It should convert stuff like double-quotes (") to it's associated HTML entity which, when echo'd to the browser, will be displayed as " again.

Good for safe output. Not so good for storing in a database (which you'd probably want to use whatever your database's "escape_string" function is).

-TG

= = = Original message = = =

I having been looking for some snippet to help me with changing MS
Word double, quotes, single quotes and other characters to acceptable
HTML safe characters. The problem comes about when the people using
the forms paste large articles from Word into the form, I do a normal
check and add slashes but lately they have been getting lazy and using
the special characters from Word.

___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

attached mail follows:


Check in the comments section of ths page: http://us3.php.net/htmlentities
. You're not the first person to have this problem.
Ben

On Mon, 31 Oct 2005 10:30:49 -0500, Dan McCullough
<dan.mcculloughgmail.com> wrote:

> I having been looking for some snippet to help me with changing MS
> Word double, quotes, single quotes and other characters to acceptable
> HTML safe characters. The problem comes about when the people using
> the forms paste large articles from Word into the form, I do a normal
> check and add slashes but lately they have been getting lazy and using
> the special characters from Word.

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

attached mail follows:


Dan McCullough wrote:
> I having been looking for some snippet to help me with changing
> MS Word double, quotes, single quotes and other characters to
> acceptable HTML safe characters.

This seems to work:

$search = array('/[\x07\x95]/',
                 '/\x85/',
                 '/[\x91\x92]/',
                 '/[\x93\x94]/');

$replace = array('-',
                  '...',
                  "'",
                  '"');

$string = preg_replace($search, $replace, $string);

Hope that helps.

Chris

--
Chris Shiflett
Brain Bulb, The PHP Consultancy
http://brainbulb.com/

attached mail follows:


On Mon, October 31, 2005 9:30 am, Dan McCullough wrote:
> I having been looking for some snippet to help me with changing MS
> Word double, quotes, single quotes and other characters to acceptable
> HTML safe characters. The problem comes about when the people using
> the forms paste large articles from Word into the form, I do a normal
> check and add slashes but lately they have been getting lazy and using
> the special characters from Word.

There are several functions at http://php.net/htmlentities in the
User-Contributed notes for this.

Pick the one you like.

PS ALWAYS read the User-Contributed notes of related functions when
looking for this kind of stuff. They're a Gold Mine.

--
Like Music?
http://l-i-e.com/artists.htm

attached mail follows:


I actually got it pretty quickly after reading the Rasmus AJAX tutorial
It was simple and easy to understand.
Thank you, Rasmus :)

I just needed to seemlessly launch the QuickTime player from a Flash
page. Seems like Ajax is going to do this quite nicely.

g

On Oct 30, 2005, at 10:06 PM, Richard Lynch wrote:

> You probably should be asking in an Ajax forum...
>
> That said:
>
> Ajax just goes and gets whatever is at a URL.
>
> You can have the biggest, baddest PHP script at that URL that spits
> out whatever you want.
>
> Or it can always just spit out "42"
>
> Ajax don't really care either way.
>
> And PHP doesn't really care if Ajax is asking for AppleJacks is
> asking.
>
> Somebody asks, PHP spits out the data.
>
> So, YES, your Ajax can request a PHP URL and get back any HTML you
> feel like.
>
> For that matter, you *could* use Ajax to request the actual ".mov"
> file, if you can get some kind of .mov player to run Ajax. And you
> could have PHP spitting out the QT movie from a
> http://php.net/readfile or similar.
>
> Hell, you could write a PHP script to GENERATE a QuickTime movie on
> the fly, if you knew QT internals enough to do it.
>
> On Sun, October 30, 2005 6:34 pm, Graham Anderson wrote:
>
>>
>> Can you use AJAX to output an entire php-generated embed tag into a
>> web page?
>>
>> something like:
>>
>> <?php
>> // simple no frills qt embed
>> $qtembed = <<<EOB
>> <item>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"
>> height="352" width="216" codebase="http://www.apple.com/qtactivex/
>> qtplugin.cab">
>> <embed src="themovie.mov" width="352" height="216">
>> </embed>
>> </object>
>> </item>
>> EOB;
>>
>> header('Content-Type: text/xml'); // ajax only seems to like text/xml
>> header('Content-Length: '.strlen($qtembed));
>> echo $qtembed;
>> ?>
>>
>>
>>
>> I am a bit new to Ajax stuff, but thankfully, have been able to make
>> simple examples work.
>> From the examples I have tried thus far , it 'appears' that Ajax
>> only supports sending/receiving elements like zip code....not entire
>> tags
>> Is there a way to 'curl' the html to see what 'xmlhttprequest' is
>> sending and receiving ?
>>
>> Maybe I am going about this the wrong way and there is a better
>> solution?
>> I wanted to avoid pop-up windows, launching new html pages, and
>> iframes if possible.
>> Ultimately, I want to dynamically write an invisible movie embed tag
>> into an html document when called by some 'geturl' actionscript.
>> Basically, click a button in a flash movie, and the quicktime
>> player launches.
>>
>> Instead, should I write a 'empty" quicktime movie tag into the html
>> document with the element, moviename, for Ajax to target ?
>>
>>
>>
>>
>> many thanks in advance :)
>> g
>>
>>
>>
>> this is the script I was attempting to modify:
>> http://developer.apple.com/internet/webcontent/XMLHttpRequestExample/
>> example.html
>>
>>
>>
>> these are the two javascript functions where loadDoc is called by a
>> form from the above html
>>
>> function loadDoc(evt) {
>> // equalize W3C/IE event models to get event object
>> evt = (evt) ? evt : ((window.event) ? window.event : null);
>> if (evt) {
>> // equalize W3C/IE models to get event target reference
>> var elem = (evt.target) ? evt.target : ((evt.srcElement) ?
>> evt.srcElement : null);
>> if (elem) {
>> try {
>> if (elem.selectedIndex > 0) {
>> loadXMLDoc(elem.options
>> [elem.selectedIndex].value);
>> }
>> }
>> catch(e) {
>> var msg = (typeof e == "string") ? e :
>> ((e.message) ? e.message : "Unknown Error");
>> alert("Unable to get XML data:\n" + msg);
>> return;
>> }
>> }
>> }
>> }
>>
>> // retrieve text of an XML document element, including
>> // elements using namespaces
>> function getElementTextNS(prefix, local, parentElem, index) {
>> var result = "";
>> if (prefix && isIE) {
>> // IE/Windows way of handling namespaces
>> result = parentElem.getElementsByTagName(prefix + ":" +
>> local)[index];
>> } else {
>> // the namespace versions of this method
>> // (getElementsByTagNameNS()) operate
>> // differently in Safari and Mozilla, but both
>> // return value with just local name, provided
>> // there aren't conflicts with non-namespace element
>> // names
>> result = parentElem.getElementsByTagName(local)[index];
>> }
>> if (result) {
>> // get text, accounting for possible
>> // whitespace (carriage return) text nodes
>> if (result.childNodes.length > 1) {
>> return result.childNodes[1].nodeValue;
>> } else {
>> return result.firstChild.nodeValue;
>> }
>> } else {
>> return "n/a";
>> }
>> }
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>>
>
>
> --
> Like Music?
> http://l-i-e.com/artists.htm
>
>

attached mail follows:


Hi.

I am looking for a good tried and tested B2B software like Alibaba.

Can anyone please suggest if they have tried and running any?

Thanks
Denis

attached mail follows:


On Mon, 2005-10-31 at 12:04, Denis L. Menezes wrote:
> Hi.
>
> I am looking for a good tried and tested B2B software like Alibaba.

There was this one... but 40 thieves ran off with it :p

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. |
`------------------------------------------------------------'