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
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: yurtesen at ispro dot net dot tr
New email:
PHP Version: OS:

 

 [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-2022 The PHP Group
All rights reserved.
Last updated: Wed Jan 26 09:03:33 2022 UTC