php-general Digest 14 Jul 2008 04:21:10 -0000 Issue 5567
Topics (messages 276722 through 276739):
Re: case and accent - insensitive regular expression?
276722 by: tedd
Shared Authentication Scheme - the reason for the Redirect and POST mailing
276723 by: Alex Chamberlain
276725 by: Colin Guthrie
276727 by: Alex Chamberlain
Re: Most popular per month
276724 by: Ryan S
Re: PDO Question. Number of rows returned
276726 by: Stephen
276729 by: Bastien Koert
276731 by: Stephen
276732 by: Bastien Koert
Re: Saving loading time at counting rows
276728 by: Eric Butera
276733 by: Joep Roebroek
Re: scalable web gallery
276730 by: paragasu
string comparison
276734 by: Sudhakar
276736 by: Robert Cummings
276737 by: dg
Re: IPv6 validation
276735 by: Robert Cummings
276738 by: Per Jessen
Freelance PHP development in India
276739 by: Denis L. Menezes
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 ---
At 8:31 AM -0400 7/13/08, Andrew Ballard wrote:
On Sat, Jul 12, 2008 at 10:29 AM, tedd <[EMAIL PROTECTED]> wrote:
At 9:36 AM +0200 7/12/08, Giulio Mastrosanti wrote:
Hi,
I have a php page that asks user for a key ( or a list of keys ) and then
shows a list of items matching the query.
every item in the list shows its data, and the list of keys it has ( a
list of comma-separated words )
I would like to higlight, in the list of keys shown for every item, the
words matching the query,
this can be easily achieved with a search and replace, for every search
word, i search it in the key list and replace it adding a style tag to
higlight it such as for example to have it in red color:
if ( @stripos($keylist,$keysearch!== false ) {
$keylist = str_ireplace($keysearch,'<span style="color:
#FF0000">'.$keysearch.'</span>',$keylist);
}
but i have some problem with accented characters:
i have mysql with character encoding utf8, and all the php pages are
declared as utf8
mysql in configured to perform queries in a case and accent insensitive
way.
this mean that if you search for the word 'cafe', you have returned rows
that contains in the keyword list 'cafe', but
also 'café' with the accent. (
I think it has to do with 'collation'
settings, but I'm not investigating at
the moment because it is OK for me the way it works ).
now my problem is to find a way ( I imagine with some kind of regular
expression ) to achieve in php a search and replace accent-insensitive, so
that i can find the word 'cafe' in a string
also if it is 'café', or 'CAFÉ',
or 'CAFE', and vice-versa.
hope the problem is clear and well-explained in english,
thank you for any tip,
Giulio
Giulio:
Three things:
1. Your English is fine.
2. Try using mb_ereg_replace()
http://www.php.net/mb_ereg_replace
Place the accents you want to change in that and change them to whatever you
want.
3. Change:
<span style="color: #FF0000">'.$keysearch.'</span>'
to
<span class="keysearch">'.$keysearch.'</span>'
and add
.keysearch
{
color: #FF0000;
}
to your css.
Cheers,
tedd
I may be mistaken (and if I am, then just ignore this as ignorant
rambling), but I don't think he's wanting to replace the accented
characters in the original string. I think he's just wanting the
pattern to find all variations of the same string and highlight them
without changing them. For example, his last paragraph would look like
this:
[quote]
now my problem is to find a way ( I imagine with some kind of regular
expression ) to achieve in php a search and replace
accent-insensitive, so that i can find the word '<span
class="keysearch">cafe</span>' in a string also if it is '<span
class="keysearch">café</span>', or '<span
class="keysearch">CAFÉ</span>', or '<span
class="keysearch">CAFE</span>', and vice-versa.
[/quote]
The best I can think of right now is something like this:
<?php
function highlight_search_terms($word, $string) {
$search = preg_quote($word);
$search = str_replace('a', '[aàáâãäå]', $search);
$search = str_replace('e', '[eèéêë]', $search);
/* repeat for each possible accented character */
return preg_replace('/\b' . $search . '\b/i', '<span
class="keysearch">$0</span>', $string);
}
$string = "now my problem is to find a way ( I imagine with some kind
of regular expression ) to achieve in php a search and replace
accent-insensitive, so that i can find the word 'cafe' in a string
also if it is 'café', or 'CAFÉ', or 'CAFE', and vice-versa.";
echo highlight_search_terms('cafe', $string);
?>
Andrew
Andrew:
You may be right -- it's ambiguous now that I
review it again. He does say search and replace
but I'm not sure if that's what he really wants.
It looks more like search with one string and
highlight all like-strings.
Cheers,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
--- End Message ---
--- Begin Message ---
I am at the very early stages of developing a shared authentication scheme
(SAS). Often referred to as single sign on, but a fundamentally different
concept, the scheme hopes to assign a single set of credentials to each user
(username, password etc), which they can then use to sign on to a range of
websites. The server will be proprietary software, but the client
implementations will be open: this is mainly in the interests of security
rather than making a huge amount of money – the service will be free for
users, and free for small to medium sized websites, the threshold of which
is yet to be set.
The scheme draws inspiration from several existing and similar schemes. The
client will redirect the user to the server to authenticate on one of any
number of levels. Initially, this will just be done by using a
username/number and a password, but in the future will expand to features,
such as private information authentication (ie using date of birth, place of
birth etc) or even smart card authentication, if demand is such that we can
implement it cost effectively. Upon authorisation, the server will redirect
the browser back to the client website to enjoy their membership benefits.
The company will be registered in the UK, and hence will be subject to
strict data protection laws. Despite this, the scheme hopes to minimise user
‘form filling’ by storing and providing a central database of basic personal
details: at this stage, there will certainly not be storage of any bank
details etc.
The server and client will initially be programmed in PHP, so I wanted to
gather some opinion on whether people wanted another SAS, and what would
make them use it over any other?? The company will be there, not only to
serve the end user, but to serve the developer as well. If anybody wants to
be one of the first users/developers, feel free to contact me on this email
address and I will keep you posted.
At this stage, a name has not been confirmed due to the lack of domain, and
I am operating as an individual until such time as the code and service goes
public. I hope to rectify this in the coming days: watch this space.
Thanks in advance,
Alex Chamberlain
--- End Message ---
--- Begin Message ---
Alex Chamberlain wrote:
The server and client will initially be programmed in PHP, so I wanted to
gather some opinion on whether people wanted another SAS, and what would
make them use it over any other?? The company will be there, not only to
serve the end user, but to serve the developer as well. If anybody wants to
be one of the first users/developers, feel free to contact me on this email
address and I will keep you posted.
Personally I don't really like the idea of yet another SAS/SSO... The
whole point of an SSO is summed up in the first letter of the Acronym...
*Single*. If there are multiple different services and different sites
implement different SSO systems then there is no longer a *Single* service.
Personally, I think that a distributed system with a single
*specification* that allows different implementations to exist is the
only way forward here and for that, OpenID seems like the best spec out
there right now.
Perhaps you can explain what your system would offer that would make it
better than an OpenID service? Perhaps your service will be OpenID
compatible to ensure wider exposure? Perhaps it does more than OpenID?
If so what?
Col
--- End Message ---
--- Begin Message ---
> Alex Chamberlain wrote:
> > The server and client will initially be programmed in PHP, so I
> wanted to
> > gather some opinion on whether people wanted another SAS, and what
> would
> > make them use it over any other?? The company will be there, not
> > only
> to
> > serve the end user, but to serve the developer as well. If anybody
> wants to
> > be one of the first users/developers, feel free to contact me on
> > this
> email
> > address and I will keep you posted.
>
> Personally I don't really like the idea of yet another SAS/SSO... The
> whole point of an SSO is summed up in the first letter of the
> Acronym...
> *Single*. If there are multiple different services and different sites
> implement different SSO systems then there is no longer a *Single*
> service.
>
> Personally, I think that a distributed system with a single
> *specification* that allows different implementations to exist is the
> only way forward here and for that, OpenID seems like the best spec
> out there right now.
>
> Perhaps you can explain what your system would offer that would make
> it better than an OpenID service? Perhaps your service will be OpenID
> compatible to ensure wider exposure? Perhaps it does more than OpenID?
> If so what?
>
> Col
I was anticipating this question, but did not want to prompt it. In fact, I
started a few weeks ago looking at the OpenID specification, and a PHP server
implementation: I found it to be confusing and quite buggy. I hope to implement
a OpenID 'frontend' in the future, but not straight away. I also consulted
several friends, as well as some of my 18-year-old brothers friends - although
a few were very comfortable with the internet and did understand, a lot were
confused by the concept of a URL itself - they sort of understood when I
explained it was a web address, but could not understand how to use this as a
username: this is a fundamental problem of their discovery procedure, in my
opinion.
Also, a single server system will be more consistent and more secure, and I
hope the sharing of personal information *legally* will be a key attraction for
most websites. I am at a very early stage, and welcome any comments.
Alex
No virus found in this outgoing message. Scanned by AVG Free 8.0
Checked by AVG - http://www.avg.com
Version: 8.0.138 / Virus Database: 270.4.10/1549 - Release Date: 12/07/2008
16:31
--- End Message ---
--- Begin Message ---
Thanks Brady, Wolf, Bernhard!
Will write back if i hit a wall but I think your explanations and links should
take me all the way.
Cheers!
Ryan
--- End Message ---
--- Begin Message ---
Kevin Waterson wrote:
I am switching to PDO and can't find an equivalent to mysql_num_rows.
Am I missing something silly?
Or is there a change of thinking needed for PDO?
How should I determine how many rows a query returned?
PDO returns an array, sizeof/count will get you home
I would like to know how many rows I am working with before starting to
fetch.
Also fetchall, does not seem to have a style that returns each column
value just once. I see this ugly thing in the manual:
Fetch all of the remaining rows in the result set:
Array
(
[0] => Array
(
[NAME] => pear
[0] => pear
[COLOUR] => green
[1] => green
)
[1] => Array
(
[NAME] => watermelon
[0] => watermelon
[COLOUR] => pink
[1] => pink
)
)
If I could get the column offsets only, without the column names I would be
very happy.
Stephen
--- End Message ---
--- Begin Message ---
On Sun, Jul 13, 2008 at 10:30 AM, Stephen <[EMAIL PROTECTED]> wrote:
> Kevin Waterson wrote:
>
>> I am switching to PDO and can't find an equivalent to mysql_num_rows.
>>>
>>> Am I missing something silly?
>>>
>>> Or is there a change of thinking needed for PDO?
>>>
>>> How should I determine how many rows a query returned?
>>>
>>>
>>
>> PDO returns an array, sizeof/count will get you home
>>
>>
> I would like to know how many rows I am working with before starting to
> fetch.
>
> Also fetchall, does not seem to have a style that returns each column value
> just once. I see this ugly thing in the manual:
>
> Fetch all of the remaining rows in the result set:
> Array
> (
> [0] => Array
> (
> [NAME] => pear
> [0] => pear
> [COLOUR] => green
> [1] => green
> )
>
> [1] => Array
> (
> [NAME] => watermelon
> [0] => watermelon
> [COLOUR] => pink
> [1] => pink
> )
>
> )
>
> If I could get the column offsets only, without the column names I would be
> very happy.
>
> Stephen
>
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
http://ca3.php.net/manual/en/pdostatement.rowcount.php
--
Bastien
Cat, the other other white meat
--- End Message ---
--- Begin Message ---
Bastien Koert wrote:
On Sun, Jul 13, 2008 at 10:30 AM, Stephen <[EMAIL PROTECTED]> wrote:
Kevin Waterson wrote:
I am switching to PDO and can't find an equivalent to mysql_num_rows.
Am I missing something silly?
Or is there a change of thinking needed for PDO?
How should I determine how many rows a query returned?
PDO returns an array, sizeof/count will get you home
I would like to know how many rows I am working with before starting to
fetch.
Also fetchall, does not seem to have a style that returns each column value
just once. I see this ugly thing in the manual:
Fetch all of the remaining rows in the result set:
Array
(
[0] => Array
(
[NAME] => pear
[0] => pear
[COLOUR] => green
[1] => green
)
[1] => Array
(
[NAME] => watermelon
[0] => watermelon
[COLOUR] => pink
[1] => pink
)
)
If I could get the column offsets only, without the column names I would be
very happy.
http://ca3.php.net/manual/en/pdostatement.rowcount.php
This is only good for updates, inserts and deletes.<br>
I am just doing a select.
Stephen<br>
--- End Message ---
--- Begin Message ---
On Sun, Jul 13, 2008 at 11:12 AM, Stephen <[EMAIL PROTECTED]> wrote:
> Bastien Koert wrote:
>
> On Sun, Jul 13, 2008 at 10:30 AM, Stephen <[EMAIL PROTECTED]> <[EMAIL
> PROTECTED]> wrote:
>
>
>
> Kevin Waterson wrote:
>
>
>
> I am switching to PDO and can't find an equivalent to mysql_num_rows.
>
>
> Am I missing something silly?
>
> Or is there a change of thinking needed for PDO?
>
> How should I determine how many rows a query returned?
>
>
>
>
> PDO returns an array, sizeof/count will get you home
>
>
>
>
> I would like to know how many rows I am working with before starting to
> fetch.
>
> Also fetchall, does not seem to have a style that returns each column value
> just once. I see this ugly thing in the manual:
>
> Fetch all of the remaining rows in the result set:
> Array
> (
> [0] => Array
> (
> [NAME] => pear
> [0] => pear
> [COLOUR] => green
> [1] => green
> )
>
> [1] => Array
> (
> [NAME] => watermelon
> [0] => watermelon
> [COLOUR] => pink
> [1] => pink
> )
>
> )
>
> If I could get the column offsets only, without the column names I would be
> very happy.
>
> Stephen
>
>
>
>
> http://ca3.php.net/manual/en/pdostatement.rowcount.php
>
> This is only good for updates, inserts and deletes.
>
> I am just doing a select.
> Stephen
>
>
my bad.
Note you can change the default return array behaviour by change the
FETCH_STYLE, default is both ordinal and col name
--
Bastien
Cat, the other other white meat
--- End Message ---
--- Begin Message ---
On Sat, Jul 12, 2008 at 8:26 PM, Joep Roebroek <[EMAIL PROTECTED]> wrote:
> I had this question, which I didn't really know where to ask, so I
> thought to begin at this mailing list.
>
> Very basicly said, I count the rows of a table which had approx 50000
> or more rows.
>
> The problem is, there is a notable difference in loading time with
> other pages. Is there a technique to estimate the number of rows
> instead of exactly couting them? So that it saves loading time.
>
> For example, when you search with google, you get an estimate of the
> number of results, how do they do this?
>
> Maybe this is not a question for the PHP Mailing list, but if not
> where is a better place to ask this?
>
> regards,
>
> Joep
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
In general get in the mindset of making your web app have fast reads
and allow slower writes. So instead of generating a very expensive
count query on each request (or read), make sure that you have some
pre-generated count elsewhere. You can even tie this generate count
routine to any add/edit/delete's to make sure that it is up to date or
just cron it for some interval.
--- End Message ---
--- Begin Message ---
I think, I will store the count and update it every 24 hours like
tedd, says. I have thought of that earlier but was woundering if there
might be another method.
But I am wondering how google estimates the number of results, but I
think that is a more complex thing :P.
Thanks for the responses :)
regards,
Joep
2008/7/13 Joep Roebroek <[EMAIL PROTECTED]>:
> I had this question, which I didn't really know where to ask, so I
> thought to begin at this mailing list.
>
> Very basicly said, I count the rows of a table which had approx 50000
> or more rows.
>
> The problem is, there is a notable difference in loading time with
> other pages. Is there a technique to estimate the number of rows
> instead of exactly couting them? So that it saves loading time.
>
> For example, when you search with google, you get an estimate of the
> number of results, how do they do this?
>
> Maybe this is not a question for the PHP Mailing list, but if not
> where is a better place to ask this?
>
> regards,
>
> Joep
>
--- End Message ---
--- Begin Message ---
oic.. the concept is relatively simple.. thanks for the explaination daniel..
On 7/13/08, Daniel Brown <[EMAIL PROTECTED]> wrote:
> On Sat, Jul 12, 2008 at 2:37 PM, tedd <[EMAIL PROTECTED]> wrote:
>>
>> Hey, let's knock off that old shit, newlywed !
>>
>> Just because you finally got laid doesn't mean you can beat me in memory
>> loss. :-)
>
> That's "lei'd", sir.
>
> --
> </Daniel P. Brown>
> Dedicated Servers - Intel 2.4GHz w/2TB bandwidth/mo. starting at just
> $59.99/mo. with no contract!
> Dedicated servers, VPS, and hosting from $2.50/mo.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
hi
i am writing a small application where a user enters a phrase in the
textfield and i would like to display all the files present in the root
directory which consists of the keyword or keywords entered by the user.
i have used a few comparison functions but i am not getting the expected
result.
$my_file = file_get_contents("filename.html");
what ever the user enters whether it is a single word or few words i would
like to compare with $my_file in a case insensitive manner.
can anyone suggest the best method and how to go about.
thanks.
--- End Message ---
--- Begin Message ---
On Sun, 2008-07-13 at 21:47 +0530, Sudhakar wrote:
> hi
>
> i am writing a small application where a user enters a phrase in the
> textfield and i would like to display all the files present in the root
> directory which consists of the keyword or keywords entered by the user.
>
> i have used a few comparison functions but i am not getting the expected
> result.
>
> $my_file = file_get_contents("filename.html");
> what ever the user enters whether it is a single word or few words i would
> like to compare with $my_file in a case insensitive manner.
>
> can anyone suggest the best method and how to go about.
I don't suggest using file_get_contents. It would probably be more
efficient (at least less memory intensive) to use fopen() and fread().
Just be sure you overlap each read by $the_size_of_the_largest
phrase_or_keyword - 1. Then use stripos() for matching... of course that
won't work so well if whitespace doesn't need to match exactly in
phrases. In which case you'll need to resort to other techniques.
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
--- End Message ---
--- Begin Message ---
On Jul 13, 2008, at 9:17 AM, Sudhakar wrote:
hi
i am writing a small application where a user enters a phrase in the
textfield and i would like to display all the files present in the
root
directory which consists of the keyword or keywords entered by the
user.
i have used a few comparison functions but i am not getting the
expected
result.
I use this script to list archive files from a directory based on
keyword. I'd guess a modified version using the keywords from users
might work:
// create archives box
if ($handle = opendir('../diaryarchives/')) {
while (false !== ($file =
readdir($handle))) {
$pos = strpos($file, diary_);
$pagemarked = "diary"."_";
if ($pos !== false) {
//print "$file<br>";
$file_name = ereg_replace
("$pagemarked","",$file);
$file_name = ereg_replace
(".php","",$file_name);
//print "* $file_name<br>";
//print "$file<br>";
$archive_list_gather[] = '<li><a href="/diaryarchives/'.
$file.'">'.$file_name.'</a></li>';
}
}
closedir($handle);
}
rsort($archive_list_gather);
foreach($archive_list_gather as $value) {
$archive_list .= "$value";
}
// build archives box
$archives_box = '<div id="diary-archives">
<h3 class="side"><img src="/images/h3s_diaryarchives.gif"
alt="Diary Archives" width="225" height="20" /></h3>
<ul>
'.$archive_list.'
</ul>
</div>';
// publish archives box
$filename = PATHA.'/diaryarchivesbox.php';
publishpages($archives_box, $filename);
--- End Message ---
--- Begin Message ---
On Sun, 2008-07-13 at 17:48 +1000, Kevin Waterson wrote:
> This one time, at band camp, Per Jessen <[EMAIL PROTECTED]> wrote:
>
> > No, it's a simple matter of need. People also run apache 1.x, mysql 3.x
> > etc. There are still Linux 2.2 and 2.4 systems out there too.
>
> 4 years its been, thats incompetence.
Something smells like a troll around here *looks suspiciously at Kevin*.
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
--- End Message ---
--- Begin Message ---
Kevin Waterson wrote:
> This one time, at band camp, Per Jessen <[EMAIL PROTECTED]> wrote:
>
>> No, it's a simple matter of need. People also run apache 1.x, mysql
>> 3.x etc. There are still Linux 2.2 and 2.4 systems out there too.
>
> 4 years its been, thats incompetence.
>
> Kevin
Kevin, I don't know how old you are nor how long you have been in IT,
but your opinions suggest you might be fairly inexperienced.
Like I said, remaining back-level with software or an OS it's a matter
of need or choice. Sometime both are heavily influenced by time and
money. Not upgrading something to PHP5 due to lack of manpower is not
incompetent at all, it's reality.
/Per Jessen, Zürich
--- End Message ---
--- Begin Message ---
Dear friends.
I am looking for freelance web developers in India.
Can contact me?
Thanks
Denis
--- End Message ---