php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25618 * operator doesnt function as it is supposed to be
Submitted: 2003-09-21 07:46 UTC Modified: 2003-09-21 09:21 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: yurtesen at ispro dot net dot tr Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 4.3.3 OS: FreeBSD 4.8-STABLE
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
23 + 30 = ?
Subscribe to this entry?

 
 [2003-09-21 07:46 UTC] yurtesen at ispro dot net dot tr
Description:
------------
If I have string
<a HREF="linkhere"><font>texthere</a></font>
I can extract the text 'linkhere' and 'texthere' with
preg_match_all("/<a.*href=\"(.*)\".*><.*>(.*)<\/a>/iU", $line, $matches);

But if the string is
<a HREF="linkhere"><font><b>texthere</a></b></font>
preg_match_all("/<a.*href=\"(.*)\".*>(?:<.*>)*(.*)<\/a>/iU", $line, $matches);

doesnt work. It matches for "<font><b>texthere"
I am trying to exclude <font><b> by matching repeatedly by
(?:<.*>)* before the actual text I need.

You can check out my php configuration from
http://www.ispro.net/temp/phpinfo.php

Reproduce code:
---------------
<?
  $line = '<a HREF="linkhere"><font><b>texthere</a></b></font>';

  preg_match_all("/<a.*href=\"(.*)\".*>(?:<.*>)*(.*)<\/a>/iU", $line, $matches);

  print_r($matches);

?>

Expected result:
----------------
Array
(
    [0] => Array
        (
            [0] => <a HREF="linkhere"><font><b>texthere</a>
        )

    [1] => Array
        (
            [0] => linkhere
        )

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

)

Actual result:
--------------
Array
(
    [0] => Array
        (
            [0] => <a HREF="linkhere"><font><b>texthere</a>
        )

    [1] => Array
        (
            [0] => linkhere
        )

    [2] => Array
        (
            [0] => <font><b>texthere
        )

)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-09-21 09:21 UTC] rasmus@php.net
You just need to make your * non-greedy there.
eg.
"/<a.*href=\"(.*)\".*>(?:<.*>)*?(.*)<\/a>/iU"
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 00:01:28 2024 UTC