> Do you need to use ".*?"? If there will be only white characters, use
> \s* instead.
>
unfortunately there's some content either side of $file before
this content is different for each item, so i can't define it in the
pattern.
--
PHP General Mailing List (http://www.php.net/)
To unsubsc
> And what about [^>]* -if there are no html tags
>
not thought about that, but XML tags, not HTML tags... does that make any
difference?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
> Not sure if I understand you correct but
> the way you wrote your replace pattern the result should be
> .
> If you want just the file to be replaced you have to use something like
> preg_replace("|.*?($file).*?|si",'\\1',$contents)
>
no, i want just the whole replaced for that particular file
$contents = preg_replace( "|.*?".$file.".*?|si", "",
$contents );
okay, so i figured out that it's matching the first occurence of
which will always be the first record and then going on to match the $file
and deleting everything between. obviously not what i want.
without giving a unique attri
skate wrote:
$contents = preg_replace( "|.*?$file.*?|si", "", $contents );
it's being run on an XML file, where each entry is .. with
a $file pointer in there.
it works okay, except for the fact that it deletes that record, and every
record before it. i can't figure out why it's being greed
> preg_replace("|.*?$file.*?|si","",$contents)
>
>
> fhh
> 1060205191
> hhh
> xml/news/1060205191.xml
>
>
> fgjghjh
> 1060205186
> fgjh
> xml/news/1060205186.xml
>
>
> fgjhh
> 1060205182
> fghh
> xml/news/1060205182.xml
>
>
Not sure if I understand you correct
- Original Message -
From: "skate" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, August 06, 2003 3:16 PM
Subject: [PHP] greedy preg
>
> $contents = preg_replace( "|.*?$file.*?|si", "",
$contents );
>
> it's be
From: "skate" <[EMAIL PROTECTED]>
> $contents = preg_replace( "|.*?".$file.".*?|si", "",
> $contents );
>
> okay, so i figured out that it's matching the first occurence of
> which will always be the first record and then going on to match the $file
> and deleting everything between. obviously not
Do you need to use ".*?"? If there will be only white characters, use
\s* instead.
skate wrote:
$contents = preg_replace( "|.*?".$file.".*?|si", "",
$contents );
okay, so i figured out that it's matching the first occurence of
which will always be the first record and then going on to match the
>
> You cannot store file pointers. If you output the variable it's going to
> look something like "Resource ID #1" which is meaningless except to the
> instance of the script that created it. Or did you mean something
different
> by "$file pointer"?
sorry, wrong words...
when i meant $file is
And what about [^>]* -if there are no html tags
skate wrote:
Do you need to use ".*?"? If there will be only white characters, use
\s* instead.
unfortunately there's some content either side of $file before
this content is different for each item, so i can't define it in the
pattern.
--
P
$contents = preg_replace( "|.*?$file.*?|si", "", $contents );
it's being run on an XML file, where each entry is .. with
a $file pointer in there.
it works okay, except for the fact that it deletes that record, and every
record before it. i can't figure out why it's being greedy? i know i
skate wrote:
What are the possible values of $file? Are you looking to replace just a
specific occurance of a $file between tags? Maybe this will help:
$contents = preg_replace("|[^<]*$file[^<]*|si","",$contents);
or just use the 'U' modifier for "ungreedy"...
i'm looking to replace the entir
> What are the possible values of $file? Are you looking to replace just a
> specific occurance of a $file between tags? Maybe this will help:
>
> $contents = preg_replace("|[^<]*$file[^<]*|si","",$contents);
>
> or just use the 'U' modifier for "ungreedy"...
>
i'm looking to replace the entire
>
> Yeah, it should be. What kind on content can be around $file and also
> within the tag?
>
here's a snip of the xml file...
it's finding the $file correctly, but deletes all records from the beginning
of the file onwards. it leaves the xml file with valid xml ... at the
start... so for the
15 matches
Mail list logo