php-general Digest 19 Feb 2011 03:09:11 -0000 Issue 7189
Topics (messages 311424 through 311439):
Re: Howdy (new in here)
311424 by: Robert Cummings
311438 by: D. Dante Lorenso
Connection Handling - unreliable at best?
311425 by: James Green
New to list and to PHP
311426 by: Pete Woodhead
311430 by: Adam Richardson
how to dynamically generate list of arguments to pass to array_diff
311427 by: Mari Masuda
Re: Mysql 5.5 and PHP Mysql API Version 5.1.41
311428 by: Tommy Pham
311431 by: Tommy Pham
Re: [SOLVED] [PHP] how to dynamically generate list of arguments to pass to
array_diff
311429 by: Mari Masuda
Re: improve speed of PHP answers
311432 by: Tommy Pham
Re: Displaying Results
311433 by: Tommy Pham
Regex pattern for preg_match_all
311434 by: Tommy Pham
311435 by: Simon J Welsh
311436 by: Peter Lind
311437 by: Tommy Pham
9970318527584
311439 by: John Taylor-Johnston
Administrivia:
To subscribe to the digest, e-mail:
[email protected]
To unsubscribe from the digest, e-mail:
[email protected]
To post to the list, e-mail:
[email protected]
----------------------------------------------------------------------
--- Begin Message ---
On 11-02-16 06:36 PM, Tamara Temple wrote:
On Feb 15, 2011, at 11:23 PM, Brian Waters wrote:
On Tue, Feb 15, 2011 at 11:46 PM, Tamara Temple<[email protected]
wrote:
I was unlucky enough to find someone who coded a
function that went on for 30 pages one (this was in C, not PHP) and
*that*
was hard to untangle.
Why!?!?!?!?!?!?!
- BW
(un?)fortunately, he was no longer with the company, which was why I
got to take it over. It wasn't the oddest thing, by far. His designs
were hugely complex (way overengineered for the task at hand, plus
they didn't work), and he didn't use any consistent indenting style.
But was he consistently inconsistent? :B
Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.
--- End Message ---
--- Begin Message ---
On 2/18/11 8:39 AM, Kirk Bailey wrote:
Oh hey, that's a good point. All the stuff i saw so far indented 2
spaces. WHY?
Can I just indent a TAB if my editor permits this? indenting 4 spaces (2
nests) is easy, but suppose I hit one extra space- not enough difference
to be really noticeable. Let's talk about indentation in php for a
moment, could we?
I use PHPEclipse for an editor. It has the best code beautifier I've
used for PHP class editing. I hit Ctrl+Shift+F and the whole file jumps
into the format I have predefined. It handles indentation, curly braces
up or down, spacing, etc.
I can take code snippets from anywhere and with a couple keystrokes, the
format adheres to my preferences and is readable.
-- Dante
On 2/16/2011 6:36 PM, Tamara Temple wrote:
On Feb 15, 2011, at 11:23 PM, Brian Waters wrote:
On Tue, Feb 15, 2011 at 11:46 PM, Tamara Temple
<[email protected]> wrote:
I was unlucky enough to find someone who coded a
function that went on for 30 pages one (this was in C, not PHP) and
*that*
was hard to untangle.
Why!?!?!?!?!?!?!
- BW
(un?)fortunately, he was no longer with the company, which was why I
got to take it over. It wasn't the oddest thing, by far. His designs
were hugely complex (way overengineered for the task at hand, plus
they didn't work), and he didn't use any consistent indenting style.
--- End Message ---
--- Begin Message ---
Been reading through
http://uk.php.net/manual/en/features.connection-handling.php and
trying to implement a solution using it. So far the documented
behaviour rarely occurs.
This code is a minimal test case: http://codepad.org/GqNlcWiM
I run this behind Apache 2.2 with PHP 5.3 on Linux. The in-line
comments explain the problem. I load in the browser and hit stop
pretty much immediately but PHP does not get signalled that the user
has aborted and continues.
>From memory of having to restart apache after hitting long-running
scripts in the past, I don't ever believe I've had a script terminate
on a user abort. And I've never switched the behaviour from default.
I read several people explain this behaviour would only ever work in
writing back to the client and to flush the buffer, which is included
in the test case. I've also removed any compression from within
Apache.
Can anyone explain what I've seeing? I've tried this using Lighttpd/Windows too.
Thanks,
James
--- End Message ---
--- Begin Message ---
Hi I'm Pete Woodhead. I'm new to the list and to PHP. To be honest I very
new to code writing.
Thought this would be a good way to learn good habits as well as good code
writing.
Looking forward to learning and participating.
--- End Message ---
--- Begin Message ---
On Fri, Feb 18, 2011 at 2:03 PM, Pete Woodhead <[email protected]>wrote:
> Hi I'm Pete Woodhead. I'm new to the list and to PHP. To be honest I very
> new to code writing.
> Thought this would be a good way to learn good habits as well as good code
> writing.
> Looking forward to learning and participating.
>
Welcome, Pete.
I'm confident you'll gain valuable insight through participating in the
list.
Adam
--
Nephtali: A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com
--- End Message ---
--- Begin Message ---
Hello,
I have an array of arrays like this:
---
[array_of_arrays:private] => Array
(
[0] => Array
(
[0] => 2
[1] => 4
[2] => 5
[3] => 17
[4] => 80
)
[1] => Array
(
[0] => 5
[1] => 7
[2] => 9
[3] => 2
[4] => 16
[5] => 58
)
[2] => Array
(
[0] => 2
[1] => 4
[2] => 6
[3] => 8
[4] => 37
[5] => 92
)
)
---
and I want to do an array_diff on them so that I get something like this back:
---
Array
(
[0] => 6
[1] => 7
[2] => 8
[3] => 9
[4] => 16
[5] => 17
[6] => 37
[7] => 58
[8] => 80
[9] => 92
)
---
The arrays above are just an example; the real arrays I am working with can
have many more elements (in the tens of thousands). Also, there can be a
variable number of subarrays. I have written several different versions of my
own array_diff that iterates over all the subarrays but they are slow.
My question is is there a way to call the built-in array_diff with a
dynamically generated list of arguments? I was thinking maybe there would be a
way to do this with variable variables or if I generated a string that could be
parsed by PHP but I have only succeeded in confusing myself further. Thanks
for any suggestions.
Mari
--- End Message ---
--- Begin Message ---
On Tue, Feb 15, 2011 at 9:57 AM, Matthias Laug <[email protected]> wrote:
> Hey there,
>
> I've just migrated to Mysql 5.5 from source and it works like a charm. Still
> every now and then (in intervals of approximatly an hour) I get the following
> error:
>
> Error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2013]
> Lost connection to MySQL server at 'reading initial communication packet',
> system error: 110' in
> /home/ydadmin/build/lieferando.de/11720/library/Zend/Db/Adapter/Pdo/Abstract.php:129
> Stack trace: #0
> /home/ydadmin/build/lieferando.de/11720/library/Zend/Db/Adapter/Pdo/Abstract.php(129):
> PDO->__construct('mysql:port=6664...', '#####', '#####', Array) #1
> /home/ydadmin/build/lieferando.de/11720/library/Zend/Db/Adapter/Pdo/Mysql.php(96):
> Zend_Db_Adapter_Pdo_Abstract->_connect() #2
> /home/ydadmin/build/lieferando.de/11720/library/Zend/Db/Adapter/Abstract.php(448):
> Zend_Db_Adapter_Pdo_Mysql->_connect() #3
> /home/ydadmin/build/lieferando.de/11720/library/Zend/Db/Adapter/Pdo/Abstract.php(238):
> Zend_Db_Adapter_Abstract->query('SET NAMES 'utf8...', Array) #4
> /home/ydadmin/build/lieferando.de/11720/application/Bootstrap.php(99):
> Zend_Db_Adapter_Pdo_Abstract->query('SET NAMES 'utf8...') #5
> /home/ydadmin/build/lieferando.de/11720/library/Zend/App in
> /home/ydadmin/build/lieferando.de/11720/library/Zend/Db/Adapter/Pdo/Abstract.php
> on line 144
>
> It is like any queue is running full and this is the result, but actually no
> clue. My first guess is the API Version of the mysql client I am using with
> the precompiled php binaries (Ubuntu 10.10 Server, PHP 5.3.2-1ubuntu4.7 with
> Suhosin-Patch (cli) (built: Jan 12 2011 18:36:55))
>
> Does anyone else have the same problems?
>
> Thanks for any help,
> Matthias
> --
Have you tried a basic test w/o framework like this to ensure that
both installed versions of PHP & MySQL are working properly as
expected?
Test connection for sample data:
Penelope Guiness
Nick Wahlberg
Platform info:
Server Info: 5.5.7-rc-log
Client Info: mysqlnd 5.0.7-dev - 091210 - $Revision: 304625 $
Webserver: Microsoft-IIS/7.5
PHP: 5.3.5-cgi-fcgi
<?php
$user = 'test';
$passwd = 'test';
$host = '127.0.0.1';
$dbname = 'sample_sakila';
$sql = 'SELECT * FROM actor LIMIT 0,2';
$dsn = "mysql:host={$host};dbname={$dbname}";
if ( !extension_loaded( 'pdo' ) ) throw new \Exception(' Requires PHP
PDO extension.');
if ( !extension_loaded( 'pdo_mysql' ) ) throw new \Exception('
Requires PHP PDO driver MySQL ');
echo '<pre>Test connection for sample data: '.PHP_EOL;
$dbh = new PDO( $dsn, $user, $passwd );
foreach( $dbh->query( $sql ) as $row )
{
echo ucfirst( strtolower( $row['first_name'] ) ).' '
.ucfirst( strtolower( $row['last_name'] ) ).PHP_EOL;
}
echo PHP_EOL.'Platform info: '.PHP_EOL;
$mysqli = new mysqli( $host, $user, $passwd, $dbname );
echo 'Server Info: '.$mysqli->server_info.PHP_EOL;
echo 'Client Info: '.$mysqli->client_info.PHP_EOL;
$mysqli->close();
echo 'Webserver: '.$_SERVER['SERVER_SOFTWARE'].PHP_EOL;
echo 'PHP: '.PHP_VERSION.'-'.PHP_SAPI.PHP_EOL;
show_source(__FILE__);
Note: The MySQL server is my own Win x64 compilation. Nevertheless,
PHP shouldn't have any problems with MySQL 5.5.
Regards,
Tommy
--- End Message ---
--- Begin Message ---
BTW, how is the traffic on your site? What's the max connection limit
and timeout set on the MySQL server?
[1] from searching [2] might be the solution to your problem.
Good luck,
Tommy
[1] http://forums.mysql.com/read.php?52,364493,364831#msg-364831
[2] http://www.google.com/search?q=php+SQLSTATE[HY000]+[2013]
--- End Message ---
--- Begin Message ---
On Feb 18, 2011, at 12:03 PM, Simon J Welsh wrote:
>
> On 19/02/2011, at 8:07 AM, Mari Masuda wrote:
>> My question is is there a way to call the built-in array_diff with a
>> dynamically generated list of arguments? I was thinking maybe there would
>> be a way to do this with variable variables or if I generated a string that
>> could be parsed by PHP but I have only succeeded in confusing myself
>> further. Thanks for any suggestions.
>>
>> Mari
>
> call_user_func_array('array_diff', $this->array_of_arrays);
>
> http://php.net/call_user_func_array
>
> Though from your example, passing multiple arrays to array_diff is not what
> you're after, as it just returns the items in the first array that are not in
> any of the others.
> ---
> Simon Welsh
> Admin of http://simon.geek.nz/
>
> Who said Microsoft never created a bug-free program? The blue screen never,
> ever crashes!
>
> http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e
>
Hi Simon,
Thank you for the info on call_user_func_array and for pointing out my error!
(That bug would partially explain why I have been beating my head against the
wall for the last several days.) call_user_func_array is exactly what I need.
Thanks again!
Mari
--- End Message ---
--- Begin Message ---
On Thu, Feb 10, 2011 at 5:18 AM, Alex Nikitin <[email protected]> wrote:
<snip>
>
> One, while sorting and limiting, and improving mysql queries is a great way
> to increase application performance, dont forget that sql is not a
> programming language and as such certain tasks should not be done in
> queries, any complex computations for example would execute faster in php
> then they would in mysql (tested).
>
<snip>
Optimizing the backend for speed goes beyond just SQL query
optimization. Is the DB structure optimized? Example: best usage of
column type & column size? Do you have any indexes? Are you over
normalizing the tables? Queries makes full use of indexes? etc...
Basic DB structure is fine when you have very small # rows. Once the
rows count reach hundreds of thousands, or worse, millions, you'll
need to have an optimized DB structure. If you're limited on
knowledge and experience on RDBMS, time for major readings or ask a
friendly DBA.
Regards,
Tommy
--- End Message ---
--- Begin Message ---
On Tue, Feb 15, 2011 at 12:19 PM, Peter Lind <[email protected]> wrote:
> On 15 February 2011 20:28, Ethan Rosenberg <[email protected]> wrote:
>> Dear List -
>>
>
> Ask google you should
> Plenty of advice you'll find
> we won't do your homework
>
> Regards
> Peter
>
+1. Ethan, you should read this [1] first.
Regards,
Tommy
[1] http://www.catb.org/~esr/faqs/smart-questions.html
--- End Message ---
--- Begin Message ---
Hi folks,
This is not directly relating to PHP but it's Friday so I'm gonna give
it a shot :). Would someone please help me figure out why my regex
pattern doesn't work. Below is the code and sample data:
$html = <<<HTML
<li class="small tab "><a class="y-mast-link images"
href="http://images.search.yahoo.com/images"
data-b="http://www.yahoo.com"><span class="tab-cover y-mast-bg-hide"
style="padding-left:0em;padding-right:0em;">Images</span></a></li>
<li class="small tab "><a class="y-mast-link video"
href="http://video.search.yahoo.com/video"
data-b="http://www.yahoo.com"><span class="tab-cover y-mast-bg-hide"
style="padding-left:0em;padding-right:0em;">Video</span></a></li>
<li class="small tab "><a class="y-mast-link local"
href="http://local.yahoo.com/results"
data-b="http://www.yahoo.com"><span class="tab-cover y-mast-bg-hide"
style="padding-left:0em;padding-right:0em;">Local</span></a></li>
<li class="small tab "><a class="y-mast-link shopping"
href="http://shopping.yahoo.com/search"
data-b="http://www.yahoo.com"><span class="tab-cover y-mast-bg-hide"
style="padding-left:0em;padding-right:0em;">Shopping</span></a></li>
<li class="small lasttab more-tab "><a class="y-mast-link more"
href="http://tools.search.yahoo.com/about/forsearchers.html" ><span
class="tab-cover y-mast-bg-hide">More</span><span
class="y-fp-pg-controls arrow"></span></a></li>
HTML;
$pattern =
'%<a\s[^href]*href\s*=\s*[\'|"]?([^\'|"|#]+)[\'|"]?\s*[^>]*>(.*)?</a>%im';
preg_match_all($pattern, $html, $matches);
The only matches I got is:
Match 1 of 1: <a class="y-mast-link local"
href="http://local.yahoo.com/results"
data-b="http://www.yahoo.com"><span class="tab-cover y-mast-bg-hide"
style="padding-left:0em;padding-right:0em;">Local</span></a>
Group 1: http://local.yahoo.com/results
Group 2: <span class="tab-cover y-mast-bg-hide"
style="padding-left:0em;padding-right:0em;">Local</span>
The pattern I made was to work in cases where the page is
non-compliant to any of standard W3.
Thanks,
Tommy
--- End Message ---
--- Begin Message ---
As far as I can tell, your problem lies in [^href]*. That will match any
characters other than h, r, e or f, not anything other than the string href.
Consider replacing it with [^>]*?. The ? makes it non-greedy so it will stop as
soon as it can (when it matches the first href) rather than as late as it can
(when it matches a >)
---
Simon Welsh
Sent from my phone, excuse the brevity
On 19/02/2011, at 10:36, Tommy Pham <[email protected]> wrote:
> Hi folks,
>
> This is not directly relating to PHP but it's Friday so I'm gonna give
> it a shot :). Would someone please help me figure out why my regex
> pattern doesn't work. Below is the code and sample data:
>
> $html = <<<HTML
> <li class="small tab "><a class="y-mast-link images"
> href="http://images.search.yahoo.com/images"
> data-b="http://www.yahoo.com"><span class="tab-cover y-mast-bg-hide"
> style="padding-left:0em;padding-right:0em;">Images</span></a></li>
> <li class="small tab "><a class="y-mast-link video"
> href="http://video.search.yahoo.com/video"
> data-b="http://www.yahoo.com"><span class="tab-cover y-mast-bg-hide"
> style="padding-left:0em;padding-right:0em;">Video</span></a></li>
> <li class="small tab "><a class="y-mast-link local"
> href="http://local.yahoo.com/results"
> data-b="http://www.yahoo.com"><span class="tab-cover y-mast-bg-hide"
> style="padding-left:0em;padding-right:0em;">Local</span></a></li>
> <li class="small tab "><a class="y-mast-link shopping"
> href="http://shopping.yahoo.com/search"
> data-b="http://www.yahoo.com"><span class="tab-cover y-mast-bg-hide"
> style="padding-left:0em;padding-right:0em;">Shopping</span></a></li>
> <li class="small lasttab more-tab "><a class="y-mast-link more"
> href="http://tools.search.yahoo.com/about/forsearchers.html" ><span
> class="tab-cover y-mast-bg-hide">More</span><span
> class="y-fp-pg-controls arrow"></span></a></li>
> HTML;
>
> $pattern =
> '%<a\s[^href]*href\s*=\s*[\'|"]?([^\'|"|#]+)[\'|"]?\s*[^>]*>(.*)?</a>%im';
> preg_match_all($pattern, $html, $matches);
>
> The only matches I got is:
>
> Match 1 of 1: <a class="y-mast-link local"
> href="http://local.yahoo.com/results"
> data-b="http://www.yahoo.com"><span class="tab-cover y-mast-bg-hide"
> style="padding-left:0em;padding-right:0em;">Local</span></a>
>
> Group 1: http://local.yahoo.com/results
>
> Group 2: <span class="tab-cover y-mast-bg-hide"
> style="padding-left:0em;padding-right:0em;">Local</span>
>
> The pattern I made was to work in cases where the page is
> non-compliant to any of standard W3.
>
> Thanks,
> Tommy
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--- End Message ---
--- Begin Message ---
On 18 February 2011 22:36, Tommy Pham <[email protected]> wrote:
> Hi folks,
>
> This is not directly relating to PHP but it's Friday so I'm gonna give
> it a shot :). Would someone please help me figure out why my regex
> pattern doesn't work. Below is the code and sample data:
>
> $html = <<<HTML
> <li class="small tab "><a class="y-mast-link images"
> href="http://images.search.yahoo.com/images"
> data-b="http://www.yahoo.com"><span class="tab-cover y-mast-bg-hide"
> style="padding-left:0em;padding-right:0em;">Images</span></a></li>
> <li class="small tab "><a class="y-mast-link video"
> href="http://video.search.yahoo.com/video"
> data-b="http://www.yahoo.com"><span class="tab-cover y-mast-bg-hide"
> style="padding-left:0em;padding-right:0em;">Video</span></a></li>
> <li class="small tab "><a class="y-mast-link local"
> href="http://local.yahoo.com/results"
> data-b="http://www.yahoo.com"><span class="tab-cover y-mast-bg-hide"
> style="padding-left:0em;padding-right:0em;">Local</span></a></li>
> <li class="small tab "><a class="y-mast-link shopping"
> href="http://shopping.yahoo.com/search"
> data-b="http://www.yahoo.com"><span class="tab-cover y-mast-bg-hide"
> style="padding-left:0em;padding-right:0em;">Shopping</span></a></li>
> <li class="small lasttab more-tab "><a class="y-mast-link more"
> href="http://tools.search.yahoo.com/about/forsearchers.html" ><span
> class="tab-cover y-mast-bg-hide">More</span><span
> class="y-fp-pg-controls arrow"></span></a></li>
> HTML;
>
> $pattern =
> '%<a\s[^href]*href\s*=\s*[\'|"]?([^\'|"|#]+)[\'|"]?\s*[^>]*>(.*)?</a>%im';
> preg_match_all($pattern, $html, $matches);
>
> The only matches I got is:
>
> Match 1 of 1: <a class="y-mast-link local"
> href="http://local.yahoo.com/results"
> data-b="http://www.yahoo.com"><span class="tab-cover y-mast-bg-hide"
> style="padding-left:0em;padding-right:0em;">Local</span></a>
>
> Group 1: http://local.yahoo.com/results
>
> Group 2: <span class="tab-cover y-mast-bg-hide"
> style="padding-left:0em;padding-right:0em;">Local</span>
>
> The pattern I made was to work in cases where the page is
> non-compliant to any of standard W3.
>
Not entirely sure what your input data is, as I'm guessing one or more
mail programs may have added line breaks. When I run the code I get no
matches at all - so I'm guessing you might have different input on
your end. More specifically, I'm also guessing you have line breaks on
your end, but not equally distributed - which would explain the one
hit.
Apart from that, there are a couple of things I'd rework in your regex:
%<a\s+.*?(?!href)\s+href\s*=\s*([^\s\'"]+|\'[^\']+\'|\"[^\"]+\")[^>]*>(.*?)</a>%ims
* added modifier to whitespace at first
* allowing for any character not followed by href (non-greedy)
* match the href
* use proper alternation
* capture anything inside the <a> tag, non-greedy
* match with a closing </a> tag
Results:
array(3) {
[0]=>
array(5) {
[0]=>
string(205) "<a class="y-mast-link images"
href="http://images.search.yahoo.com/images"
data-b="http://www.yahoo.com"><span class="tab-cover y-mast-bg-hide"
style="padding-left:0em;padding-right:0em;">Images</span></a>"
[1]=>
string(201) "<a class="y-mast-link video"
href="http://video.search.yahoo.com/video"
data-b="http://www.yahoo.com"><span class="tab-cover y-mast-bg-hide"
style="padding-left:0em;padding-right:0em;">Video</span></a>"
[2]=>
string(196) "<a class="y-mast-link local"
href="http://local.yahoo.com/results"
data-b="http://www.yahoo.com"><span class="tab-cover y-mast-bg-hide"
style="padding-left:0em;padding-right:0em;">Local</span></a>"
[3]=>
string(204) "<a class="y-mast-link shopping"
href="http://shopping.yahoo.com/search"
data-b="http://www.yahoo.com"><span class="tab-cover y-mast-bg-hide"
style="padding-left:0em;padding-right:0em;">Shopping</span></a>"
[4]=>
string(188) "<a class="y-mast-link more"
href="http://tools.search.yahoo.com/about/forsearchers.html" ><span
class="tab-cover y-mast-bg-hide">More</span><span
class="y-fp-pg-controls arrow"></span></a>"
}
[1]=>
array(5) {
[0]=>
string(39) ""http://images.search.yahoo.com/images""
[1]=>
string(37) ""http://video.search.yahoo.com/video""
[2]=>
string(32) ""http://local.yahoo.com/results""
[3]=>
string(34) ""http://shopping.yahoo.com/search""
[4]=>
string(55) ""http://tools.search.yahoo.com/about/forsearchers.html""
}
[2]=>
array(5) {
[0]=>
string(96) "<span class="tab-cover y-mast-bg-hide"
style="padding-left:0em;padding-right:0em;">Images</span>"
[1]=>
string(95) "<span class="tab-cover y-mast-bg-hide"
style="padding-left:0em;padding-right:0em;">Video</span>"
[2]=>
string(95) "<span class="tab-cover y-mast-bg-hide"
style="padding-left:0em;padding-right:0em;">Local</span>"
[3]=>
string(98) "<span class="tab-cover y-mast-bg-hide"
style="padding-left:0em;padding-right:0em;">Shopping</span>"
[4]=>
string(94) "<span
class="tab-cover y-mast-bg-hide">More</span><span
class="y-fp-pg-controls arrow"></span>"
}
--
<hype>
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
</hype>
--- End Message ---
--- Begin Message ---
@Simon,
Thanks for explaining about the [^href]. I need to read up more about
greediness. I thought I understood it but guess not.
@Peter,
I tried your pattern but it didn't capture all of my new test cases.
Also, it captures the single/double quotes in addition to the
fragments inside the href. I couldn't figure out how to modify your
pattern to exclude the ', ", and URL fragment from group 1 matches.
Below is the new pattern with the new sample test cases that I got it
to work. The new pattern failed only 1 of the non-compliant.
$html = <<<HTML
<a href=/sample/link>content</a>
<a class=link href=/sample/link_extra_attribs title=sample
link>content link_extra_attribs</a>
<a href='/sample/link_single_quote'>content link_single_quote</a>
<a class='link' href='/sample/link_single_quote_pre_attribs'>content
link_single_quote_pre_attribs</a>
<a class='link' href='/sample/link_single_quote_extra_attribs'
title='sample link'>content link_single_quote_extra_attribs</a>
<a class='link'
href='/sample/link_single_quote_extra_attribs_frag#fragment'
title='sample link'>content
link_single_quote_extra_attribs_frag#fragment</a>
<a class='link'
href='/sample/link_single_quote_extra_attribs_query_frag?par=val#fragment'
title='sample link'>content
link_single_quote_extra_attribs_query_frag?par=val#fragment</a>
<a href="/sample/link_double_quote">content link_double_quote</a>
<a class="link" href="/sample/link_double_quote_pre_attribs">content
link_double_quote_pre_attribs</a>
<a class="link"
href="/sample/link_double_quote_extra_attribs_frag#fragment"
title="sample link">content
link_double_quote_extra_attribs_frag#fragment</a>
<a class="link"
href="/sample/link_double_quote_extra_attribs_nested_tag"
title="sample link"><img class="image" src="/images/content.jpg"
alt="content" title="content">
link_double_quote_extra_attribs_nested_tag</a>
<a href="#fragment">content fragment</a>
<a class="link" href="#fragment" title="sample link">content fragment</a>
<li class="small tab "><a class="y-mast-link images"
href="http://images.search.yahoo.com/images"
data-b="http://www.yahoo.com"><span class="tab-cover y-mast-bg-hide"
style="padding-left:0em;padding-right:0em;">Images</span></a></li>
<li class="small tab "><a class="y-mast-link video"
href="http://video.search.yahoo.com/video"
data-b="http://www.yahoo.com"><span class="tab-cover y-mast-bg-hide"
style="padding-left:0em;padding-right:0em;">Video</span></a></li>
<li class="small tab "><a class="y-mast-link local"
href="http://local.yahoo.com/results"
data-b="http://www.yahoo.com"><span class="tab-cover y-mast-bg-hide"
style="padding-left:0em;padding-right:0em;">Local</span></a></li>
<li class="small tab "><a class="y-mast-link shopping"
href="http://shopping.yahoo.com/search"
data-b="http://www.yahoo.com"><span class="tab-cover y-mast-bg-hide"
style="padding-left:0em;padding-right:0em;">Shopping</span></a></li>
<li class="small lasttab more-tab "><a class="y-mast-link more"
href="http://tools.search.yahoo.com/about/forsearchers.html" ><span
class="tab-cover y-mast-bg-hide">More</span><span
class="y-fp-pg-controls arrow"></span></a></li>
HTML;
$pattern =
'%<a[\s]+[^>]*?href\s*=\s*["\']?([^"\'#>]*)["\']?\s?[^>]*>(.*?)</a>%ims';
preg_match_all($pattern, $html, $matches);
Thanks for your time,
Tommy
--- End Message ---
--- Begin Message ---
9970318527584
Could this number refer to a date()? In late 2009?
How could I calculate it?
--- End Message ---