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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Wed Jan 15 08:01:29 2025 UTC